getting cl_build_program_failure error

北慕城南 提交于 2020-01-17 12:25:26

问题


I am currently working on a project about OpenCL and ran into some troubles when I was trying to build the program. So I have the following code:

    //Read source file
    std::ifstream sourceFile("calculation_kernel.cl");
    std::string sourceCode(std::istreambuf_iterator<char>(sourceFile), (std::istreambuf_iterator<char>()));
    cl::Program::Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length()+1));

    if (sourceFile.is_open()){
        printf("the file is open\n");
    }else{
        printf("error opening file\n");
    }

    // Make program of the source code in the context
    cl::Program program = cl::Program(context, source);

    // Build program for these specific devices
    program.build(devices);

The code compiles fine, but I will get a clBuildProgram(-11) erro when I try to run it. I have verified that my kernel file can be successfully opened. Am I missing something here? Or is there a way to debug this error?

Thanks in advance!


回答1:


The error code -11 corresponds to CL_BUILD_PROGRAM_FAILURE. This indicates that your kernel code failed to compile, likely due to a syntax error. Assuming you've enabled exceptions in the OpenCL C++ bindings (#define __CL_ENABLE_EXCEPTIONS), you can retrieve the build log with something like this:

try
{
  program.build(devices);
}
catch (cl::Error error)
{
  if (error.err() == CL_BUILD_PROGRAM_FAILURE)
  {
    // Get the build log for the first device
    std::string log = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[0]);
    std::cerr << log << std::endl;
  }
  throw(error);
}


来源:https://stackoverflow.com/questions/29488393/getting-cl-build-program-failure-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!