2015-04-07 146 views
0

我目前正在开发一个关于OpenCL的项目,并在尝试构建该程序时遇到了一些麻烦。所以,我有以下代码:越来越cl_build_program_failure错误

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

的代码编译好,但我会得到一个clBuildProgram(-11)埃罗当我尝试运行它。我已验证我的内核文件可以成功打开。 我在这里错过了什么吗?或者有没有办法来调试这个错误?

提前致谢!

回答

2

错误代码-11对应于CL_BUILD_PROGRAM_FAILURE。这表明您的内核代码无法编译,可能是由于语法错误。假设您已经在OpenCL C++绑定中启用了例外(#define __CL_ENABLE_EXCEPTIONS),则可以使用类似如下方式检索构建日志:

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