Most OpenCL Tutorials give a nice introduction to OpenCL, yet I have not found information on the question of interoperability of the compilation targets. It seems that I have to compile OpenCL code for the target GPU. Now when making a binary distribution of an application using OpenCL, does one have to make several builds for the vendor-platforms?
3
OpenCL works similarly to other GPU libraries like OpenGL. What you ship is an intermediate representation. The GPU’s driver does final compilation for execution on the specific device at run time. Here is an intro to OpenCL slide presentation from Khronos.
Edit: With OpenCL 2 the compilation model changed some to be much more flexible. Now there is an LLVM backend that targets the new SPIR-V intermediate representation, so any language compiler that targets LLVM should be capable of being used to target OpenCL. Other than that the model is pretty much the same but gains a step, source compiles to LLVM IR, LLVM IR compiles to SPIR-V, driver handles final compilation and execution.
3
No, you do not need to have a per-target-platform compiled binary: OpenCL’s API supports compiling kernel binaries for several different devices, and obtaining the compiled code with clGetProgramInfo()
. You can do this for several target platforms, place all your binaries in your distribution, and ship that.
2