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

[MLIR] Generalize expand_shape to take shape as explicit input #69267

Merged
merged 1 commit into from
Apr 21, 2024

Conversation

Shukla-Gaurav
Copy link
Contributor

@Shukla-Gaurav Shukla-Gaurav commented Oct 17, 2023

This patch generalizes tensor.expand_shape and memref.expand_shape to consume the output shape as a list of SSA values. This enables us to implement generic reshape operations with dynamic shapes using collapse_shape/expand_shape pairs.

The output_shape input to expand_shape follows the static/dynamic representation that's also used in tensor.extract_slice.

Differential Revision: https://reviews.llvm.org/D140821

Copy link
Contributor

@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.

Ok, I think this is not looking too bad. Adding the helper build method here would make the diff much smaller I think.

mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h Outdated Show resolved Hide resolved
mlir/lib/Conversion/TosaToTensor/TosaToTensor.cpp Outdated Show resolved Hide resolved
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp Outdated Show resolved Hide resolved
mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Oct 19, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@MaheshRavishankar
Copy link
Contributor

Hey, I left a few comments. Let me know when this is ready for review.

Copy link
Contributor

@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.

Next rounds of comments. Thanks!

mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td Outdated Show resolved Hide resolved
mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp Outdated Show resolved Hide resolved
mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp Outdated Show resolved Hide resolved
@Shukla-Gaurav Shukla-Gaurav force-pushed the arcpatch-D140821 branch 2 times, most recently from dec4859 to f9d0f60 Compare October 30, 2023 16:09
@Shukla-Gaurav
Copy link
Contributor Author

@MaheshRavishankar Thanks for reviewing, have addressed all the comments, and is ready for re-review.
@ramiro050 @sanjoy Thanks for implementing this, it was needed for a long time. As I am continuing this, would love to have your review on this.

Copy link
Contributor

@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.

ok, this looks good to me. Lets test this with IREE. Ill let you know how to do that.

Copy link
Contributor

@ramiro050 ramiro050 left a comment

Choose a reason for hiding this comment

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

Thanks for getting this across the finish line! LGTM

@Shukla-Gaurav Shukla-Gaurav changed the title [DRAFT] Generalize expand_shape to take shape as explicit input [MLIR] Generalize expand_shape to take shape as explicit input Nov 30, 2023
Shukla-Gaurav added a commit to Shukla-Gaurav/iree that referenced this pull request Apr 16, 2024
*DO NOT SUBMIT*
This commit is to test and fix the bugs introduced by importing
tensor.expand_shape changes in IREE.
(check here llvm/llvm-project#69267)

Signed-Off-by: Gaurav Shukla <gashukla@amd.com>
@Shukla-Gaurav
Copy link
Contributor Author

@MaheshRavishankar Could you please re-review it? There is still one failure in reshape_fusion(as discussed), meanwhile I can fix that. Thanks :)

@aartbik
Copy link
Contributor

aartbik commented Apr 17, 2024

I added a comment that has not been addressed yet?

Copy link
Contributor

@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.

Thanks! Left a few mostly minor comments. Nothing that I see as blocker for landing.

mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td Outdated Show resolved Hide resolved
mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td Outdated Show resolved Hide resolved
mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td Outdated Show resolved Hide resolved
mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td Outdated Show resolved Hide resolved
mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td Outdated Show resolved Hide resolved
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp Outdated Show resolved Hide resolved
mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp Outdated Show resolved Hide resolved
mlir/include/mlir/Dialect/Utils/ReshapeOpsUtils.h Outdated Show resolved Hide resolved
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp Outdated Show resolved Hide resolved
mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp Show resolved Hide resolved
Copy link
Contributor

@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.

Ok, looks ogod to me. Left a single comment but it is not a blocker and is OK to do it after this PR as well since that part needs to be fixed after this PR lands.

@bjacob
Copy link
Contributor

bjacob commented Apr 19, 2024

Ok, looks ogod to me. Left a single comment but it is not a blocker and is OK to do it after this PR as well since that part needs to be fixed after this PR lands.

yes please please do as follow-up and not lose the progress on (very slow) CI here :-)

@bjacob
Copy link
Contributor

bjacob commented Apr 21, 2024

Windows CI failed with

fatal error C1060: compiler is out of heap space

Probably unrelated to this PR, but also not completely impossible that something about this PR increases compiler memory usage and pushes it over a threshold, so we need to get a green CI run before merging. Unfortunately I don't see a "retrigger" button here. Can you push an empty commit to this PR to cause a retrigger maybe?

This patch generalizes tensor.expand_shape and memref.expand_shape to consume
the output shape as a list of SSA values.  This enables us to implement generic
reshape operations with dynamic shapes using collapse_shape/expand_shape pairs.

The output_shape input to expand_shape follows the static/dynamic representation
that's also used in `tensor.extract_slice`.

Differential Revision: https://reviews.llvm.org/D140821
@bjacob bjacob merged commit e095d97 into llvm:main Apr 21, 2024
4 checks passed
@joker-eph
Copy link
Collaborator

I think this broke the bot: https://lab.llvm.org/buildbot/#/builders/61/builds/57064

@joker-eph
Copy link
Collaborator

Reverted in #89540

aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 21, 2024
…69267)

This patch generalizes tensor.expand_shape and memref.expand_shape to
consume the output shape as a list of SSA values. This enables us to
implement generic reshape operations with dynamic shapes using
collapse_shape/expand_shape pairs.

The output_shape input to expand_shape follows the static/dynamic
representation that's also used in `tensor.extract_slice`.

Differential Revision: https://reviews.llvm.org/D140821

Co-authored-by: Ramiro Leal-Cavazos <ramiroleal050@gmail.com>
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel "Peripheral" support tier build system: utils/bazel mlir:bufferization Bufferization infrastructure mlir:linalg mlir:memref mlir:sparse Sparse compiler in MLIR mlir:tensor mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants