Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clBuildProgram failed with error code -11 and without build log

Tags:

opencl

I have worked little bit in OpenCL now but recently "clBuildProgram" failed in one of my program. My code excerpt is below:

cl_program program;
program = clCreateProgramWithSource(context, 1, (const char**) &kernel_string, NULL, &err);
if(err != CL_SUCCESS)
{
cout<<"Unable to create Program Object. Error code = "<<err<<endl;
exit(1);
}
if(clBuildProgram(program, 0, NULL, NULL, NULL, NULL) != CL_SUCCESS)
{
cout<<"Program Build failed\n";
size_t length;
char buffer[2048];
clGetProgramBuildInfo(program, device_id[0], CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &length);
cout<<"--- Build log ---\n "<<buffer<<endl;
exit(1);
}

Normally earlier I got syntax or other errors inside kernel file here with the help of "clGetProgramBuildInfo()" function whenever "clBuildProgram" Failed but when this program runs, on console it only prints:

Program Build failed --- Build log ---

And when I tried to print the error code returned by "clBuildProgram"; it is "-11"...... What can be the problem with my kernel file that I dont get any build fail information ?

like image 544
Akhtar Ali Avatar asked Oct 21 '11 16:10

Akhtar Ali


3 Answers

You can learn the meaning of OpenCL error codes by searching in cl.h. In this case, -11 is just what you'd expect, CL_BUILD_PROGRAM_FAILURE. It's certainly curious that the build log is empty. Two questions:

1.) What is the return value from clGetProgramBuildInfo?

2.) What platform are you on? If you are using Apple's OpenCL implementation, you could try setting CL_LOG_ERRORS=stdout in your environment. For example, from Terminal:

$ CL_LOG_ERRORS=stdout ./myprog

It's also pretty easy to set this in Xcode (Edit Scheme -> Arguments -> Environment Variables).

like image 163
James Avatar answered Sep 30 '22 20:09

James


If you are using the C instead of C++:

err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL); 

////////////////Add the following lines to see the log file///////////

if (err != CL_SUCCESS) {
char *buff_erro;
cl_int errcode;
size_t build_log_len;
errcode = clGetProgramBuildInfo(program, devices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_len);
if (errcode) {
            printf("clGetProgramBuildInfo failed at line %d\n", __LINE__);
            exit(-1);
        }

    buff_erro = malloc(build_log_len);
    if (!buff_erro) {
        printf("malloc failed at line %d\n", __LINE__);
        exit(-2);
    }

    errcode = clGetProgramBuildInfo(program, devices[0], CL_PROGRAM_BUILD_LOG, build_log_len, buff_erro, NULL);
    if (errcode) {
        printf("clGetProgramBuildInfo failed at line %d\n", __LINE__);
        exit(-3);
    }

    fprintf(stderr,"Build log: \n%s\n", buff_erro); //Be careful with  the fprint
    free(buff_erro);
    fprintf(stderr,"clBuildProgram failed\n");
    exit(EXIT_FAILURE);
}
like image 20
Rein Avatar answered Sep 30 '22 19:09

Rein


I encountered the same problem with an empty log file. I was testing my ocl kernel on a different computer. It had 2 platforms instead of one. One Intel GPU and one AMD GPU. I only had AMD OCL SDK installed. Installing the Intel OCL SDK fixed the problem. Also selecting the AMD platform instead of the Intel GPU platform fixed it.

like image 24
Jonas V Avatar answered Sep 30 '22 18:09

Jonas V