收到 cl_build_program_failure 错误
getting cl_build_program_failure error
我目前正在做一个关于 OpenCL 的项目,运行 在尝试构建该程序时遇到了一些麻烦。所以我有以下代码:
//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) 错误。我已经验证我的内核文件可以成功打开。
我在这里错过了什么吗?或者有没有办法调试这个错误?
提前致谢!
错误代码-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);
}
我目前正在做一个关于 OpenCL 的项目,运行 在尝试构建该程序时遇到了一些麻烦。所以我有以下代码:
//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) 错误。我已经验证我的内核文件可以成功打开。 我在这里错过了什么吗?或者有没有办法调试这个错误?
提前致谢!
错误代码-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);
}