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

transformations: linalg.generic to loops factor out some helpers #2662

Merged
merged 11 commits into from
Jun 3, 2024

Conversation

superlopuh
Copy link
Member

In order to lower to an imperfectly-nested loop structure, it is useful to have a factored-out set of helpers, introduced in this PR.

Note stacked PR.

@superlopuh superlopuh added the transformations Changes or adds a transformatio label May 29, 2024
@superlopuh superlopuh self-assigned this May 29, 2024
Copy link

codecov bot commented May 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.69%. Comparing base (ce845e6) to head (5a9caf8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2662   +/-   ##
=======================================
  Coverage   89.68%   89.69%           
=======================================
  Files         364      364           
  Lines       46901    46920   +19     
  Branches     7114     7119    +5     
=======================================
+ Hits        42065    42084   +19     
  Misses       3733     3733           
  Partials     1103     1103           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@superlopuh superlopuh force-pushed the sasha/memref_stream/loop-utils-outline branch from fd59df9 to 24fd1a9 Compare May 30, 2024 06:51
@superlopuh superlopuh force-pushed the sasha/memref_stream/loop-utils-location branch from 7a73b0d to 32c68d2 Compare May 30, 2024 06:51
],
) -> Sequence[SSAValue]:
"""
Creates a perfect loop nest, populating the innermost body with the provided
Copy link
Contributor

Choose a reason for hiding this comment

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

SHould the title hint that we care about a perfect lops nest?

Copy link
Member Author

Choose a reason for hiding this comment

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

what title?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I mean the function name

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, maybe, although since it's a private function, I think it's sort of safe to drop the implicit perfection

rewriter.insert_op_at_location(loop, insertion_point)
results = loop.results

if i + 1 == len(bounds):
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this line trying to check?

Copy link
Member Author

Choose a reason for hiding this comment

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

that it's the last iteration in the loop

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, sorry I thought by default enumerate starts at 1 for a moemnt.

xdsl/transforms/loop_nest_lowering_utils.py Show resolved Hide resolved
Base automatically changed from sasha/memref_stream/loop-utils-location to main June 2, 2024 18:29
Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

I think this is great, although I feel reviewing is quite hard given the total lack of docstrings and sparse comments on the code.

Comment on lines +127 to +137
def _insert_load_ops(
rewriter: PatternRewriter,
insertion_point: InsertPoint,
ind_vars: Sequence[BlockArgument],
affine_map_attrs: Sequence[AffineMapAttr],
operands: Sequence[SSAValue],
args: Sequence[BlockArgument],
load: Callable[
[SSAValue, Sequence[SSAValue], PatternRewriter, InsertPoint], SSAValue
],
) -> Sequence[tuple[int, SSAValue]]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would love a docstring on this chonker

Comment on lines +151 to +159
def _insert_store_ops(
rewriter: PatternRewriter,
insertion_point: InsertPoint,
ind_vars: Sequence[BlockArgument],
output_indexing_maps: Sequence[AffineMapAttr],
yield_operands: Sequence[SSAValue],
output_operands: Sequence[SSAValue],
store: Callable[[SSAValue, SSAValue, Sequence[SSAValue]], Operation],
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, seeing this many operands without a docstring makes me nervous

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does it need all these things to insert the stores (e.g. what are the yield_operands?)

Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

It's still really hard to reason about these functions, I would ideally like to see complex core code to be much, much more documented, but alas. Have my thumb 👍

@superlopuh
Copy link
Member Author

I'm happy to make changes! Although it would be easier with more specific feedback. Like what isn't clear, etc.

@superlopuh
Copy link
Member Author

I'll merge this for now, but am more than happy to open a new PR to add the further clarifications you recommend

@superlopuh superlopuh merged commit 2248553 into main Jun 3, 2024
10 checks passed
@superlopuh superlopuh deleted the sasha/memref_stream/loop-utils-outline branch June 3, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
transformations Changes or adds a transformatio
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants