opencl支持double双精度浮点数

先查看设备是否支持cl_khr_fp64, 若无cl_khr_fp64则设备不支持双精度浮点数。  如果有cl_khr_fp64的相关信息,在kernel文件中添加:

#pragma OPENCL EXTENSION cl_khr_fp64 : enable即可。


具体方法如下:

假设已获取某设备cl_device_id deviceId, 首先获取设备信息如下:

cl_int errNum;

size_t paramValueSize;

//cl_khr_fp64的相关信息在 cl_device_info CL_DEVICE_EXTENSIONS中

errNum = clGetDeviceInfo(deviceId, CL_DEVICE_EXTENSIONS, 0,NULL,¶mValueSize);

if(errNum != CL_SUCCESS)

{

cerr<<"failed to find opencl device info"<

return;

}

char* info = (char*)malloc(sizeof(char)*paramValueSize);

errNum = clGetDeviceInfo(deviceId, CL_DEVICE_EXTENSIONS, paramValueSize, info, NULL);

if(errNum !=  CL_SUCCESS)

{

cerr<<"failed to find opencl device info"<

return;

}

cout<<"CL_DEVICE_EXTENSIONS: \t"<


你可能感兴趣的:(C++,opencl)