2015-04-07 145 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); 
}