首页 文章

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

提问于
浏览
0

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

当我调用 clGetDeviceInfo() 来查询特定设备的信息时,参数 param_name 的某些选项会返回错误代码-30(= CL_INVALID_VALUE) . 一个非常着名的选项是CL_DEVICE_EXTENSIONS,无论我使用什么sdk或平台,它都应该返回一串扩展名 . 我检查了每个边缘,并且还对参数进行了双重检查 .

另一件我不明白的是当我在工作的Windows机器上运行我的源时, clGetPlatformInfo() 函数也返回CL_INVALID_VALUE查询CL_PLATFORM_EXTENSIONS字符串 . 在家里我使用运行Ubuntu的Linux机器,它显示扩展字符串没有任何问题 .


以下是我的平台数据:

  • 工作:

  • Intel Core i5 2500 CPU

  • NVIDIA Geforce 210 GPU

  • AMD APP SDK 3.0 Beta

  • 主页:

  • Intel Core i7 5820K CPU

  • AMD Radeon HD7700 GPU

  • AMD APP SDK 3.0 Beta


以下是来源:

源代码用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中所看到的那样,也没有理由返回错误 . 从 Headers 中复制param_name以保存没有输入错误 .

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

1 回答

  • 2

    OpenCL规范声明 clGetDeviceInfo 可以返回 CL_INVALID_VALUE if(除其他外):

    ...或者如果param_value_size指定的字节大小是<表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);
    

相关问题