Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-codegen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Christian Heinigk
dune-codegen
Commits
54f1a482
Commit
54f1a482
authored
6 years ago
by
René Heß
Browse files
Options
Downloads
Patches
Plain Diff
Loopy transformation replacinrd reductions with inplace accumulation
parent
d8093a55
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/dune/codegen/loopy/transformations/remove_reductions.py
+58
-0
58 additions, 0 deletions
...n/dune/codegen/loopy/transformations/remove_reductions.py
with
58 additions
and
0 deletions
python/dune/codegen/loopy/transformations/remove_reductions.py
0 → 100644
+
58
−
0
View file @
54f1a482
import
loopy
as
lp
import
pymbolic.primitives
as
prim
def
remove_reduction
(
knl
,
match
):
"""
Removes all matching reductions and do direct accumulation in assignee instead
"""
instructions
=
[]
# Find reductions
for
instr
in
lp
.
find_instructions
(
knl
,
match
):
if
isinstance
(
instr
.
expression
,
lp
.
symbolic
.
Reduction
):
# Remove the instruction from the kernel
knl
=
lp
.
remove_instructions
(
knl
,
set
([
instr
.
id
]))
# Add instruction that sets assignee to zero
id_zero
=
instr
.
id
+
'
_set_zero
'
instructions
.
append
(
lp
.
Assignment
(
instr
.
assignee
,
0
,
within_inames
=
instr
.
within_inames
,
id
=
id_zero
,
tags
=
(
'
set_zero
'
,)
))
# Add instruction that accumulates directly in assignee
assignee
=
instr
.
assignee
expression
=
prim
.
Sum
((
assignee
,
instr
.
expression
.
expr
))
within_inames
=
frozenset
(
tuple
(
instr
.
within_inames
)
+
instr
.
expression
.
inames
)
id_accum
=
instr
.
id
+
'
_accum
'
instructions
.
append
(
lp
.
Assignment
(
assignee
,
expression
,
within_inames
=
within_inames
,
id
=
id_accum
,
depends_on
=
frozenset
((
id_zero
,)),
tags
=
(
'
assignement
'
,)))
knl
=
knl
.
copy
(
instructions
=
knl
.
instructions
+
instructions
)
return
knl
def
remove_all_reductions
(
knl
):
"""
Remove all reductions from loopy kernel
This removes all reductions by instead setting the assignee to zero and
directly accumulating in the assignee.
"""
# Find ids of all reductions
ids
=
[]
for
instr
in
knl
.
instructions
:
if
isinstance
(
instr
.
expression
,
lp
.
symbolic
.
Reduction
):
ids
.
append
(
instr
.
id
)
# Remove reductions
for
id
in
ids
:
match
=
lp
.
match
.
Id
(
id
)
knl
=
remove_reduction
(
knl
,
match
)
return
knl
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment