我现在在OpenCL中做了一点点工作但是最近“clBuildProgram”在我的一个程序中失败了。我的代码摘录如下:
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);
}
通常早些时候,在“clBuildProgram”失败的情况下,在“clBuildProgram”函数的帮助下,我在内核文件中得到了语法或其他错误,但是当这个程序运行时,在控制台上它只打印:
程序构建失败 ---建立日志---
当我尝试打印“clBuildProgram”返回的错误代码时;是“-11”...... 我的内核文件有什么问题,我没有得到任何构建失败信息?
答案 0 :(得分:10)
您可以通过在cl.h中搜索来了解OpenCL错误代码的含义。在这种情况下,-11正是您所期望的,CL_BUILD_PROGRAM_FAILURE。毫无疑问,构建日志是空的。两个问题:
1。)clGetProgramBuildInfo的返回值是什么?
2.你在什么平台上?如果您使用的是Apple的OpenCL实现,则可以尝试在您的环境中设置CL_LOG_ERRORS = stdout。例如,来自终端:
$ CL_LOG_ERRORS = stdout ./myprog
在Xcode(编辑方案 - &gt; Arguments - &gt;环境变量)中设置它也很容易。
答案 1 :(得分:4)
如果您使用的是C而不是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);
}
答案 2 :(得分:1)
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.
答案 3 :(得分:0)
当OpenCL内核源代码缺少_kernel
属性标记时,我已经在OSX 10.14.6上看到了这种情况。如果_kernel
标记和返回类型都丢失,则似乎会使系统OpenCL编译器守护进程崩溃,然后需要几秒钟重新启动,新内核才能再次编译。