Reputation: 132202
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_devices
To 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_AMD
is 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?
Upvotes: 3
Views: 368
Reputation: 1229
As you assumed, you start with the usual clCompileProgram()
and clBuildProgram()
.
Next you can use clGetProgramInfo()
with CL_PROGRAM_BINARY_SIZES
to get the sizes for your buffer allocations, and a second time with CL_PROGRAM_BINARIES
to get the actual binary images of the program.
This image can then be used with clCreateProgramWithBinary()
instead of clCreateProgramWithSource()
.
Hope that helps.
Upvotes: 2