简体   繁体   中英

getting cl_build_program_failure error

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!

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);
}

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