Repository navigation
[Codegen] Add SwapExtractWithCollapsePattern - #21419
Merged
Merged
Conversation
yzhang93
requested review from
antiagainst,
hanhanW and
qedawkins
as code owners
July 18, 2025 22:08
Signed-off-by: yzhang93 <[email protected]>
yzhang93
force-pushed
the
swap_collapse_with_slice
branch
from
July 18, 2025 22:10
0a411b0 to
bd3b05d
Compare
yzhang93
commented
Jul 18, 2025
| if (isa<Value>(collapsedSize) || isa<Value>(collapsedOffset)) { | ||
| // Special case especially for collapse shape of convolution filter in | ||
| // IGEMM, while the offset is dynamic and the size is static. | ||
| if (isa<Attribute>(collapsedSize) && isa<Value>(collapsedOffset) && |
Contributor
Author
There was a problem hiding this comment.
From here to line 544 is the added special case.
Signed-off-by: yzhang93 <[email protected]>
Max191
reviewed
Jul 21, 2025
Max191
left a comment
Contributor
There was a problem hiding this comment.
First round of comments. If we can do the fusion in GPUFuseAndHoistParallelLoops, then it would be good to avoid adding the new pass option.
Signed-off-by: yzhang93 <[email protected]>
Signed-off-by: yzhang93 <[email protected]>
Max191
approved these changes
Jul 24, 2025
Comment on lines
+486
to
+489
| if (map.getNumInputs() != 1 || map.getNumResults() != 1) { | ||
| return rewriter.notifyMatchFailure( | ||
| sliceOp, "affine.apply must have one input and one result"); | ||
| } |
Contributor
There was a problem hiding this comment.
I think having multiple inputs is okay, as long as there is a single result. isMultipleOf only checks the result, so the number of inputs shouldn't matter.
Signed-off-by: yzhang93 <[email protected]>
yzhang93
enabled auto-merge (squash)
July 24, 2025 20:01
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
This PR adds a pattern to swap the `collapse_shape` with the `extract_slice` op to enable more loop fusion opportunity. Note this pattern is adapted from the upstream[ `BubbleUpCollapseShapeThroughExtractSlice`](https://github.com/llvm/llvm-project/blob/ffb453989b0e95d85b6cfa543b65fec23b65649d/mlir/lib/Dialect/Tensor/Transforms/ReshapePatterns.cpp#L322) by allowing some special cases we've seen through the IGEMM path. The special case is processed under `CASE #1` session with the corresponding tests mainly focusing on the changes. Note that some strict conditions are added to match the special case for convolutions which maybe not general and robust enough to add to upstream. In addition, we break the [upstream single pattern](https://github.com/llvm/llvm-project/blob/ffb453989b0e95d85b6cfa543b65fec23b65649d/mlir/lib/Dialect/Tensor/Transforms/ReshapePatterns.cpp#L767) into two separate ones to be able to apply them separately in different passes. --------- Signed-off-by: yzhang93 <[email protected]>
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
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.
This PR adds a pattern to swap the
collapse_shapewith theextract_sliceop to enable more loop fusion opportunity. Note this pattern is adapted from the upstreamBubbleUpCollapseShapeThroughExtractSliceby allowing some special cases we've seen through the IGEMM path.The special case is processed under
CASE #1session with the corresponding tests mainly focusing on the changes. Note that some strict conditions are added to match the special case for convolutions which maybe not general and robust enough to add to upstream. In addition, we break the upstream single pattern into two separate ones to be able to apply them separately in different passes.