Skip to content

[mlir] Check if the stride tensor is empty. #76428

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

Merged
merged 3 commits into from
Jan 3, 2024
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
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ bool vector::isContiguousSlice(MemRefType memrefType, VectorType vectorType) {
return false;

// Cond 1: A contiguous memref will always have a unit trailing stride.
if (strides.back() != 1)
if (strides.empty() || strides.back() != 1)
return false;

// Cond 2: Strides of a contiguous memref have to match the flattened dims.
Expand Down
15 changes: 15 additions & 0 deletions mlir/test/Dialect/Vector/vector-transfer-flatten.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,18 @@ func.func @fold_unit_dims_entirely(%arg0 : vector<8xi32>,
// CHECK: %[[VAL_3:.*]] = arith.muli %[[VAL_0]], %[[VAL_1]] : vector<8xi32>
// CHECK: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_2]] : vector<8xi32>
// CHECK: return %[[VAL_4]] : vector<8xi32>

// -----

// This test is to make sure there is no crash for empty stride.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not add a proper test instead? That would defend against any future breakage and also test one more quite relevant case.

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 am sorry but I don't understand. What do you mean by a proper test? This test is a simplification of the original test that was breaking. Without my change it will break the same way, and and with my change it will not crash and run to completion. The comment was added to show why the test was added. I also added some CHECK tags with the tests, to make sure it is executing.

Copy link
Contributor

Choose a reason for hiding this comment

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

The “check” lines added, unlike for other tests in this file, do not reveal/check/verify/document the expected behaviour for this case. Well, apart from making sure that the transformation doesn’t crash.

Tl,Dr Please add more check lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for explaining it for me! I added more checks. I also added a check-not for for the error message string that the crash would cause.

func.func @stride_empty_test(%1: memref<i16>) -> vector<32x256xi16> {
%c0_i16 = arith.constant 0 : i16
%3 = vector.transfer_read %1[], %c0_i16 {permutation_map = affine_map<() -> (0, 0)>} : memref<i16>, vector<32x256xi16>
return %3 : vector<32x256xi16>

// CHECK-LABEL: func.func @stride_empty_test
// CHECK: %[[VAL:.*]] = arith.constant 0 : i16
// CHECK: %[[RET:.*]] = vector.transfer_read {{.*}} vector<32x256xi16>
// CHECK: return %[[RET]]
// CHECK-NOT: empty()
}