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

interpreter: (pdl) add an initial version of EqSat PDL Interpreter #3572

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jianyicheng
Copy link
Collaborator

This is an initial attempt of adding a PDL interpreter for EqSat because rewrites in EqSat does not replace operations but append new operations into existing ops.
This PR also includes a unit test for the eqsat interpreter.

@jianyicheng jianyicheng added the interpreter xDSL Interpreter label Dec 5, 2024
@jianyicheng jianyicheng self-assigned this Dec 5, 2024
Comment on lines 19 to 32
@dataclass
class EqsatPDLMatcher(PDLMatcher):
def match_operand(
self, ssa_val: SSAValue, pdl_op: pdl.OperandOp, xdsl_val: SSAValue
):
owner = xdsl_val.owner
assert isinstance(owner, eqsat.EClassOp)
assert (
len(owner.operands) == 1
), "newly converted eqsat always has 1 element in eclass"
arg = owner.operands[0]
res = super().match_operand(ssa_val, pdl_op, arg)
# self.value_to_eclass[arg] = owner
return res
Copy link
Member

Choose a reason for hiding this comment

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

could you please open a first PR that just adds this, and adds a corresponding pytest unit test for this in the style of the existing pdl matching tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean splitting this PR into two (Matcher and Rewriter)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created an PR here: #3574

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jianyicheng - is it correct that this assert implies the matched e-class has at most one element?
If I update the testcase to respect (a+b)+c - then you get an e-class with two elements - is that correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@cowardsa
I think this PR only targets the example of swapping inputs for (a+b) to help review. Future PRs can target (a+b)+c progressively.

if isinstance(op, pdl.RewriteOp)
]
pattern_applier = GreedyRewritePatternApplier(rewrite_patterns)
# TODO: remove apply_recursively=False
Copy link
Member

@superlopuh superlopuh Dec 5, 2024

Choose a reason for hiding this comment

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

outdated comment

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.40%. Comparing base (dd58ef0) to head (45d8f71).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3572    +/-   ##
========================================
  Coverage   90.40%   90.40%            
========================================
  Files         469      470     +1     
  Lines       58907    59058   +151     
  Branches     5605     5625    +20     
========================================
+ Hits        53252    53389   +137     
- Misses       4213     4221     +8     
- Partials     1442     1448     +6     

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

@jianyicheng jianyicheng changed the base branch from main to jianyi/eqsat/pdl_matcher December 5, 2024 15:15
Base automatically changed from jianyi/eqsat/pdl_matcher to main December 5, 2024 15:37
@jianyicheng jianyicheng marked this pull request as draft December 5, 2024 15:40
@jianyicheng
Copy link
Collaborator Author

@superlopuh Do we need to split this PR further, or this is okay to merge?

self.interpreter.push_scope("rewrite")
self.interpreter.set_values(matcher.matching_context.items())
self.functions.rewriter = rewriter
# self.functions.value_to_eclass = matcher.value_to_eclass
Copy link
Member

Choose a reason for hiding this comment

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

commented code

Comment on lines +64 to +67
assert pdl_op_val is not None, "TODO: handle None root op in pdl.RewriteOp"
assert (
self.pdl_rewrite_op.body is not None
), "TODO: handle None body op in pdl.RewriteOp"
Copy link
Member

Choose a reason for hiding this comment

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

could you please raise DiagnosticExceptions here and add filecheck tests for them?

Comment on lines +143 to +144
# How to deal with operandSegmentSizes?
# operand_values, attribute_values, type_values = args
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# How to deal with operandSegmentSizes?
# operand_values, attribute_values, type_values = args

@superlopuh
Copy link
Member

Ideally we'd like unit tests for each interpreter method, but I also think that it should be ok to add these as this project progresses further. I added some TODOs as I was prototyping things, but we try to avoid them in main, could you please add a test that checks for these specifically? Ideally also for the NotImplementedError in the interpreter.

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

Successfully merging this pull request may close these issues.

3 participants