-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce algebraic transformations for sum-reduction operations #711
base: main
Are you sure you want to change the base?
Conversation
9f2286d
to
7f51390
Compare
aa470e3
to
4995215
Compare
4995215
to
e83ca29
Compare
.. autofunction:: hoist_invariant_multiplicative_terms_in_sum_reduction | ||
|
||
.. autofunction:: extract_multiplicative_terms_in_sum_reduction_as_subst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. autofunction:: hoist_invariant_multiplicative_terms_in_sum_reduction | |
.. autofunction:: extract_multiplicative_terms_in_sum_reduction_as_subst | |
.. automodule:: loopy.transform.reduction |
return super().map_reduction(expr) | ||
|
||
|
||
def hoist_invariant_multiplicative_terms_in_sum_reduction( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name?
- inverse of "distribute"
- "out of"
:arg within: A match expression understood by :func:`loopy.match.parse_match` | ||
that specifies the instructions over which the transformation is to be | ||
performed. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add example?
out[j] = sum(i, x[i]*y[j])
after hoisting wrt i:
out[j] = y[j]*sum(i, x[i])
return super().map_reduction(expr) | ||
|
||
|
||
def hoist_invariant_multiplicative_terms_in_sum_reduction( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this work on TranslationUnit
?
within: Any = None | ||
) -> LoopKernel: | ||
""" | ||
Hoists loop-invariant multiplicative terms in a sum-reduction expression. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify how this interacts with reductions with multiple inames.
|
||
|
||
def extract_multiplicative_terms_in_sum_reduction_as_subst( | ||
kernel: LoopKernel, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply to TranslationUnit
?
arguments: Sequence[p.Expression], | ||
terms_filter: Callable[[p.Expression], bool], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguments: Sequence[p.Expression], | |
terms_filter: Callable[[p.Expression], bool], | |
arguments: Sequence[ExpressionT], | |
terms_filter: Callable[[ExpressionT], bool], |
|
||
# {{{ extract_multiplicative_terms_in_sum_reduction_as_subst | ||
|
||
class ContainsSumReduction(CombineMapper): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done by simply attempting the transformation (without checking first) and aborting if there's ambiguity? (That would make this guy redundant, possibly.)
return super().map_reduction(expr) | ||
|
||
|
||
def extract_multiplicative_terms_in_sum_reduction_as_subst( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the outer reduction matter?
return super().map_reduction(expr) | ||
|
||
|
||
def hoist_invariant_multiplicative_terms_in_sum_reduction( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about other operations that satisfy a distributive property? (Specify classes maybe? We don't need to enumerate things that obey the distributive law. We can't, not comprehensively, anyway.)
The function signature for the transforms aren't finalized yet. I'm happy to make changes to these with help from the reviewers.
Draft because: