[Mlir-commits] [mlir] [mlir][gpu] Fix crash in `gpu-module-to-binary` (PR #75477)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Dec 14 06:29:51 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-gpu
Author: Fabian Mora (fabianmcg)
<details>
<summary>Changes</summary>
This patch fixes the error in issue #<!-- -->75434. The crash was being caused by not checking for a lack of target attributes in a GPU module. It's now considered an error to invoke the pass with a GPU module with no target attributes.
---
Full diff: https://github.com/llvm/llvm-project/pull/75477.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp (+3)
- (added) mlir/test/Dialect/GPU/module-to-binary-invalid.mlir (+12)
``````````diff
diff --git a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
index e81992ca8e9a33..70d36297e103f3 100644
--- a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
@@ -101,6 +101,9 @@ LogicalResult moduleSerializer(GPUModuleOp op,
const TargetOptions &targetOptions) {
OpBuilder builder(op->getContext());
SmallVector<Attribute> objects;
+ // Fail if there are no target attributes
+ if (!op.getTargetsAttr())
+ return op.emitError("the module has no target attributes");
// Serialize all targets.
for (auto targetAttr : op.getTargetsAttr()) {
assert(targetAttr && "Target attribute cannot be null.");
diff --git a/mlir/test/Dialect/GPU/module-to-binary-invalid.mlir b/mlir/test/Dialect/GPU/module-to-binary-invalid.mlir
new file mode 100644
index 00000000000000..7043c4fe49e1a6
--- /dev/null
+++ b/mlir/test/Dialect/GPU/module-to-binary-invalid.mlir
@@ -0,0 +1,12 @@
+// RUN: mlir-opt %s --gpu-module-to-binary --verify-diagnostics
+
+module attributes {gpu.container_module} {
+ // expected-error @below {{the module has no target attributes}}
+ gpu.module @kernel_module1 {
+ llvm.func @kernel(%arg0: i32, %arg1: !llvm.ptr,
+ %arg2: !llvm.ptr, %arg3: i64, %arg4: i64,
+ %arg5: i64) attributes {gpu.kernel} {
+ llvm.return
+ }
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/75477
More information about the Mlir-commits
mailing list