小编Pej*_*vak的帖子

在 OpenCL 库中找不到 cl::Error 类

我在一些代码中看到,在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)

c++ error-handling opencl

1
推荐指数
1
解决办法
402
查看次数

标签 统计

c++ ×1

error-handling ×1

opencl ×1