0

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!

forseqn
  • 39
  • 8

1 Answers1

4

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);
}
jprice
  • 9,755
  • 1
  • 28
  • 32