[Mlir-commits] [mlir] [mlir][NVVM] Diagnose non-NVVM target ops before serialization (PR #210000)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 16 00:49:49 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-gpu
Author: shubhamnarlawar
<details>
<summary>Changes</summary>
When a gpu.module targeted with #nvvm.target contains operations from other GPU target dialects (e.g. rocdl, xevm), those ops are translated to their LLVM intrinsics (e.g. llvm.amdgcn.*)
Add a walk at the top of NVVMTargetAttrImpl::serializeToObject that rejects operations from foreign GPU target dialects with a clear diagnostic before any LLVM IR is produced
This PR fixes #<!-- -->205274
---
Full diff: https://github.com/llvm/llvm-project/pull/210000.diff
2 Files Affected:
- (modified) mlir/lib/Target/LLVM/NVVM/Target.cpp (+14)
- (modified) mlir/test/Dialect/GPU/module-to-binary-invalid.mlir (+27-1)
``````````diff
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index 2d197a162a7af..41351dc766d1c 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -760,6 +760,20 @@ NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
module->emitError("Module must be a GPU module.");
return std::nullopt;
}
+
+ // Reject operations from other GPU target dialects.
+ WalkResult foreignOp = module->walk([&](Operation *op) {
+ StringRef dialect = op->getDialect()->getNamespace();
+ if (dialect == "rocdl" || dialect == "xevm") {
+ op->emitError() << "'" << op->getName() << "' from '" << dialect
+ << "' dialect is not compatible with the NVVM target";
+ return WalkResult::interrupt();
+ }
+ return WalkResult::advance();
+ });
+ if (foreignOp.wasInterrupted())
+ return std::nullopt;
+
NVPTXSerializer serializer(*module, cast<NVVMTargetAttr>(attribute), options);
serializer.init();
std::optional<SmallVector<char, 0>> result = serializer.run();
diff --git a/mlir/test/Dialect/GPU/module-to-binary-invalid.mlir b/mlir/test/Dialect/GPU/module-to-binary-invalid.mlir
index 7043c4fe49e1a..e7eb75f11388b 100644
--- a/mlir/test/Dialect/GPU/module-to-binary-invalid.mlir
+++ b/mlir/test/Dialect/GPU/module-to-binary-invalid.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s --gpu-module-to-binary --verify-diagnostics
+// RUN: mlir-opt %s --gpu-module-to-binary --verify-diagnostics --split-input-file
module attributes {gpu.container_module} {
// expected-error @below {{the module has no target attributes}}
@@ -10,3 +10,29 @@ module attributes {gpu.container_module} {
}
}
}
+
+// -----
+
+module attributes {gpu.container_module} {
+ // expected-error @below {{An error happened while serializing the module}}
+ gpu.module @kernel_module_nvvm_rocdl_op [#nvvm.target] {
+ llvm.func @kernel() attributes {gpu.kernel} {
+ // expected-error @below {{'rocdl.workitem.id.x' from 'rocdl' dialect is not compatible with the NVVM target}}
+ %tx = rocdl.workitem.id.x : i32
+ llvm.return
+ }
+ }
+}
+
+// -----
+
+module attributes {gpu.container_module} {
+ // expected-error @below {{An error happened while serializing the module}}
+ gpu.module @kernel_module_nvvm_rocdl_barrier [#nvvm.target] {
+ llvm.func @kernel() attributes {gpu.kernel} {
+ // expected-error @below {{'rocdl.barrier' from 'rocdl' dialect is not compatible with the NVVM target}}
+ rocdl.barrier
+ llvm.return
+ }
+ }
+}
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/210000
More information about the Mlir-commits
mailing list