为什么我程序的clBuildProgram()永远都build失败啊?

芒果树上的长颈鹿 2014-12-24 04:59:31
前面都已正确输出,到build程序的时候就失败。
const char options[] = "-cl-std=CL1.1";
errNum = clBuildProgram(program,1,deviceIds,options,NULL,NULL);
if(errNum == CL_SUCCESS)
{
cout<<"The program Build success."<<endl;
}
cout<<errNum<<endl;
返回错误码-11;
求教大神,这是什么原因啊。输出错误日志也都是铪乱码。
内核改了好几次了。
...全文
4496 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wsqcwg 2015-04-10
  • 打赏
  • 举报
回复
楼主问题解决了吗?我也是有这个问题 用char数组不行 用string就可以,不知道为什么
  • 打赏
  • 举报
回复
我好像发现了什么。。。那个clBuildProgram第二个参数设置为0是什么意思啊。。。
  • 打赏
  • 举报
回复
int main() { //error Number. cl_int errNum; //Get Platform. cl_uint numPlatforms; cl_platform_id *platformIds; errNum = clGetPlatformIDs(0,NULL,&numPlatforms); platformIds = (cl_platform_id *)alloca(sizeof(cl_platform_id)*numPlatforms); errNum = clGetPlatformIDs(numPlatforms,platformIds,NULL); //Get the Devices list. cl_uint numDevices; cl_device_id *deviceIds; errNum = clGetDeviceIDs(*platformIds,CL_DEVICE_TYPE_ALL,0,NULL,&numDevices); deviceIds = (cl_device_id *)alloca(sizeof(cl_device_id)*numDevices); errNum = clGetDeviceIDs(*platformIds,CL_DEVICE_TYPE_ALL,numDevices,deviceIds,NULL); cout<<errNum<<endl; //Create a Context. cl_context context; cl_context_properties properties [] = { CL_CONTEXT_PLATFORM,(cl_context_properties)platformIds[0],0 }; cl_int contextErr;//Context error number. context = clCreateContext(properties,numDevices,deviceIds,NULL,NULL,&contextErr); cout<<"The Error Number of Context is :"<<contextErr<<endl; fstream fileOpen("KernelFile.cl"); string programString(istreambuf_iterator<char>(fileOpen),(istreambuf_iterator<char>())); cout<<programString<<endl; const char *programCodeSource = programString.c_str(); cl_program program; cl_int programErr; program = clCreateProgramWithSource(context,1,&programCodeSource,NULL,&programErr); cout<<programErr<<endl; if(program != NULL) { cout<<"The program is created success."<<endl; } cl_int BuildProgramErrNum ; errNum = clBuildProgram(program,1,NULL,NULL,NULL,&BuildProgramErrNum); cout<<BuildProgramErrNum<<endl; char *buildLog; size_t buildLogSize; clGetProgramBuildInfo(program,*deviceIds,CL_PROGRAM_BUILD_LOG,0,NULL,&buildLogSize); buildLog = (char *)alloca(sizeof(char)*buildLogSize); clGetProgramBuildInfo(program,*deviceIds,CL_PROGRAM_BUILD_LOG,buildLogSize,buildLog,NULL); cout<<buildLog<<endl; system("pause"); return 0; }
引用 6 楼 lcwyylcwyy 的回复:
我觉得先确定是不是平台设备和context的问题,再确定是否能编译,最后看内核是否正确。
就这么多代码,跪谢大神了 构建程序的错误码为空。
zenny_chen 2014-12-27
  • 打赏
  • 举报
回复
引用 8 楼 moonhyw231 的回复:
我好像发现了什么。。。那个clBuildProgram第二个参数设置为0是什么意思啊。。。
请参照我2楼的clBuildProgram写法~
  • 打赏
  • 举报
回复
引用 2 楼 zenny_chen 的回复:
-11表示——CL_BUILD_PROGRAM_FAILURE 说明你的OpenCL kernel程序构建失败~你可以用以下方式把错误日志打印出来:

	ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
    if (ret != CL_SUCCESS)
    {
        size_t len;
        char buffer[8 * 1024];
        
        printf("Error: Failed to build program executable!\n");
        clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
        printf("%s\n", buffer);
        goto FINISH;
    }
打印出的日志是铪乱码。。。怎么办啊。。大神。。。
lcwyylcwyy 2014-12-25
  • 打赏
  • 举报
回复
我觉得先确定是不是平台设备和context的问题,再确定是否能编译,最后看内核是否正确。
  • 打赏
  • 举报
回复
引用 1 楼 lcwyylcwyy 的回复:
用CodeXL中的编译工具查一下,看看kernel中哪有问题。还有一种最笨的办法,先找个先能编译的,再把每个函数逐个复制进去编译看看,挂在那个里了,再逐行检查。
把内核代码清空了也还是不行,这是为什么啊?
清风水岸 2014-12-25
  • 打赏
  • 举报
回复
一楼应该是可行的办法,或者找一个可以编译的替换掉看下。
zenny_chen 2014-12-24
  • 打赏
  • 举报
回复
-11表示——CL_BUILD_PROGRAM_FAILURE 说明你的OpenCL kernel程序构建失败~你可以用以下方式把错误日志打印出来:

	ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL);
    if (ret != CL_SUCCESS)
    {
        size_t len;
        char buffer[8 * 1024];
        
        printf("Error: Failed to build program executable!\n");
        clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
        printf("%s\n", buffer);
        goto FINISH;
    }
lcwyylcwyy 2014-12-24
  • 打赏
  • 举报
回复
用CodeXL中的编译工具查一下,看看kernel中哪有问题。还有一种最笨的办法,先找个先能编译的,再把每个函数逐个复制进去编译看看,挂在那个里了,再逐行检查。

602

社区成员

发帖
与我相关
我的任务
社区描述
异构开发技术
社区管理员
  • OpenCL和异构编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧