2
votes

Is it possible to translate OpenCL-style SPIR-V to Vulkan-style SPIR-V?
I know that it is possible to use clspv to compile OpenCL C to Vulkan-style SPIR-V, but I haven't seen any indication that it also supports ingesting OpenCL-style SPIR-V.

Thank you for any suggestions if you know how to achieve this :)

1
Maybe uncompile with spirv-cross and recompile? Not sure if it supports Kernel SPIR-V though... - krOoze
Sounds awful, but I'll test it ;-) - fodinabor
no idea if it will work, but try SPIRV-Cross and see if can bring it out to GLSL and then just recompile it with glslang to SPIR-V Also don't say "Vulkan Style" as the correct term is "Execution Model" for better search results khronos.org/registry/spir-v/specs/unified1/… - FrickeFresh
clspv is based on clang, so I wonder if you can use the Khronos SPIR-V LLVM translator to convert CL SPIR-V to SPIR (LLVM IR) and then pass the right clang command-line flags to clspv so it ingests the SPIR and does its thing? - Andrea
Yes, you can use SPIR-V LLVM translator to convert the CL SPIR-V to LLVM IR, that can be ingested by clspv using the -x=ir cli option. That will probably work for CL SPIR-V generated from OpenCL C and OpenCL C++ as those are supported by clspv as source languages natively. What does not work for example is ingesting SPIR-V or IR from Intel's SYCL device compiler, although it still is valid OpenCL SPIR-V. So it's not a solution for every usecase, yet. - fodinabor

1 Answers

-1
votes

I know that it is possible to use clspv to compile OpenCL C to Vulkan-style SPIR-V, but I haven't seen any indication that it also supports ingesting OpenCL-style SPIR-V.

clspv compiles to "Opencl-style SPIR-V". IOW, it uses OpenCL execution model and also OpenCL memory model. The answer to your question is no (in general). The problem is that e.g. GLSL uses logical memory model, which means pointers are abstract, so you can't have pointers to pointers. While OpenCL allows this, because it uses physical memory model. Plus there are other things in OpenCL which cannot be expressed in GLSL. You could try to write some translator, and it might work for some very simple code, but that's about it.