我在一些代码中看到,在OpenCL库中,有一个名为cl::Error的类,OpenCL可以捕获代码中的错误和错误类型。但是当我添加我的代码时,就像这样
#include <CL/cl.hpp>
#include <fstream>
#include <iostream>
#include <cassert>
#include <exception>
#define __CL_ENABLE_EXCEPTIONS
int main()
{
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
assert(platforms.size() > 0);
auto myPlatform = platforms.front();
std::cout << "Using platform: " << myPlatform.getInfo<CL_PLATFORM_NAME>() << std::endl;
std::vector<cl::Device> devices;
myPlatform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
auto myDevice = devices.front();
std::cout<< "Using device: "<< myDevice.getInfo<CL_DEVICE_NAME>() << std::endl;
std::ifstream helloworldfile("helloWorldKernel.cl");
std::string src(std::istreambuf_iterator<char>(helloworldfile), (std::istreambuf_iterator<char>()));
cl::Program::Sources source(1,std::make_pair(src.c_str(), src.length() + 1));
cl::Context context(myDevice);
cl::Program program(context,source);
cl::CommandQueue queue(context,myDevice);
try
{
program.build("-cl-std=CL1.2");
} catch(cl::Error& e)
{
std::cout << e.what() …Run Code Online (Sandbox Code Playgroud)