问题描述
我目前正在从事有关OpenCL的项目,在尝试构建程序时遇到了一些麻烦.所以我有以下代码:
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);
代码可以很好地编译,但是当我尝试运行它时,我会得到clBuildProgram(-11)错误.我已验证可以成功打开我的内核文件.我在这里想念什么吗?还是有办法调试此错误?
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?
提前谢谢!
推荐答案
错误代码-11
对应于CL_BUILD_PROGRAM_FAILURE
.这表明您的内核代码可能由于语法错误而无法编译.假设您已在OpenCL C ++绑定(#define __CL_ENABLE_EXCEPTIONS
)中启用了例外,则可以使用以下内容检索构建日志:
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);
}
这篇关于出现cl_build_program_failure错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!