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

misc: Implement and test dynamic IRDL dialect registering. #2654

Merged
merged 17 commits into from
May 30, 2024

Conversation

PapyChacal
Copy link
Collaborator

This is an implementation - through our interpreter infrastructure - of IRDL dialect registering. That is, at runtime, read an IRDL dialect in MLIR form, and register the described dialect to use right away.

NB: This only implements the steps described here; avoiding any more involved discussion abut how exactly to integrate this in xdsl-opt or hack in Python import mechanism and what not. To be continued!

@PapyChacal PapyChacal added interpreter xDSL Interpreter misc Miscellaneous labels May 29, 2024
@PapyChacal PapyChacal self-assigned this May 29, 2024
@PapyChacal PapyChacal marked this pull request as ready for review May 29, 2024 10:26
Copy link

codecov bot commented May 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.64%. Comparing base (ae12eed) to head (9fc66d5).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2654      +/-   ##
==========================================
+ Coverage   89.63%   89.64%   +0.01%     
==========================================
  Files         362      364       +2     
  Lines       46341    46546     +205     
  Branches     7009     7033      +24     
==========================================
+ Hits        41537    41728     +191     
- Misses       3726     3733       +7     
- Partials     1078     1085       +7     

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

Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

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

Very cool to see this working!
I have some comments on the structure of the interpreter, but otherwise that looks good to me!

In term of testing, I'm wondering if we should not just add this feature to xdsl-opt directly, so we can test it with xdsl-opt --load-irdl="my_file.irdl" my_file.mlir?

xdsl/interpreters/irdl.py Outdated Show resolved Hide resolved
Comment on lines 77 to 83
for k, v in get_accessors_from_param_attr_def(
self.attrs_defs[self.current]
).items():
setattr(self.attrs[op.sym_name], k, v)
setattr(
self.attrs[op.sym_name], "name", f"{self.dialect_name}.{op.sym_name.data}"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel that this should be moved somewhere else?
We should probably have a function in irdl.py that just does all the initialization for an attribute that is being defined? So if we ever refactor something we won't forget this place if that makes sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reminder; This is at the core because EqAttr expect an existing Attribute type.
Because of cyclic references, my first iteration is to first define shallow Attribute types and progressively populate them.
Indeed, a probably cleaner approach would be to first work with more abstract references, and resolve them later.

Do we want to work on this now or on a second PR? Genuine question, I'm not looking forward to this working as much as you AFAIU 😋 So your call!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BUt I might have overinterpreted; I guess literally those lines could be factored out, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thing is, injecting it directly in the type's dictionary is specific to this compromise in the dynamic Dialect creation: IRDL typically creates the full dict and then give it to the type constructor.

We could switch both to this style to duplicate 🤷

Copy link
Collaborator Author

@PapyChacal PapyChacal May 30, 2024

Choose a reason for hiding this comment

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

I rewrote it to get the IRDL code out of the loop and do:

        attr = self.get_attr(interpreter, name)
        attr_def = self._get_attr_def(interpreter, name)
        to_inject = get_accessors_from_param_attr_def(attr_def)
        for k, v in to_inject.items():
            setattr(attr, k, v)

doest it help? It clarifies that the only added thing from already IRDL-factored code is the late injection in the type's dictionary.

I'd love a clean attr.__dict__ |= to_inject, but that is forbidden wizardry 🧙

Copy link
Member

Choose a reason for hiding this comment

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

😱

Comment on lines 111 to 117
for k, v in get_accessors_from_op_def(
self.ops_defs[self.current], None
).items():
setattr(self.ops[op.sym_name], k, v)
setattr(
self.ops[op.sym_name], "name", f"{self.dialect_name}.{op.sym_name.data}"
)
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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tried something on the other comment, will replicate whatever satisfying answer here.

xdsl/interpreters/irdl.py Outdated Show resolved Hide resolved
@math-fehr math-fehr self-requested a review May 30, 2024 14:26
Copy link
Member

@superlopuh superlopuh left a comment

Choose a reason for hiding this comment

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

To me, this is already looking pretty great. Would you mind opening separate PRs for the immprovements to the interpreter.py, irdl.py (core), and irdl.py (dialect) files? Then we can dive into more nitty-gritty interpreter impl things.

@superlopuh
Copy link
Member

Concretely, I think it would be great to have separate unit tests for the name helpers and for set_data on the interpreter.

@superlopuh
Copy link
Member

Looks good now with tests

@PapyChacal PapyChacal merged commit 932d917 into main May 30, 2024
10 checks passed
@PapyChacal PapyChacal deleted the emilien/irdl-interp branch May 30, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter xDSL Interpreter misc Miscellaneous
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants