Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kaushikcfd
Copy link
Collaborator

@kaushikcfd kaushikcfd commented Dec 16, 2022

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:

  • Pass CI
  • Change commit messages to reflect subject emails

@kaushikcfd kaushikcfd changed the title Introduces algebraic transformation for sum-reduction operations Introduces algebraic transformations for sum-reduction operations Dec 16, 2022
@kaushikcfd kaushikcfd changed the title Introduces algebraic transformations for sum-reduction operations Introduce algebraic transformations for sum-reduction operations Dec 16, 2022
@kaushikcfd kaushikcfd force-pushed the redn_algebraic_transforms branch 3 times, most recently from 9f2286d to 7f51390 Compare December 17, 2022 03:18
@kaushikcfd kaushikcfd marked this pull request as ready for review December 17, 2022 03:20
@kaushikcfd kaushikcfd force-pushed the redn_algebraic_transforms branch 2 times, most recently from aa470e3 to 4995215 Compare December 18, 2022 14:23
Comment on lines +86 to +88
.. autofunction:: hoist_invariant_multiplicative_terms_in_sum_reduction

.. autofunction:: extract_multiplicative_terms_in_sum_reduction_as_subst
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. 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(
Copy link
Owner

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.
"""
Copy link
Owner

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(
Copy link
Owner

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.
Copy link
Owner

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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply to TranslationUnit?

Comment on lines +234 to +235
arguments: Sequence[p.Expression],
terms_filter: Callable[[p.Expression], bool],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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):
Copy link
Owner

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(
Copy link
Owner

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(
Copy link
Owner

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants