[英]OpenCL: How to check for build errors using the C++ wrapper
If I build an openCL Program from source code like this 如果我从这样的源代码构建一个openCL程序
cl::Program program = cl::Program(context, sourceCode);
program.build(devices);
I would like to check if this was successful. 我想检查一下这是否成功。 I saw a few examples of how to do this in C, but since my project ist in C++ I was wondering how to get (in case something goes wrong) a readable text message that indicates what might be the issue using the C++ wrapper. 我在C中看到了一些如何执行此操作的示例,但由于我的项目是在C ++中,因此我想知道如何获取(如果出现问题)可读的文本消息,该消息指示使用C ++包装器可能存在的问题。
I have also enabled exceptions 我也启用了例外
#define CL_HPP_ENABLE_EXCEPTIONS
but do not know if build(...)
throws an exception. 但不知道build(...)
会抛出异常。
I am using the AMD APP SDK 3.0 and the cl2.hpp
from the Khronos webpage (as it was not included in the SDK). 我正在使用AMD APP SDK 3.0和Khronos网页上的cl2.hpp
(因为它没有包含在SDK中)。
The cl::Program::build()
function does indeed throw an exception if the build fails. 如果构建失败, cl::Program::build()
函数确实会抛出异常。 Here's how you can get the build log: 以下是如何获取构建日志:
cl::Program program = cl::Program(context, sourceCode);
try
{
program.build(devices);
}
catch (cl::Error& e)
{
if (e.err() == CL_BUILD_PROGRAM_FAILURE)
{
for (cl::Device dev : devices)
{
// Check the build status
cl_build_status status = program.getBuildInfo<CL_PROGRAM_BUILD_STATUS>(dev);
if (status != CL_BUILD_ERROR)
continue;
// Get the build log
std::string name = dev.getInfo<CL_DEVICE_NAME>();
std::string buildlog = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(dev);
std::cerr << "Build log for " << name << ":" << std::endl
<< buildlog << std::endl;
}
else
{
throw e;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.