问题描述
我开始为使用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 Beta
-
主页:
- 英特尔酷睿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 中看到,因此也没有理由返回错误.从标题中复制 param_name 并保存,没有键入错误.
如果有人知道这个问题的答案,那就太好了.
OpenCL规范指出,clGetDeviceInfo
可以在以下情况下返回CL_INVALID_VALUE
:
对于CL_DEVICE_EXTENSIONS
查询,您已为128个字符分配了存储空间,并且正在将128作为param_value_size
参数传递.如果设备支持很多扩展,则完全有可能需要更多个128个字符以上的.
您可以通过将0
和NULL
传递给param_value_size
和param_value
参数来查询存储查询结果所需的空间量,然后使用它来分配足够的存储空间:
clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &retSize);
char extensions[retSize];
clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, retSize, extensions, &retSize);
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.
The OpenCL specification states that clGetDeviceInfo
can return CL_INVALID_VALUE
if (among other things):
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);
这篇关于clGetDeviceInfo和clGetPlatformInfo在OpenCL中失败,错误代码为-30(CL_INVALID_VALUE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!