windowscmakeopenclgpgpuspir-v

Is there an OS-independent way to transpile OpenCL kernels into SPIR-V?


I've found a guide on Offline Compilation of OpenCL Kernels into SPIR-V Using Open Source Tooling for clang but I cannot find an official way to do this with other compilers.

Is there a way to transpile an OpenCL kernel into SPIR-V using CMake? If no, is there another universal way to build the same OpenCL-containing project except writing custom scripts and call clang on different operating systems (I'm especially interested in Linux and Windows)?

I saw that SPIR-V is designed for use by OpenCL 2.0+, but NVidia graphics cards support only OpenCL 1.2-. Will applications containing SPIR-V modules be working on NVidia graphics cards?


Solution

  • but I cannot find an official way to do this with other compilers.

    Because there isn't any official way. Most implementations don't even let you run their compiler in standalone/offline fashion. There is Clang, and IIRC Intel did have an offline OpenCL compiler; i'm not aware of any others.

    is there another universal way to build the same OpenCL-containing project except writing custom scripts and call clang on different operating systems

    Depends on what you mean by "building". The only way that works almost everywhere is to distribute the OpenCL sources with your program, and call clBuildProgram() at runtime. If that's not good for you, then you have two options, 1) obfuscate the CL sources, 2) distribute binaries. For 2), there is no official binary format that works everywhere. SPIR-V comes close, but its support is only mandatory since OpenCL 2.1.

    Will applications containing SPIR-V modules be working on NVidia graphics cards?

    No. You can get Nvidia-specific binaries using the "official way", by calling clGetProgramInfo() after clBuildProgram().