-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MLIR][Spirv] Don't lower tensors that can't be represented by an ArrayType #171002
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
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-mlir-spirv Author: Stefan Weigl-Bosker (sweiglbosker) ChangesI noticed this because of #159738, though it was only caught by his fuzzer because it wrapped to 0. Full diff: https://github.com/llvm/llvm-project/pull/171002.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index cb9b7f6ec2fd2..f07307fcd2f9d 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -502,6 +502,11 @@ static Type convertTensorType(const spirv::TargetEnv &targetEnv,
<< type << " illegal: cannot handle zero-element tensors\n");
return nullptr;
}
+ if (arrayElemCount > std::numeric_limits<unsigned>::max()) {
+ LLVM_DEBUG(llvm::dbgs()
+ << type << " illegal: cannot fit tensor into target type\n");
+ return nullptr;
+ }
Type arrayElemType = convertScalarType(targetEnv, options, scalarType);
if (!arrayElemType)
|
|
@llvm/pr-subscribers-mlir Author: Stefan Weigl-Bosker (sweiglbosker) ChangesI noticed this because of #159738, though it was only caught by his fuzzer because it wrapped to 0. Full diff: https://github.com/llvm/llvm-project/pull/171002.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index cb9b7f6ec2fd2..f07307fcd2f9d 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -502,6 +502,11 @@ static Type convertTensorType(const spirv::TargetEnv &targetEnv,
<< type << " illegal: cannot handle zero-element tensors\n");
return nullptr;
}
+ if (arrayElemCount > std::numeric_limits<unsigned>::max()) {
+ LLVM_DEBUG(llvm::dbgs()
+ << type << " illegal: cannot fit tensor into target type\n");
+ return nullptr;
+ }
Type arrayElemType = convertScalarType(targetEnv, options, scalarType);
if (!arrayElemType)
|
kuhar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this. Would it be possible to add a lit test?
39e3fc3 to
62e7846
Compare
Done! |
62e7846 to
1d0bf9a
Compare
| << type << " illegal: cannot handle zero-element tensors\n"); | ||
| return nullptr; | ||
| } | ||
| if (arrayElemCount > std::numeric_limits<unsigned>::max()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (arrayElemCount > std::numeric_limits<unsigned>::max()) { | |
| if (arrayElemCount > std::numeric_limits<uint32_t>::max()) { |
to make it platform-independent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is actually the accurate way to do things, as ArrayType.elementCount is an unsigned.
I noticed this because of #159738, though it was only caught by his fuzzer because it wrapped to 0.
Also, is there a reason for the usage of
unsignedfor sizes in spirv types? I believe most of the builtin types useint64_tfor sizes, so it may make sense to do the same for spirv.