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

Fix rank-mismatch issue in flow.tensor.reshape folders. #5475

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions iree/compiler/Dialect/Flow/IR/FlowOpFolders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ static bool compareShapesEqual(ShapedType lhsType, ValueRange lhsDynamicDims,
// Static shape equivalence means we can fast-path the check.
return true;
}
if (lhsType.getRank() != rhsType.getRank()) {
MaheshRavishankar marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
unsigned dynamicDimIndex = 0;
for (unsigned i = 0; i < lhsType.getRank(); ++i) {
if (lhsType.isDynamicDim(i) != rhsType.isDynamicDim(i)) {
Expand Down
9 changes: 9 additions & 0 deletions iree/compiler/Dialect/Flow/IR/test/tensor_folding.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ func @reshapeNoOpStatic(%arg0: tensor<4x4xf32>) -> tensor<4x4xf32> {

// -----

// CHECK-LABEL: @reshapeRankDifferent
func @reshapeRankDifferent(%arg0: tensor<1xf32>) -> tensor<f32> {
// CHECK-NEXT: flow.tensor.reshape %arg0
%0 = flow.tensor.reshape %arg0 : tensor<1xf32> -> tensor<f32>
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting test case. I would think this should be a special case and should be treated as the same. THe number of elements is 1 in the source and 0 in the target, but is really 1 in reality.

@benvanik any thoughts?

return %0 : tensor<f32>
}

// -----

// CHECK-LABEL: @reshapeStaticDifferent
func @reshapeStaticDifferent(%arg0: tensor<1x4xf32>) -> tensor<4x1xf32> {
// CHECK-NEXT: flow.tensor.reshape %arg0
Expand Down