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

clGetDeviceInfo and clGetPlatformInfo fails in OpenCL with error code -30 (CL_INVALID_VALUE)

我开始写一些关于使用 OpenCL 的文章 "engine"。现在,我遇到了一个比较奇怪的问题。

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

另一件我不明白的事情是,当我 运行 我的源代码在我的 Windows 机器上工作时,clGetPlatformInfo() 功能也 return 我 CL_INVALID_VALUE 查询 CL_PLATFORM_EXTENSIONS 字符串。在家里,我使用 Linux 机器 运行ning Ubuntu,它显示扩展字符串没有任何问题。


以下是我平台的数据:


这是来源:

源代码是用 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 这样就没有理由了return 错误也是如此。 param_name 是从 header 复制过来的,以确保没有输入错误。

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

OpenCL 规范声明 clGetDeviceInfo 可以 return 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参数来查询存储查询结果所需的space数量,然后使用它来分配足够的存储空间:

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

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