-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir][affine] Improve --affine-scalrep to identify reduction variables #138005
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Restrict isValidDim to induction vars, and not iter_args
…tomaticAllocationScope This doesnt affect their behavior when they are just called from the command line, since these switches will target the ops nested within the module (which before where func.func, now can be others). Fix affine tests Fix anchor for some passes TODO better fix would be to improve the PassManager to support passes that can run on an arbitrary nesting level. Then these passes could continue to target the root op properly. The fix with Nesting::ImplicitAny is really bad because it changes the anchor of OperationPass<> passes (any anchor) to target children of the root instead of the root. Fix pass manager nesting again
And canonicalize a single-element memref copy into a load and a store. This allows SROA to scalarize the copied elements. Currently SROA cannot handle forwarding of one memory slot to another.
causing relinking of many libs when a change to Pass.cpp is made
It had a bug whereby the regions of an op are marked as dead code, and their successors are not properly populated, if any operand of a RegionBranchOpInterface is not folded to a constant. The interface already is meant to support partially-folded operands, so we should use that instead of giving up. Some changes are also just to make debug prints more helpful. Some of them were printing pointer addresses.
The problem is that the live in set is not necessarily already populated when we ask for the start op
in the case where the subview op uses an index of an affine loop as eg, the offset. The previous implementation always generated symbols, and the verifier failed, although the transformation is valid if you just generate dims for the variables that are not symbols, but are valid dims.
and not just plain dims and symbols. This makes it possible to fold memref.subview ops that use an affine expression of valid symbol and dims as an offset, even if that expression is computed by arith ops like muli and addi.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: this is a reopening of #118987 which I inadvertently closed.
Improve the affine scalar replacement pass to identify memref accesses that are used as a reduction variable, and turn them into
iter_argsvariables. For instance in:the load/store pattern on
%minin the inner loop is characteristic of a reduction. The memory location%min[%i]is invariant on the inner loop induction var, so it is basically used as a scalar. We can rewrite this loop to the following:where this memory location is "scalarized" as an
iter_argsvariable. This allows existing affine passes to apply more optimizations on the reduction loop, eg, it can be vectorized, or it can be turned into anaffine.parallelloop with a combiner for the reduction.This kind of code pattern is often found in the affine loops generated from linalg code, so I think it's very useful to include this.
I expect maybe some backlash over why I put this into the scalar replacement pass instead of a new pass. I think this is justfied because
iter_argsvariable. So even if it seems unrelated to the load-store forwardings that the pass is currently doing, I think it still fits within the scope of--affine-scalrep.Thanks for reading!