-
Notifications
You must be signed in to change notification settings - Fork 77
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
transforms: add restrict flag to StencilShapeMinimize pass #3411
Conversation
Could you please complete the checklist in the description? |
Co-authored-by: Nicolai Stawinoga <36768051+n-io@users.noreply.github.com>
Co-authored-by: Nicolai Stawinoga <36768051+n-io@users.noreply.github.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3411 +/- ##
==========================================
+ Coverage 90.15% 90.17% +0.01%
==========================================
Files 455 456 +1
Lines 57429 57562 +133
Branches 5530 5543 +13
==========================================
+ Hits 51775 51905 +130
- Misses 4195 4197 +2
- Partials 1459 1460 +1 ☔ View full report in Codecov by Sentry. |
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.
Great, while there are ways to combine this into one filecheck mlir file (if you grep for --check-prefix
), you could also make a new one. Happy to help with either way.
Co-authored-by: Nicolai Stawinoga <36768051+n-io@users.noreply.github.com>
any help on how to get started on this would be greatly appreciated! |
I just pushed a filecheck to your branch, but it will likely break. The last thing to do is to run shape inference ( |
@@ -91,6 +92,7 @@ def apply(self, ctx: MLContext, op: builtin.ModuleOp) -> None: | |||
] | |||
) | |||
).rewrite_module(op) | |||
ShapeInferencePass().apply(ctx, op) |
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.
I would recommend against this
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.
@n-io, what's the motivation for doing this inside the pass and not as part of the pass pipeline?
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.
The most immediate purpose is to undo the InvalidateTemps()
rewrite pattern. The pass in general is super useful for restricting the stencil grid size to something small enough that for instance it can be run in a simulator. The idea is simple: invalidate temps, modify size on store ops, un-invalidate temps. The result will then be picked up by stencil-shape-minimize
, which will handle the rest. The only alternative would be to separate this out from shape-minimize altogether, though running stencil-shape-minimize{restrict=30,30,30}
seems to make a lot of sense in my head instead of having it as a fully independent pass, and I do think they have to be run together in order to produce a program that passes validation (which we want after every logical pass).
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.
Ah OK, that makes sense. The main thing that triggered me was calling a pass inside of another pass, for the same reason, as the contract is that a pass leaves the IR in a valid state, if the IR is in a valid state to begin with. In that sense it would make sense to split out the body of the shape inference pass into a helper method, and to call into that from here.
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.
I've seen this done in a few places, though was never sure why helper methods are preferred, including by post_walk_func
?
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.
My understanding is that it's preferable to expose the least restrictive API when possible. For example, there's no need to pass the context when performing shape inference. It's probably also to make things more flexible in general, like you may want to only perform shape inference on a subset of your module.
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.
I'm not sure I follow - do I need to make some updates here?
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.
Yes, please! Could pull out the body of the shape inference pass into a python function that takes any operation, and no MLContext, and call that helper function from here instead of the pass?
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.
ok, thank you!
Co-authored-by: Nicolai Stawinoga <36768051+n-io@users.noreply.github.com>
Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
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.
It would probably be good to get @n-io's tick before merging, but LGTM!
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.
LGTM, feel free to merge!
…ct#3411) Add a restrict flag to the StencilShapeMinimize pass which restricts the grid size of a stencil computation. --------- Co-authored-by: emmau678 <eu233@Emma-laptop> Co-authored-by: Nicolai Stawinoga <36768051+n-io@users.noreply.github.com> Co-authored-by: n-io <n-io@users.noreply.github.com> Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
Add a restrict flag to the StencilShapeMinimize pass which restricts the grid size of a stencil computation.