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

给你一囗甜甜゛ 提交于 2019-12-12 04:54:52

问题


I am starting to write a little "engine" for using OpenCL. Now, I encountered a problem that is quite strange.

When I call clGetDeviceInfo() to query informations of the specific device, some of the options for the parameter param_name return the error code -30 ( = CL_INVALID_VALUE). A very famous one is the option CL_DEVICE_EXTENSIONS which should return me a string of extensions no matter what sdk or platform I am using. I checked every edge and also the parameters are double checked.

Another thing I do not understand is when I run my source on my Windows machine at work, the clGetPlatformInfo() function also returns me CL_INVALID_VALUE querying the CL_PLATFORM_EXTENSIONS string. At home I am using a Linux machine running Ubuntu and it shows the extensions string without any problem.


Here are the data of my platforms:

  • Work:

    • Intel Core i5 2500 CPU
    • NVIDIA Geforce 210 GPU
    • AMD APP SDK 3.0 Beta
  • Home:

    • Intel Core i7 5820K CPU
    • AMD Radeon HD7700 GPU
    • AMD APP SDK 3.0 Beta

And here is the source:

The source is written in cpp and the opencl fuctions are embedded in some wrapper classes (i.e. 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)...
}

As you can see in the code param_value_size > param_value_size_ret so that there is no reason to return the error, too. The param_name is copied from the header to be save there is no typing error.

It would be great if somebody knew an answer to this problem.


回答1:


The OpenCL specification states that clGetDeviceInfo can return CL_INVALID_VALUE if (among other things):

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

For the CL_DEVICE_EXTENSIONS query, you have allocated storage for 128 characters, and are passing 128 as the param_value_size parameter. If the device supports a lot of extensions, it is entirely possible that it needs more than 128 characters.

You can query the amount of space needed to store the query result by passing 0 and NULL to the param_value_size and param_value arguments, and then use this to allocate sufficient storage:

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

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


来源:https://stackoverflow.com/questions/29290806/clgetdeviceinfo-and-clgetplatforminfo-fails-in-opencl-with-error-code-30-cl-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!