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

core: Implement EffectKind #2793

Merged
merged 30 commits into from
Jul 5, 2024
Merged

core: Implement EffectKind #2793

merged 30 commits into from
Jul 5, 2024

Conversation

PapyChacal
Copy link
Collaborator

Implement EffectKind, sepcifying READ, WRITE, ALLOC or FREE side-effects.

Use it to enable our MemoryEffect to return this more precise information, and leverage it in DCE (an unused read-only effect is safe to erase) and CSE (A duplicate read-only is safe to replace with an earlier one if we can ensure there was no write in-between)

MLIR further enables to express side-effects tied to specific resources and values, but this a little step forward.

@PapyChacal PapyChacal added the core xDSL core (ir, textual format, ...) label Jun 27, 2024
@PapyChacal PapyChacal self-assigned this Jun 27, 2024
xdsl/traits.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.83%. Comparing base (094a0e0) to head (38e56df).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2793   +/-   ##
=======================================
  Coverage   89.83%   89.83%           
=======================================
  Files         396      396           
  Lines       49139    49233   +94     
  Branches     7533     7546   +13     
=======================================
+ Hits        44145    44230   +85     
- Misses       3804     3813    +9     
  Partials     1190     1190           

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

Copy link
Contributor

@zero9178 zero9178 left a comment

Choose a reason for hiding this comment

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

PR and code LGTM and matches MLIR with the more limited feature set (any reason this is still a draft acutally? I'd stamp otherwise).

One thing worth considering at your discretion:
One annoyance I've always had with this interface in MLIR is that if an Op implemented the trait/interface, it was impossible for the op to dynamically (based on attributes e.g.) be able to say "I am side effect free" or "I affect the universe" (the same as an op not implementing the interface basically). This is because both in this PR and in MLIR, returning an empty set means "no side effect".
If it instead returned a set | None (or similar) then we could encode None to mean the same as a missing trait implementation (effects the universe).

A common ues case for this would be a call op e.g. The call op may be annotated with a pure attribute and in that case you want it to not have any side effects. If it doesn't, you'll want it to affect the universe

Thought I'd mention this now so that if you do want it, that you don't have to go through the refacotring churn twice.

@PapyChacal PapyChacal marked this pull request as ready for review June 27, 2024 20:13
@PapyChacal
Copy link
Collaborator Author

Interesting point, thanks!! I'll give it some thought and would love to discuss it, as I'm lass experienced on that side of things. My first thought is to ask if that option isn't still limited. It still means arbitrary but finite effects of some kind, or absolutely everything, right?

What about reading the universe while writing to a defined part? Genuinely wondering as I'm not sure it would either represent something practical or enable more powerful anything 🤔

@zero9178
Copy link
Contributor

It still means arbitrary but finite effects of some kind, or absolutely everything, right?

It generally means absolutely everything yes. The most conservative answer.

What about reading the universe while writing to a defined part? Genuinely wondering as I'm not sure it would either represent something practical or enable more powerful anything 🤔

Good question. This is currently unimplemented in MLIR as well as there is no special value for the universe right now. I've seen this come up from time to time in discussions but haven't seen anyone actually try to implement it. MLIR does have the concept of Resources on side effects but these represent distinct aka non-aliasing regions. Ideas to implement this would be making a universe resource and/or allowing resources to specify the aliasing relationship between them.

@PapyChacal
Copy link
Collaborator Author

What about reading the universe while writing to a defined part? Genuinely wondering as I'm not sure it would either represent something practical or enable more powerful anything 🤔

Good question. This is currently unimplemented in MLIR as well as there is no special value for the universe right now. I've seen this come up from time to time in discussions but haven't seen anyone actually try to implement it. MLIR does have the concept of Resources on side effects but these represent distinct aka non-aliasing regions. Ideas to implement this would be making a universe resource and/or allowing resources to specify the aliasing relationship between them.

Right, I guess the best end-game answer is building an aliasing framework for resources indeed, having a Universe defined as aliasing everything.
But yeah, interesting questions in themselves, but in practice, I'm trying to get basics running in xDSL here rather than exploring that side of things; so I think I'll just go with the easy None escape-hatch here and stay out of the rabbit hole myself 🐰

Thanks a lot for the discussion though, didn't cross my mind yet!

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.

Really cool! I will not lie, I did not try to understand the entire algorithm, I just trust you there ;)

xdsl/dialects/test.py Show resolved Hide resolved
xdsl/traits.py Outdated Show resolved Hide resolved
xdsl/traits.py Outdated Show resolved Hide resolved
xdsl/traits.py Outdated Show resolved Hide resolved
xdsl/traits.py Outdated Show resolved Hide resolved
@PapyChacal
Copy link
Collaborator Author

I hear your point; to clarify mine, by sugar, I meant my own proposal of helper base classes, not the composability, which indeed is a bit more core.

I'll add composability; unless I realize an awful consequence or what not

On the sugar : I think the vast majority of implementations will be "have effect(s) a if b(op)", so a cute wrapper parametrized by an effect and predicate would help a lot I think; especially with composability included!

@AntonLydike
Copy link
Collaborator

I hear your point; to clarify mine, by sugar, I meant my own proposal of helper base classes, not the composability, which indeed is a bit more core.

Ah yes, this makes much more sense!

I'll add composability; unless I realize an awful consequence or what not

Let's hope it's all fine! 🤞

On the sugar : I think the vast majority of implementations will be "have effect(s) a if b(op)", so a cute wrapper parametrized by an effect and predicate would help a lot I think; especially with composability included!

Agree 100%. I guess I could see two traits for different kinds of efffects (e.g. HasReadEffectIf... and HasWriteEffectIf...) that may be mixed and matched by ops. At least this feels like a somewhat natural thing to do.

Looking forward to us being at that stage!

xdsl/traits.py Outdated Show resolved Hide resolved
…veMemoryEffect in terms of MemoryEffect again.

rename to get_effets.
@PapyChacal PapyChacal requested a review from AntonLydike June 29, 2024 01:29
xdsl/traits.py Outdated Show resolved Hide resolved
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.

Nice 🚀

xdsl/traits.py Outdated Show resolved Hide resolved
xdsl/traits.py Outdated Show resolved Hide resolved
xdsl/traits.py Show resolved Hide resolved
xdsl/transforms/dead_code_elimination.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@webmiche webmiche left a comment

Choose a reason for hiding this comment

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

Cool concept, really like it 👍

xdsl/traits.py Show resolved Hide resolved
xdsl/traits.py Show resolved Hide resolved
@PapyChacal PapyChacal merged commit 9e2bf03 into main Jul 5, 2024
9 checks passed
@PapyChacal PapyChacal deleted the emilien/effect-kind branch July 5, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core xDSL core (ir, textual format, ...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants