I want to compile an OpenCL kernel for a certain AMD GPU - which is not available on my machine -, so that later I'm able to just load and run it when that GPU is present.
I've read this question here on SO:
Offline compilation for AMD and NVIDIA OpenCL Kernels without cards installed
And the answer suggesting I create the OpenCL context with CL_CONTEXT_OFFLINE_DEVICES_AMD. Ok, I can do that. But what then? In AMD's OpenCL Programming User Guide, it says:
A.8.6
cl_amd_offline_devicesTo generate binary images offline, it is necessary to access the compiler for every device that the runtime supports, even if the device is currently not installed on the system. When, during context creation,CL_CONTEXT_OFFLINE_DEVICES_AMDis passed in the context properties, all supported devices, whether online or offline, are reported and can be used to create OpenCL binary images.
ok, but how exactly? I'm assuming I'd need to call clCompileProgram() or clBuildProgram(), right? How do I set the device list for it to the device I like?
As you assumed, you start with the usual
clCompileProgram()andclBuildProgram().Next you can use
clGetProgramInfo()withCL_PROGRAM_BINARY_SIZESto get the sizes for your buffer allocations, and a second time withCL_PROGRAM_BINARIESto get the actual binary images of the program.This image can then be used with
clCreateProgramWithBinary()instead ofclCreateProgramWithSource().Hope that helps.