[Mlir-commits] [mlir] 419c45a - [mlir][gpu] Fix crash in `gpu-module-to-binary` (#75477)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Dec 14 11:03:14 PST 2023


Author: Fabian Mora
Date: 2023-12-14T14:03:10-05:00
New Revision: 419c45a3252489d0ebac4535fe5a4ed9a6af6bbd

URL: https://github.com/llvm/llvm-project/commit/419c45a3252489d0ebac4535fe5a4ed9a6af6bbd
DIFF: https://github.com/llvm/llvm-project/commit/419c45a3252489d0ebac4535fe5a4ed9a6af6bbd.diff

LOG: [mlir][gpu] Fix crash in `gpu-module-to-binary` (#75477)

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.

Added: 
    mlir/test/Dialect/GPU/module-to-binary-invalid.mlir

Modified: 
    mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp

Removed: 
    


################################################################################
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
+    }
+  }
+}


        


More information about the Mlir-commits mailing list