获取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 openn");
}else{
printf("error opening filen");
}
// 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
。这表明您的内核代码未能编译,可能是由于语法错误。假设您已经在OpenCLC++绑定(#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);
}
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 为什么我会收到"Run-Time Check Failure #2 - Stack around the variable 'pr' was corrupted"错误?
- "candidate template ignored: substitution failure:"编译器错误?
- c++ 收到错误"Run-Time check failure #2 - stack around variable sub was corrupted"