2

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 :)

fodinabor
  • 451
  • 5
  • 15
  • Maybe uncompile with spirv-cross and recompile? Not sure if it supports Kernel SPIR-V though... – krOoze Nov 07 '19 at 22:28
  • Sounds awful, but I'll test it ;-) – fodinabor Nov 08 '19 at 12:35
  • 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 https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_execution_model_a_execution_model – FrickeFresh Nov 10 '19 at 15:20
  • 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 May 11 '20 at 23:11
  • 1
    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 May 12 '20 at 09:45
  • Perhaps you should make that an “answer”? Though maybe a little pointless for your own question. – Andrea May 17 '20 at 18:55

1 Answers1

-1

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.

mogu
  • 1,091
  • 6
  • 8
  • “clspv compiles to "Opencl-style SPIR-V"” — what? “Clspv is a prototype compiler for a subset of OpenCL C to Vulkan compute shaders” is the first thing it says on its GitHub page! – Andrea May 11 '20 at 22:57