c++ - clGetDeviceInfo 和 clGetPlatformInfo 在 OpenCL 中失败,错误代码为 -30 (CL_INVALID_VALUE)

标签 c++ opencl gpgpu opencl.net

我开始为使用 OpenCL 编写一个小“引擎”。现在,我遇到了一个很奇怪的问题。

当我调用 clGetDeviceInfo() 查询特定设备的信息时,参数 param_name 的一些选项返回错误代码 -30 (= CL_INVALID_VALUE)。一个非常著名的选项是 CL_DEVICE_EXTENSIONS 选项,无论我使用什么 sdk 或平台,它都应该返回一串扩展。我检查了每条边,还仔细检查了参数。

另一件我不明白的事情是,当我在我的 Windows 机器上运行我的源代码时,clGetPlatformInfo() 函数也会返回 CL_INVALID_VALUE 查询 CL_PLATFORM_EXTENSIONS 字符串。在家里,我使用的是运行 Ubuntu 的 Linux 机器,它可以毫无问题地显示扩展字符串。


这是我的平台的数据:

  • 工作:

    • 英特尔酷睿 i5 2500 CPU
    • NVIDIA Geforce 210 GPU
    • AMD APP SDK 3.0 测试版
  • 首页:

    • 英特尔酷睿 i7 5820K CPU
    • AMD Radeon HD7700 GPU
    • AMD APP SDK 3.0 测试版

这是来源:

源代码是用 cpp 编写的,opencl 函数嵌入在一些包装类(即 OCLDevice)中。

OCLDevice::OCLDevice(cl_device_id device)
{
  cl_int errNum;
  cl_uint uintBuffer;
  cl_long longBuffer;
  cl_bool boolBuffer;   
  char str[128];
  size_t strSize = (sizeof(char) * 128);
  size_t retSize;

  //Device name string.
  errNum = 
      clGetDeviceInfo(device,CL_DEVICE_NAME,strSize,(void*)str,&retSize);
  throwException();
  this->name = string(str,retSize);

  //The platform associated with this device.
  errNum = 
     clGetDeviceInfo(device, CL_DEVICE_PLATFORM,
                     sizeof(cl_platform_id),
                     (void*)&(this->platform), &retSize);
  throwException();

  //The OpenCL device type.
  errNum = 
      clGetDeviceInfo(device, CL_DEVICE_TYPE, 
                      sizeof(cl_device_type),
                      (void*)&(this->devType),&retSize);
  throwException();

  //Vendor name string.
  errNum = 
      clGetDeviceInfo(device,CL_DEVICE_VENDOR,
                      strSize,(void*)str,&retSize);
  throwException();
  this->vendor = string(str,retSize);

  //A unique device vendor identifier. 
  //An example of a unique device identifier could be the PCIe ID.
  errNum =
      clGetDeviceInfo(device, CL_DEVICE_VENDOR_ID,
                      sizeof(unsigned int),
                      (void*)&(this->vendorID),&retSize);
  throwException();

  //Returns a space separated list of extension names
  //supported by the device.
  clearString(str,retSize); //fills the char string with 0-characters
  errNum =
      clGetDeviceInfo(device,CL_DEVICE_EXTENSIONS,strSize,str,&retSize);
  throwException();

  //some more queries (some with some without the same error)...
}

正如您在代码中看到的那样 param_value_size> param_value_size_ret 这样就没有理由返回错误了。 param_name 是从要保存的 header 中复制的,没有输入错误。

如果有人知道这个问题的答案就太好了。

最佳答案

OpenCL 规范声明 clGetDeviceInfo 可以返回 CL_INVALID_VALUE 如果(除其他事项外):

... or if size in bytes specified by param_value_size is < size of return type as specified in table 4.3 ...

对于 CL_DEVICE_EXTENSIONS 查询,您已为 128 个字符分配存储空间,并将 128 作为 param_value_size 参数传递。如果设备支持大量扩展,则它完全有可能需要 超过 128 个字符。

您可以通过将0NULL 传递给param_value_sizeparam_value 来查询存储查询结果所需的空间量 参数,然后使用它来分配足够的存储空间:

clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &retSize);

char extensions[retSize];
clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, retSize, extensions, &retSize);

关于c++ - clGetDeviceInfo 和 clGetPlatformInfo 在 OpenCL 中失败,错误代码为 -30 (CL_INVALID_VALUE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29290806/

相关文章:

c++ - 什么是 CStringArray 或 CSortStringArray。那么如何将这个数组按顺序排列呢?

c++ - 如何将int4数组复制到int8 vector 中

c++ - OpenCL 中的 FFT 2D 内核运行时间 =0

c - CUDA 大整数加法

cuda - "Global Load Efficiency"超过 100%

c++ - 使递归在 C++ 中更高效

c++ - 对于大文件,我应该使用哪个 libxml2 API?

类层次结构中的 C++ 异常处理

c - 初始化 OpenCL 对象

c# - 我如何在 Emgu CV 项目中利用 OpenCL