Get binary of kernel - clGetProgramInfo


thank anyone who can help me.

I need that my code run without be compiled in execution time.

When i run the host code, in this line a error of access in memory occurs.

errcode = clGetProgramInfo(program, CL_PROGRAM_BINARIES, binary_sizes[0] * sizeof(size_t), teste_aloprado,&quantidadecopiadaparamvalue);

The all code of that i tried follows:

errcode = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES,num_dispositivos * sizeof(size_t), binary_sizes, &quantidadecopiadaparamvalue);
cout << "
Foram copiados: " << quantidadecopiadaparamvalue << "

if( errcode == CL_SUCCESS )
	cout &lt;&lt; "

A quantidade de Bytes é: " << binary_sizes[0];
cout << "
Não retornou a quantidade de bytes.";

char **binary = (char **) malloc(num_dispositivos * sizeof(char*));
for(int i = 0; i &lt; num_dispositivos; i++ )
	binary[i] = (char *) malloc(binary_sizes[i] * sizeof(char));
size_t *teste_aloprado = (size_t *) malloc(binary_sizes[0] * sizeof(size_t));
errcode = clGetProgramInfo(program, CL_PROGRAM_BINARIES, binary_sizes[0] * sizeof(size_t), teste_aloprado,&quantidadecopiadaparamvalue);

No one know how to help me?

It would help if you posted the actual error code returned, but it looks like you’re passing the wrong arguments. You should be passing binary rather than teste_aloprado, and the size should I think be num_dispositivos * sizeof(unsigned char *).

Technically each time you’ve used char it should be unsigned char, but in reality I don’t think it’ll make much difference.

I’ve written a tool that does this extraction, which you can see at … nlineclc.c. It only handles one device, but it might still be useful as sample code.

Very Thanks,

Works fine now


I succeeded get binary and save in a file.

But, in clgetprogramwithbinary and in
sivia = clCreateKernel(program,“sivia”,&erro_create_kernel); ,
no error occurs, but when i call to run kernel the error below occurs:

Kernel Sivia deu zebra! -48


Identificacao do erro: CL_INVALID_KERNEL - -48
Error: Runtime failed to load kernels from OCL binary!

Very Thanks,


I realized that i made a mistake.

At first it seems that i caught the binary and put in a file, and after load in a buffer.

When i loaded and made the program object with the binary with clCreateProgramWithBinary no error occurs, but in clCreateKernel(program,“sivia”,&erro_create_kernel);


Very Thanks for help

bmerry or other person that can help, what’s happening with code?