简体   繁体   中英

build opencl kernel failure

When I use clBuildProgram in my OpenCl code it fails with the error code -11 without any log information.

Here is what my code looks like:

  ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);

  if (ret != CL_SUCCESS)
    {
        size_t len;
        char buffer[2048];
    cl_build_status bldstatus;
    printf("\nError %d: Failed to build program executable [ %s ]\n",ret,get_error_string(ret));
        ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_STATUS, sizeof(bldstatus), (void *)&bldstatus, &len);
        printf("Build Status %d: %s\n",ret,get_error_string(ret));
    printf("INFO: %s\n", get_error_string(bldstatus));
        ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_OPTIONS, sizeof(buffer), buffer, &len);
        printf("Build Options %d: %s\n",ret,get_error_string(ret));
    printf("INFO: %s\n", buffer);   
        ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);    
    printf("Build Log %d: %s\n",ret,get_error_string(ret));
    printf("%s\n", buffer);
    (void)infoinfo(platform_id,device_id);
    exit(1);
    }

Here is what the output looks like:

Error -11: Failed to build program executable [ CL_BUILD_PROGRAM_FAILURE ]
Build Status 0: CL_SUCCESS
INFO: CL_DEVICE_NOT_AVAILABLE
Build Options 0: CL_SUCCESS
INFO: 
Build Log -30: CL_INVALID_VALUE


CL_PLATFORM_NAME : NVIDIA CUDA
CL_PLATFORM_VERSION : OpenCL 1.1 CUDA 4.2.1
Device name : Tesla K20m
Driver version : 319.32
Global Memory (MB) : 4799
Global Memory Cache (KB) : 208
Local Memory (KB) : 48
Max clock (MHz) : 705
Max Work Group Size : 1024
Number of parallel compute cores : 13
Is the device available : yes

So, just by chance can you guys see any mistake or something weird in the lines above ?

Thank you,

Éric.

It looks like you might be using clGetProgramBuildInfo() wrong. The first time it is called, it should should be telling the size of the buffer it needs on the host:

clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, NULL, NULL, &len);

then on the host allocate the memory:

char *log = new char[len] //or whatever you use

then recall clGetProgramBuildInfo():

clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, len, log, null);

I've modified the code and increased the buffer size :

  ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);

  if (ret != CL_SUCCESS)
    {
        size_t len;
        char buffer[204800];
    cl_build_status bldstatus;
    printf("\nError %d: Failed to build program executable [ %s ]\n",ret,get_error_string(ret));
        ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_STATUS, sizeof(bldstatus), (void *)&bldstatus, &len);
        if (ret != CL_SUCCESS)
          {
        printf("Build Status error %d: %s\n",ret,get_error_string(ret));
        exit(1);
      }     
    if (bldstatus == CL_BUILD_SUCCESS) printf("Build Status: CL_BUILD_SUCCESS\n");
    if (bldstatus == CL_BUILD_NONE) printf("Build Status: CL_BUILD_NONE\n"); 
    if (bldstatus == CL_BUILD_ERROR) printf("Build Status: CL_BUILD_ERROR\n");
    if (bldstatus == CL_BUILD_IN_PROGRESS) printf("Build Status: CL_BUILD_IN_PROGRESS\n");  
        ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_OPTIONS, sizeof(buffer), buffer, &len);
        if (ret != CL_SUCCESS)
          {
        printf("Build Options error %d: %s\n",ret,get_error_string(ret));
        exit(1);
      }        
    printf("Build Options: %s\n", buffer);  
        ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);    
        if (ret != CL_SUCCESS)
          {
        printf("Build Log error %d: %s\n",ret,get_error_string(ret));
        exit(1);
      }     
    printf("Build Log:\n%s\n", buffer);
    exit(1);
    }

I now get this:

Error -11: Failed to build program executable [ CL_BUILD_PROGRAM_FAILURE ]
Build Status: CL_BUILD_ERROR
Build Options:
Build Log:
:4:85: error: must specify ....

So, it works.

Thank you for your help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM