PDA

View Full Version : clBuildProgram() function error...!!



phoebe0105
05-12-2010, 09:31 AM
I solved another problem.... and I wrote a new opencl kernel source.
The new kernel source is hextile code in opencl. I want to control the hextile encoding to the openCL(GPU).
I'm changed the source code to use opencl.
When it is builded, the error is occured.

I seek this error. It is "CL_INVALID_BINARY" error.
CL_INVALID_BINARY means if program is created with clCreateWithProgramBinary and devices listed in device_list do not have a valid program binary loaded.
But I didn't call the clCreateWithProgramBinary() function. I called clCreateProgramWithSource() function.

why is this occured the problem?

david.garcia
05-12-2010, 02:50 PM
What OpenCL implementation are you using? AMD/NVidia/Apple?

Did you remember to call clBuildProgram() after you called clCreateProgramWithSource()?

phoebe0105
05-12-2010, 04:20 PM
What OpenCL implementation are you using? AMD/NVidia/Apple?

Did you remember to call clBuildProgram() after you called clCreateProgramWithSource()?


First I called clCreateProgramWithSource() and then I called clBuildProgram() function.

Also I am using NVidia implementation.

david.garcia
05-13-2010, 07:00 AM
Did you check if clBuildProgram returned some kind of error? Try something like this:



cl_build_status build_status;
cl_int errcode = clBuildProgram(program, num_devices, devices, options, NULL, NULL);

if(errcode != CL_SUCCESS && errcode != CL_BUILD_PROGRAM_FAILURE)
{
panic();
}

for(i = 0; i < num_devices; ++i)
{
do
{
// Query if compilation was successful
errcode = clGetProgramBuildInfo(program, device[i], CL_PROGRAM_BUILD_STATUS,
sizeof(build_status), &build_status, NULL);
if(errcode) panic();

if(build_status == CL_BUILD_ERROR)
{
// Compilation failed. Print the build log
cl_char *build_log = NULL;
size_t build_log_len = 0;

errcode = clGetProgramBuildInfo(state->program, env->device[i], CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_len);
if(errcode) panic();

build_log = malloc(build_log_len + 1);
if(!build_log)
panic();

errcode = clGetProgramBuildInfo(program, device[i], CL_PROGRAM_BUILD_LOG, build_log_len, build_log, NULL);
if(errcode)
{
free(build_log);
panic();
}

printf("Program build failed. Build log follows:\n%s", build_log);

free(build_log);
}
}
while(build_status == CL_BUILD_IN_PROGRESS);
}


Note for OpenCL experts: I'm well aware that the code above is far from ideal :)