Offline Kernel Compiling in Ubuntu?


I am quite a noob to OpenCL, and am trying to grasp some ideas of it with guide book examples.
And I am currently using Ubuntu 12.04 with Intel / NVIDIA C2075,
of which both OpenCL SDKs are installed.

I know that there are two ways of compiling kernels (on/offline)
But I couldn’t figure out how I can compile my kernel and get binary file before compiling the whole thing.

The book says there’s a software named [Intel OpenCL offline Compiler] but what about Ubuntu??

My kernel code is very simple :

__kernel void vecAdd(__global float * a)
	int gid = get_global_id(0);
	a[gid] += a[gid];


gcc -I/usr/local/cuda-5.0/include -o kernel.clbin -lOpenCL

didn’t work that much. I got

/usr/bin/ file format not recognized; treating as linker script
/usr/bin/ syntax error
collect2: ld returned 1 exit status

I appreciate your reply!

The typical technique is to compile your program from source using clBuildProgram, then use clGetProgramInfo with the CL_PROGRAM_BINARY_SIZES and then CL_PROGRAM_BINARIES to fetch the binaries, and save them to disk. In future runs, use clCreateProgramWithBinary with the binary file.

Note: This will only work if the driver and GPU hasn’t changed. You won’t be able to ship this binary and have it run on any hardware. That capability is the promise of the SPIR feature announced with OpenCL 1.2 but not widely shipping yet.

You should have a look at

they have written a framework that should suite you. But remember that you will not be able to deliver binaries to other pc’s because the binaries are (mostly) fo your system only (depending on driver + hardware)

sadly not really,

the binaries are profided by the vendors. so its very hard to get them running on different platforms. Have a look at cuda cubin to see some of the problems.

there has been some ideas in the .ir format of khronos. but i couldnt get that one running on nvidia or amd. even intel wouldnt accept it. And i dreated it with the intel offline compiler -.-