Skip to content
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

[mlir][gpu] Fix crash in gpu-module-to-binary #75477

Merged
merged 1 commit into from
Dec 14, 2023
Merged

Conversation

fabianmcg
Copy link
Contributor

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.

This patch fixes the error in issue llvm#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.
@llvmbot
Copy link
Member

llvmbot commented Dec 14, 2023

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-gpu

Author: Fabian Mora (fabianmcg)

Changes

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

Copy link
Member

@grypp grypp left a comment

Choose a reason for hiding this comment

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

looks good thanks for fixing tihs

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.

3 participants