Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
loopy
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
Model registry
Operate
Environments
Monitor
Incidents
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
Show more breadcrumbs
Ben Sepanski
loopy
Commits
95d35e85
Commit
95d35e85
authored
8 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Add un-exposed reduction_arg_to_subst_rule transformation
parent
9b00d1b2
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
loopy/transform/data.py
+65
-0
65 additions, 0 deletions
loopy/transform/data.py
with
65 additions
and
0 deletions
loopy/transform/data.py
+
65
−
0
View file @
95d35e85
...
...
@@ -571,4 +571,69 @@ def set_temporary_scope(kernel, temp_var_names, scope):
# }}}
# {{{ reduction_arg_to_subst_rule
def
reduction_arg_to_subst_rule
(
knl
,
inames
,
insn_match
=
None
,
subst_rule_name
=
None
):
if
isinstance
(
inames
,
str
):
inames
=
[
s
.
strip
()
for
s
in
inames
.
split
(
"
,
"
)]
inames_set
=
frozenset
(
inames
)
substs
=
knl
.
substitutions
.
copy
()
var_name_gen
=
knl
.
get_var_name_generator
()
def
map_reduction
(
expr
,
rec
,
nresults
=
1
):
if
frozenset
(
expr
.
inames
)
!=
inames_set
:
return
type
(
expr
)(
operation
=
expr
.
operation
,
inames
=
expr
.
inames
,
expr
=
rec
(
expr
.
expr
),
allow_simultaneous
=
expr
.
allow_simultaneous
)
if
subst_rule_name
is
None
:
subst_rule_prefix
=
"
red_%s_arg
"
%
"
_
"
.
join
(
inames
)
my_subst_rule_name
=
var_name_gen
(
subst_rule_prefix
)
else
:
my_subst_rule_name
=
subst_rule_name
if
my_subst_rule_name
in
substs
:
raise
LoopyError
(
"
substitution rule
'
%s
'
already exists
"
%
my_subst_rule_name
)
from
loopy.kernel.data
import
SubstitutionRule
substs
[
my_subst_rule_name
]
=
SubstitutionRule
(
name
=
my_subst_rule_name
,
arguments
=
tuple
(
inames
),
expression
=
expr
.
expr
)
from
pymbolic
import
var
iname_vars
=
[
var
(
iname
)
for
iname
in
inames
]
return
type
(
expr
)(
operation
=
expr
.
operation
,
inames
=
expr
.
inames
,
expr
=
var
(
my_subst_rule_name
)(
*
iname_vars
),
allow_simultaneous
=
expr
.
allow_simultaneous
)
from
loopy.symbolic
import
ReductionCallbackMapper
cb_mapper
=
ReductionCallbackMapper
(
map_reduction
)
from
loopy.kernel.data
import
MultiAssignmentBase
new_insns
=
[]
for
insn
in
knl
.
instructions
:
if
not
isinstance
(
insn
,
MultiAssignmentBase
):
new_insns
.
append
(
insn
)
else
:
new_insns
.
append
(
insn
.
copy
(
expression
=
cb_mapper
(
insn
.
expression
)))
return
knl
.
copy
(
instructions
=
new_insns
,
substitutions
=
substs
)
# }}}
# vim: foldmethod=marker
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