In online compilation of OpenCl, we have to do...
program = clCreateProgramWithSource(context, 1, (const char **)&source_str, (const size_t *)&source
Once the program has been created you can use clGetProgramInfo with CL_PROGRAM_BINARY_SIZES
and then CL_PROGRAM_BINARIES
, storing the resulting binary programs (one for each device of the context) into a buffer you supply. You can then save this binary data to disk for use in later runs.
Not all devices might support binaries, so you will need to check the CL_PROGRAM_BINARY_SIZES
result (it returns a zero size for that device if binaries are not supported).
To save time in the future (say in future runs of your application), you can use clCreateProgramWithBinary
with the returned binaries. However, you will only ever want to do this with exactly the same hardware. Even when the graphics driver changes for the same hardware, you might want to throw the binary away and rebuild since there is potential the OpenCL compiler in the new driver has bugfixes and/or performance improvements.