debugging - 错误代码(-11)::在OpenCL中出现错误“cl_build_program_failure”的所有可能原因是什么?

标签 debugging opencl gpu

我在Linux上使用ATI RV770图形卡,OpenCl 1.0和ati-stream-sdk-v2.3-lnx64。

运行包含以下两部分的内核代码以构建内核程序时,我得到了错误代码(-11),即cl_build_program_failure。这是否意味着内核程序已编译,如果未编译,则如何编译和调试?

const char* KernelPath = "abc_kernel.cl";   //kernel program is in separate file but in same directory of host code..


/ *从内核源******* /创建程序对象

char* sProgramSource = readKernelSource(KernelPath);
size_t sourceSize =  strlen(sProgramSource) ;
program = clCreateProgramWithSource(context, 1,(const char **) &sProgramSource,&sourceSize, &err);
checkStatus("error while creating program",err);


/ *构建(编译和链接)程序******* /

char* options = (char* )malloc(10*sizeof(char));
strcpy(options, "-g");
err = clBuildProgram(program, num_devices, devices_id, options, NULL, NULL);
checkStatus("Build Program Failed", err); //This line throwing the error....


读取内核程序的功能如下:

/ *读取程序源文件* /

char* readKernelSource(const char* kernelSourcePath){
 FILE    *fp = NULL;
 size_t  sourceLength;
 char    *sourceString ;
 fp = fopen( kernelSourcePath , "r");
 if(fp == 0)
 {
        printf("failed to open file");
        return NULL;
 }
 // get the length of the source code
 fseek(fp, 0, SEEK_END);
 sourceLength = ftell(fp);
 rewind(fp);
 // allocate a buffer for the source code string and read it in
 sourceString = (char *)malloc( sourceLength + 1);
 if( fread( sourceString, 1, sourceLength, fp) !=sourceLength )
 {
          printf("\n\t Error : Fail to read file ");
          return 0;
 }
 sourceString[sourceLength+1]='\0';
 fclose(fp);
 return sourceString;


} // readKernelSource的结尾

谁能告诉我如何解决它?

这是否意味着在运行时或其他原因是OpenCl编译错误?

//使用如下所示的clGetProgramBuildInfo()打印build_log信息,但是为什么不打印任何内容?

char * build_log;
size_t log_size;

// First call to know the proper size
        err = clGetProgramBuildInfo(program, devices_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
        build_log = (char* )malloc((log_size+1));

        // Second call to get the log
        err = clGetProgramBuildInfo(program, devices_id, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);
        build_log[log_size] = '\0';
        printf("--- Build log ---\n ");
        fprintf(stderr, "%s\n", build_log);
        free(build_log);

最佳答案

此错误通常是由内核代码中的语法错误引起的。您可以使用标志CL_PROGRAM_BUILD_LOG调用OpenCL函数clGetProgramBuildInfo来访问编译器生成的日志。该日志包含您在命令行上编译时可能习惯的输出(错误,警告等)。

例如,您可以在调用clBuildProgram之后添加类似于以下内容的内容:

if (err == CL_BUILD_PROGRAM_FAILURE) {
    // Determine the size of the log
    size_t log_size;
    clGetProgramBuildInfo(program, devices_id[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);

    // Allocate memory for the log
    char *log = (char *) malloc(log_size);

    // Get the log
    clGetProgramBuildInfo(program, devices_id[0], CL_PROGRAM_BUILD_LOG, log_size, log, NULL);

    // Print the log
    printf("%s\n", log);
}


您还可以在AMD APP SDK的SDKCommon.cpp中看到函数buildOpenCLProgram(),以获取真实示例。

关于debugging - 错误代码(-11)::在OpenCL中出现错误“cl_build_program_failure”的所有可能原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9464190/

相关文章:

ruby - 为什么只有当我使用 "undefined method ` 条件时,Ruby 才会提示 +' for nil:NilClass (NoMethodError)" 'if'

c++ - 有没有办法在 Mac 上为 OpenCL 启用双 vector ?

c++ - 带有 float 的自定义内核 GpuMat

windows - 使用 WinDBG 从调用堆栈中查找 URL

c++ - 通过 IE 控件禁用 IE 脚本调试

memory-management - 使用clCreateBuffer + CL_MEM_COPY_HOST_PTR创建缓冲区对象与clCreateBuffer + clEnqueueWriteBuffer创建缓冲区对象有什么区别?

ffmpeg色彩空间转换速度

cuda - 在 CUDA 中解除纹理绑定(bind)之前我应该​​同步吗?

objective-c - 如何在不引用特定类的情况下解释崩溃日志

OpenCL 全局内存获取