Skip to content

[Global Opt] Don't propagate edge reshapes#22320

Merged
IanWood1 merged 2 commits intoiree-org:mainfrom
IanWood1:tpose_prop_edge_reshapes
Oct 17, 2025
Merged

[Global Opt] Don't propagate edge reshapes#22320
IanWood1 merged 2 commits intoiree-org:mainfrom
IanWood1:tpose_prop_edge_reshapes

Conversation

@IanWood1
Copy link
Contributor

Prevent propagating reshapes on the edges of the program in PropagateLinalgTranspose since these reshapes don't block the propagation of transposes. This is similar to what is done in BubbleUpExpandShapes:

// Don't reintroduce unit dims via propagating edge unit dim reshapes.
if (auto expandOp = dyn_cast<tensor::ExpandShapeOp>(consumer);
expandOp &&
isExpandingUnitDims(expandOp.getReassociationIndices(),
expandOp.getResultType().getShape()) &&
llvm::none_of(
consumer->getUsers(), [&](Operation *collapseConsumer) {
return isReshapeBlockingFusion(producer, collapseConsumer);
})) {
return false;
}
if (auto collapseOp = dyn_cast<tensor::CollapseShapeOp>(producer);
collapseOp &&
isExpandingUnitDims(collapseOp.getReassociationIndices(),
collapseOp.getSrcType().getShape()) &&
!isReshapeBlockingFusion(producer->getOperand(0).getDefiningOp(),
consumer)) {
return false;
}

Closes #22312

Signed-off-by: Ian Wood <ianwood@u.northwestern.edu>

// -----

util.func public @sink_non_involution_through_expand_shape(%arg0 : tensor<2x3x4xf32>) -> tensor<1x3x4x2xf32> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we want to keep this behavior... Cause this might allow the transpose to fuse with its consumers...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point is that the reshapes are on the edge so that there will be no producer/consumers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure I follow. The test is changing the behavior that is different than what I assume the end state of the code should be. Could you provide more details here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that BubbleUpExpandShapes is not perfect and doesn't currently sink reshapes through reduction operations. The idea is to not touch reshapes that are on the edges of the program since they might get stuck on a reduction operation. This shouldn't harm transpose propagation because these reshapes are on the edges and won't block any transposes from getting propagated throughout the program.

Also, I added some more context on the issue with the mlir before and after this pass #22312

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the better solution is make a change to BubbleUpExpandShapes, I'm testing if there are any regressions #22341

// -----

util.func public @bubble_non_involution_through_collapse_shape(%arg0 : tensor<1x2x3x5x7x11xf32>) -> tensor<35x11x6xf32> {
%collapsed = tensor.collapse_shape %arg0 [[0, 1, 2], [3, 4], [5]] : tensor<1x2x3x5x7x11xf32> into tensor<6x35x11xf32>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here. The transpose could fuse with its producers.

@MaheshRavishankar
Copy link
Collaborator

Could you post some more details of the problem (preferably on the issue)

Signed-off-by: Ian Wood <ianwood@u.northwestern.edu>
Copy link
Collaborator

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

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

Lets land this for now based on what we see as issues with a "more proper way". We would probably need to revisit this though.

@IanWood1 IanWood1 merged commit 189dc86 into iree-org:main Oct 17, 2025
46 checks passed
weidel-p pushed a commit to weidel-p/iree that referenced this pull request Oct 21, 2025
Prevent propagating reshapes on the edges of the program in
PropagateLinalgTranspose since these reshapes don't block the
propagation of transposes. This is similar to what is done in
BubbleUpExpandShapes:
https://github.com/iree-org/iree/blob/dad4b2d1cab357720a73c05d7bf6e1b946668082/compiler/src/iree/compiler/DispatchCreation/BubbleUpExpandShapes.cpp#L441-L459



Closes iree-org#22312

---------

Signed-off-by: Ian Wood <ianwood@u.northwestern.edu>
Signed-off-by: Philipp <philipp.weidel@intel.com>
sjain-stanford added a commit to nod-ai/amd-shark-ai that referenced this pull request Oct 23, 2025
AaronStGeorge pushed a commit to AaronStGeorge/rocm-libraries that referenced this pull request Oct 23, 2025
AaronStGeorge pushed a commit to AaronStGeorge/rocm-libraries that referenced this pull request Oct 24, 2025
AaronStGeorge pushed a commit to ROCm/rocm-libraries that referenced this pull request Oct 24, 2025
IanWood1 added a commit that referenced this pull request Oct 28, 2025
Adds flag to allow users to selectively disable the changes from
#22320. This is a stopgap for cases
where not fusing a transpose into a matmul gives better performance.

Signed-off-by: Ian Wood <ianwood@u.northwestern.edu>
bangtianliu pushed a commit to bangtianliu/iree that referenced this pull request Oct 30, 2025
…2438)

Adds flag to allow users to selectively disable the changes from
iree-org#22320. This is a stopgap for cases
where not fusing a transpose into a matmul gives better performance.

Signed-off-by: Ian Wood <ianwood@u.northwestern.edu>
AaronStGeorge pushed a commit to AaronStGeorge/fusilli that referenced this pull request Nov 18, 2025
bangtianliu pushed a commit to bangtianliu/iree that referenced this pull request Nov 19, 2025
…2438)

Adds flag to allow users to selectively disable the changes from
iree-org#22320. This is a stopgap for cases
where not fusing a transpose into a matmul gives better performance.

Signed-off-by: Ian Wood <ianwood@u.northwestern.edu>
pstarkcdpr pushed a commit to pstarkcdpr/iree that referenced this pull request Nov 28, 2025
Prevent propagating reshapes on the edges of the program in
PropagateLinalgTranspose since these reshapes don't block the
propagation of transposes. This is similar to what is done in
BubbleUpExpandShapes:
https://github.com/iree-org/iree/blob/dad4b2d1cab357720a73c05d7bf6e1b946668082/compiler/src/iree/compiler/DispatchCreation/BubbleUpExpandShapes.cpp#L441-L459



Closes iree-org#22312

---------

Signed-off-by: Ian Wood <ianwood@u.northwestern.edu>
pstarkcdpr pushed a commit to pstarkcdpr/iree that referenced this pull request Nov 28, 2025
…2438)

Adds flag to allow users to selectively disable the changes from
iree-org#22320. This is a stopgap for cases
where not fusing a transpose into a matmul gives better performance.

Signed-off-by: Ian Wood <ianwood@u.northwestern.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3D conv compilation resulting in two dispatches

2 participants