Creating and using kernel binaries

Anybody have any sample code for creating and saving binary compiled kernels that actually works? I tried using sample code I found in various places and so far no luck. I find it hard to believe that this doesn’t work so I must be doing something wrong.

When no binary is present my code uses clCreateProgramWithSource, clBuildProgram, and clCreateKernel to pull multiple kernels from the program. The binary code is then pulled from the created cl_program using clGetProgramBuildInfo with CL_PROGRAM_BINARY_SIZES and then CL_PROGRAM_BINARIES and writes it to a file. All works as expected with the kernels created via clCreateProgramWithSource.

If a binary file is present the code reads in the binary data and uses clCreateProgramWithBinary and clBuildProgram and clCreateKernel. For Nvidia opencl the call to clBuildProgram is failing with a segfault. For AMD opencl the calls to clCreateProgramWithBinary and clBuildProgram work fine however the call to clCreateKernel gives the error that it can’t find the kernel. When I look at the binary data there are no strings in it so I don’t see how it could possibly find the kernel in the binary. I tried a lot of different amd compiler options but nothing worked.

Thanks in advance,


Doing it just as you describe works fine for us on Windows. On Mac there were some issues so we always build from source. What platform are you on? Very sorry, but I can’t share source, just confirm that it does work on AMD, NVIDIA, and Intel.