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: (apply-individual-rewrite) lazily find canonicalization patterns #3631

Merged
merged 4 commits into from
Dec 16, 2024

Conversation

superlopuh
Copy link
Member

It's time to make this part of the codebase a bit more extensible and robust, as we will be reusing it for some scheduling exploration. As a first step, this PR changes the rewrite infrastructure to get the available patterns on the operation lazily, instead of by scanning all ops of all dialects.

…on patterns
@superlopuh superlopuh added the transformations Changes or adds a transformatio label Dec 12, 2024
@superlopuh superlopuh self-assigned this Dec 12, 2024
Comment on lines -97 to -99
matched_operation_index: int | None = None
operation_name: str | None = None
pattern_name: str | None = None
Copy link
Member Author

Choose a reason for hiding this comment

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

none of these were really optional

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.73%. Comparing base (f2524d5) to head (ef66e2f).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3631      +/-   ##
==========================================
- Coverage   90.74%   90.73%   -0.01%     
==========================================
  Files         465      465              
  Lines       58733    58734       +1     
  Branches     5629     5632       +3     
==========================================
- Hits        53296    53292       -4     
- Misses       3997     4000       +3     
- Partials     1440     1442       +2     

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

@superlopuh superlopuh changed the title transformations: (apply-indvidual-rewrite) lazily find canonicalization patterns transformations: (apply-inidvidual-rewrite) lazily find canonicalization patterns Dec 12, 2024
Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

Great change, this is one of the parts of the interactive gui which doesn't translate well downstream. It's possible this change fixes that issue.

uv.lock Outdated
@@ -2390,7 +2390,7 @@ wheels = [

[[package]]
name = "xdsl"
version = "0.25.0+89.gb85bb1a8"
version = "0.25.0+37.g414bcb0e.dirty"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks suspicious

Copy link
Member Author

Choose a reason for hiding this comment

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

my bad

] = {
arith.AddiOp: (AdditionOfSameVariablesToMultiplyByTwo(),),
arith.DivUIOp: (DivisionOfSameVariableToOne(),),
INDIVIDUAL_REWRITE_PATTERNS_BY_NAME: dict[str, dict[str, RewritePattern]] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why this change fits into this PR? It's also unclear to me that matching on a string is better than matching on a type

Copy link
Collaborator

Choose a reason for hiding this comment

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

Further, why change this to not being a tuple?

Copy link
Collaborator

Choose a reason for hiding this comment

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

On further thought, why is this necessary at all. Can these two just be made into canonicalization patterns?

Copy link
Member Author

Choose a reason for hiding this comment

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

I promise to make this much neater in the near future, this is just a stop-gap to not change everything at once

Copy link
Member Author

Choose a reason for hiding this comment

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

It's at least not a regression

pattern_name: str | None = None
matched_operation_index: int = field()
operation_name: str = field()
pattern_name: str = field()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had been thinking that it might be more ergonomic here to just store the pattern directly here, instead of storing the name of the pattern and then looking it up, as we currently duplicate the lookup. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

The design is there to accomodate saving the pass pipeline and then reusing it later, and not have it just as state in memory that can't be reproduced without clicking on the same buttons in the ui

Copy link
Collaborator

Choose a reason for hiding this comment

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

fair enough, that makes a lot of sense

associated with each operation, and the values are the corresponding RewritePattern
instances.
"""
def _get_pattern(op: Operation, pattern_name: str) -> RewritePattern | None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _get_pattern(op: Operation, pattern_name: str) -> RewritePattern | None:
def _get_canonicalization_pattern(op: Operation, pattern_name: str) -> RewritePattern | None:

I thought this was including the individual rewrites at first

@alexarice alexarice changed the title transformations: (apply-inidvidual-rewrite) lazily find canonicalization patterns transformations: (apply-individual-rewrite) lazily find canonicalization patterns Dec 12, 2024
@superlopuh superlopuh merged commit 52d4f1c into main Dec 16, 2024
15 checks passed
@superlopuh superlopuh deleted the sasha/gui/individual-rewrite branch December 16, 2024 09:28
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
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants