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

Conversation

bviyer
Copy link
Contributor

@bviyer bviyer commented Dec 27, 2023

Added a check to see if the stride tensor is empty. If so then return false for isContiguousSlice function.

Possible fix for #74463

Added a check to see if the stride tensor is empty. If so then
return false for isContiguousSlice function.

Possible fix for llvm#74463
@llvmbot
Copy link
Member

llvmbot commented Dec 27, 2023

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-vector

Author: Balaji V. Iyer. (bviyer)

Changes

Added a check to see if the stride tensor is empty. If so then return false for isContiguousSlice function.

Possible fix for #74463


Full diff: https://github.com/llvm/llvm-project/pull/76428.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp (+1-1)
diff --git a/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp b/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
index 2ad992af989c96..c1c0f5483a6af5 100644
--- a/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
+++ b/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp
@@ -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.

@rikhuijzer
Copy link
Member

Possible fix for #74463

Can you see whether you can simplify the bug as much as possible (simplify the reproducer code) and add it to the tests? Without it, the code that this PR changed might be changed by someone else again in the future and then we need to fix it again. Adding a test will ensure that it is fixed and remains fixed.

@banach-space
Copy link
Contributor

Thanks for the fix! We will need a test before this can be merged.

@bviyer
Copy link
Contributor Author

bviyer commented Dec 27, 2023

I added a test case here 125d919


// -----

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

the error message that comes during the crash.
@bviyer bviyer requested a review from banach-space January 2, 2024 04:23
@banach-space
Copy link
Contributor

Thanks for the fix, LGTM!

@bviyer bviyer merged commit 21fe8b6 into llvm:main Jan 3, 2024
banach-space added a commit to banach-space/llvm-project that referenced this pull request Jan 8, 2024
As per the docs [1]:

```
In absence of an explicit layout, a memref is considered to have a
multi-dimensional identity affine map layout.
```

This patch makes sure that MemRefs with no strides (i.e. no explicit
layout) are treated as contiguous when checking whether a particular
vector is a contiguous slice of the given MemRef.

[1] https://mlir.llvm.org/docs/Dialects/Builtin/#layout

Follow-up for llvm#76428.
banach-space added a commit that referenced this pull request Jan 9, 2024
#76848)

As per the docs [1]:

```
In absence of an explicit layout, a memref is considered to have a
multi-dimensional identity affine map layout.
```

This patch makes sure that MemRefs with no strides (i.e. no explicit
layout) are treated as contiguous when checking whether a particular
vector is a contiguous slice of the given MemRef.

[1] https://mlir.llvm.org/docs/Dialects/Builtin/#layout

Follow-up for #76428.
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
llvm#76848)

As per the docs [1]:

```
In absence of an explicit layout, a memref is considered to have a
multi-dimensional identity affine map layout.
```

This patch makes sure that MemRefs with no strides (i.e. no explicit
layout) are treated as contiguous when checking whether a particular
vector is a contiguous slice of the given MemRef.

[1] https://mlir.llvm.org/docs/Dialects/Builtin/#layout

Follow-up for llvm#76428.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants