Introduce algebraic transformations for sum-reduction operations#711
Introduce algebraic transformations for sum-reduction operations#711kaushikcfd wants to merge 2 commits intomainfrom
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.
| .. 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.
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.
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.
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.
Specify how this interacts with reductions with multiple inames.
|
|
||
|
|
||
| def extract_multiplicative_terms_in_sum_reduction_as_subst( | ||
| kernel: LoopKernel, |
| arguments: Sequence[p.Expression], | ||
| terms_filter: Callable[[p.Expression], bool], |
There was a problem hiding this comment.
| 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.
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.
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.
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: