[Mlir-commits] [mlir] [mlir][spirv] Do SPIR-V serialization in -test-vulkan-runner-pipeline (PR #121494)

Jakub Kuderski llvmlistbot at llvm.org
Thu Jan 2 09:49:45 PST 2025


================
@@ -135,21 +133,38 @@ LogicalResult ConvertGpuLaunchFuncToVulkanLaunchFunc::declareVulkanLaunchFunc(
   return success();
 }
 
-LogicalResult ConvertGpuLaunchFuncToVulkanLaunchFunc::createBinaryShader(
+LogicalResult ConvertGpuLaunchFuncToVulkanLaunchFunc::getBinaryShader(
     ModuleOp module, std::vector<char> &binaryShader) {
   bool done = false;
   SmallVector<uint32_t, 0> binary;
-  for (auto spirvModule : module.getOps<spirv::ModuleOp>()) {
+  gpu::BinaryOp *binaryToErase;
+  for (auto gpuBinary : module.getOps<gpu::BinaryOp>()) {
     if (done)
-      return spirvModule.emitError("should only contain one 'spirv.module' op");
+      return gpuBinary.emitError("should only contain one 'gpu.binary' op");
     done = true;
 
-    if (failed(spirv::serialize(spirvModule, binary)))
-      return failure();
+    ArrayRef<Attribute> objects = gpuBinary.getObjectsAttr().getValue();
+    if (objects.size() != 1)
+      return gpuBinary.emitError("should only contain a single object");
+
+    auto object = cast<gpu::ObjectAttr>(objects[0]);
+
+    if (!isa<spirv::TargetEnvAttr>(object.getTarget()))
+      return gpuBinary.emitError(
+          "should contain an object with a SPIR-V target environment");
+
+    StringAttr objectStrAttr = object.getObject();
+    StringRef objectStr = objectStrAttr.getValue();
+    binaryShader.insert(binaryShader.end(), objectStr.bytes_begin(),
----------------
kuhar wrote:

Yes, the attribute storage should survive until the context is destroyed

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


More information about the Mlir-commits mailing list