Hi, I think I have discovered something really weired:
I’m running OpenCL 1.1 on OSX 10.7 Lion, and trying to use a pre-compiled kernel using the “clCreateProgramWithBinary” function.
According to the reference, (http://www.khronos.org/registry/cl/sdk/ … inary.html)
the 5th argument “binaries” should be an array of pointers to the contents of the binary, but it seems that the Apple’s implementation is different:
“binaries” is an array of the file paths of the pre-compiled binaries.
Actually, Apple’s sample code “Offline Compilation Using the OpenCL Compiler” is calling clCreateProgramWithBinary with file paths. Like this:
size_t len = strlen(file_path);
program = clCreateProgramWithBinary(context, 1, &device, &len, (const unsigned char**)&file_path, NULL, &err);
Any ideas what is going on?
The contents of a precompiled binary are implementation-dependent. Maybe Apple chose them to be paths to temporary files.
All that OpenCL requires is that whatever you obtain when you call clGetProgramInfo(…, CL_PROGRAM_BINARIES, …) can later be reloaded using clCreateProgramWithBinary(). Also, note that clCreateProgramWithBinary() may fail for any reason so your application must always have be ready to fall-back and recompile the program from source.
This is an extension which allows a developer to compile their CL source code into a bitcode file (using the openclc compiler, or automatically in Xcode), and then ship that with their app instead of the original source.
The standard usage of clCreateProgramWithBinary, where a device specific binary is passed instead of the path to a bitcode file, works too.