[Mlir-commits] [mlir] [MLIR][NVVM] Add binaryCallback (PR #170853)

Mehdi Amini llvmlistbot at llvm.org
Mon Dec 8 07:12:21 PST 2025


================
@@ -220,6 +220,38 @@ TEST_F(MLIRTargetLLVMNVVM,
   }
 }
 
+// Test NVVM serialization to Binary.
+TEST_F(MLIRTargetLLVMNVVM, SKIP_WITHOUT_NVPTX(CallbackForBinary)) {
+  if (!hasPtxas())
+    GTEST_SKIP() << "PTXAS compiler not found, skipping test.";
+
+  MLIRContext context(registry);
+
+  OwningOpRef<ModuleOp> module =
+      parseSourceString<ModuleOp>(moduleStr, &context);
+  ASSERT_TRUE(!!module);
+
+  // Create an NVVM target.
+  NVVM::NVVMTargetAttr target = NVVM::NVVMTargetAttr::get(&context);
+  std::string binaryResult;
+  auto binaryCallback = [&binaryResult](llvm::StringRef binaryTarget) {
+    binaryResult = binaryTarget.str();
+  };
+  // Serialize the module.
+  auto serializer = dyn_cast<gpu::TargetAttrInterface>(target);
+  ASSERT_TRUE(!!serializer);
+  gpu::TargetOptions options("", {}, "-v", "", gpu::CompilationTarget::Binary,
+                             {}, {}, {}, {}, {}, binaryCallback);
+  for (auto gpuModule : (*module).getBody()->getOps<gpu::GPUModuleOp>()) {
+    std::optional<SmallVector<char, 0>> object =
+        serializer.serializeToObject(gpuModule, options);
----------------
joker-eph wrote:

Expanding on my other comment: the returned object here should be the same bytes as what you get through the callback.

https://github.com/llvm/llvm-project/pull/170853


More information about the Mlir-commits mailing list