Skip to content

Commit 419c45a

Browse files
authored
[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.
1 parent 15c06bc commit 419c45a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ LogicalResult moduleSerializer(GPUModuleOp op,
101101
const TargetOptions &targetOptions) {
102102
OpBuilder builder(op->getContext());
103103
SmallVector<Attribute> objects;
104+
// Fail if there are no target attributes
105+
if (!op.getTargetsAttr())
106+
return op.emitError("the module has no target attributes");
104107
// Serialize all targets.
105108
for (auto targetAttr : op.getTargetsAttr()) {
106109
assert(targetAttr && "Target attribute cannot be null.");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: mlir-opt %s --gpu-module-to-binary --verify-diagnostics
2+
3+
module attributes {gpu.container_module} {
4+
// expected-error @below {{the module has no target attributes}}
5+
gpu.module @kernel_module1 {
6+
llvm.func @kernel(%arg0: i32, %arg1: !llvm.ptr,
7+
%arg2: !llvm.ptr, %arg3: i64, %arg4: i64,
8+
%arg5: i64) attributes {gpu.kernel} {
9+
llvm.return
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)