Kernel pre-compilation

Hi all,

I’m a bit confused about all what I read on the program pre-compilation.
Everytime, there is just a part of the code but almost never all the example code.
I’ve seen 3 examples, maybe not complete.

Version 1
a. Use clCreateProgramWithSource and clBuildProgram to compile a program for which the sources are contained into a char*.
b. Use clGetProgramInfo with the option CL_PROGRAM_BINARY_SIZES to generate a string (char*) which contains the program compiled (binary).
c. Keep the string as a variable.
d. Later on, create and compile a new program from the binary (variable in c.) using clCreateProgramWithBinary and clBuildProgram.

Version 2
a. Use clCreateProgramWithSource and clBuildProgram to compile a program for which the sources are contained into a char*.
b. Use clGetProgramInfo with the option CL_PROGRAM_BINARY_SIZES to generate a string (char*) which contains the program compiled (binary).
c. Write the string in an output file.
d. Later on, read the previously generated file and store it into a char*.
e. Create and compile a new program from the binary (char*) using clCreateProgramWithBinary and clBuildProgram.

Version 3
a. Write the kernel into a .cl file.
b. Use XCode to automatically compile the .cl file into a binary file.
c. Later on, create and compile a new program from the binary file using clCreateProgramWithBinary and clBuildProgram.

For the version 3, I guess what I miss is that the compile program is simply read from the binary file and stored into a char *, as for the version 2.

Except their obvious differences, is there any better or worse solution?
Are the versions 1 and 2 similar? It seems that yes and I don’t understand why we should use an external file. I guess that the openCL programs could be compiled the first time the program (main program) is used, and then are never compiled again. But I can’t be sure.

Thanks for your reactions on the subject.

Regards,

Vincent

With version 2 of the code (storing the program binary into a file) the application only needs to compile the sources once and after that the application can always use the program binary that was saved into the file. That can save a lot of time and it’s the right way to go.

It confirms what I thought.
I my case, the OpenCL program compilation takes way less than 1 second.
I can compile my OpenCL program at the beginning of the main program and store compiled OpenCL compiled programs in char * variables.
I don’t need then to read from the disk, which should be longer in my case.

Many thanks,

Vincent Garcia