-
Couldn't load subscription status.
- Fork 75
[NFI]: XPUBackend refactoring to facilitate arch-specific implementations #5329
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering whether we should use easier to understand alternative. Have you considered:
- Inheritance: create a base class that can be derived (my preference)
- class Decorators to modify the behavior of the BE after creation
XPUBackend is the base class. Arch-specific implementations derive from it and override the required methods. For example, they could override
It could be done, by defining a metaclass, but the inheritance should be used in most use-cases. |
2c0c89d to
055acd2
Compare
| return pm | ||
|
|
||
| @classmethod | ||
| def get_ttir_passes(cls, opt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we separate the changes about get_*ir_passes in another PR? I am not sure I like it, but the other changes don't need to be blocked by it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
- Allow metaclasses injection: use XPUBackendMeta from the .meta submodule as the metaclass, if it exists. - Try to find an arch-specific implementation in the .arch.<name> submodule. - Create the list of passes in separate methods to allow subclasses to modify it.
055acd2 to
abbf291
Compare
| def make_ttir(mod, metadata, opt): | ||
| pm = ir.pass_manager(mod.context) | ||
| @classmethod | ||
| def create_pass_manager(cls, context): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the benefit of create_pass_manager? is it going to be different for other arch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the initial version it also added passes to the pm - 65c9f8a#diff-5ec0c116ff4361ab1b5db32636583aaf2da599bda46558aab877dc5670a77a39R206 . I've removed this functionality, but kept the method to save on duplication of 2 lines of code :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it is ok not to save 2 lines of code duplication in exchange for easy comparison with other backends.
The purpose of this refactoring is to simplify development for new architectures by subclassing the base class instead of adding conditional code blocks.
The main changes:
.arch.<name>submodule.