设备表示它可用,但无法在 OpenCL 中创建上下文
Device says it is available, but can't create context in OpenCL
我尝试在英特尔CPU上运行程序。我使用实际的英特尔SDK,它编译并工作到应该创建上下文的地步。这是程序的输出:
===== Platform 0 =====
PROFILE = FULL_PROFILE
VERSION = OpenCL 1.2 LINUX
NAME = Intel(R) OpenCL
VENDOR = Intel(R) Corporation
VENDOR = cl_khr_fp64 cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_intel_printf cl_ext_device_fission cl_intel_exec_by_local_thread
=== 1 OpenCL device(s) found on platform: 0
=== --- Device -- 0
DEVICE_NAME = Intel(R) Core(TM)2 Duo CPU P8400 @ 2.26GHz
DEVICE_VENDOR = Intel(R) Corporation
DEVICE_VERSION = OpenCL 1.2 (Build 67279)
DRIVER_VERSION = 1.2
DEVICE_MAX_COMPUTE_UNITS = 2
DEVICE_MAX_CLOCK_FREQUENCY = 2260
DEVICE_GLOBAL_MEM_SIZE = 4035719168
DEVICE_AVAILABLE = Yes
Unable to create GPU or CPU context
CL_DEVICE_NOT_AVAILABLE
unable to create context. Abort.
这就是造成问题的代码。
cl_context CTrainMLP_CreateContext(){
cl_int errNum;
cl_uint numPlatforms;
cl_platform_id firstPlatformId;
cl_context context=NULL;
cl_device_id device;
//get Platform and choose first one
errNum = clGetPlatformIDs(1,&firstPlatformId, &numPlatforms);
if(errNum != CL_SUCCESS || numPlatforms<=0){
cerr<<"No OpenCL platforum found!"<<endl;
return NULL;
}
char buffer[10240];
printf("===== Platform 0 =====n");
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_PROFILE,10240, buffer,NULL);
printf(" PROFILE = %sn", buffer);
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_VERSION,10240, buffer,NULL);
printf(" VERSION = %sn", buffer);
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_NAME,10240, buffer,NULL);
printf(" NAME = %sn", buffer);
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_VENDOR,10240, buffer,NULL);
printf(" VENDOR = %sn", buffer);
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_EXTENSIONS,10240, buffer,NULL);
printf(" VENDOR = %sn", buffer);
// clGetPlatformInfo(platforms[i],CL_PLATFORM_EXTENSIONS,10240,buffer,NULL);
// printf(" EXTENSIONS = %sn", buffer);
cl_uint devices_n;
// get the GPU-devices of platform i, print details of the device
errNum = clGetDeviceIDs( firstPlatformId, CL_DEVICE_TYPE_CPU, 1, &device,
&devices_n);
if (errNum != CL_SUCCESS)
printf("error getting device IDSn");
printf(" === %d OpenCL device(s) found on platform: 0nn", devices_n);
for (unsigned int d=0; d<devices_n; d++)
{
char buffer[10240];
cl_uint buf_uint;
cl_ulong buf_ulong;
cl_bool buf_bool;
printf(" === --- Device -- %d n", d);
(clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(buffer),
buffer, NULL));
printf(" DEVICE_NAME = %sn", buffer);
(clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(buffer),
buffer, NULL));
printf(" DEVICE_VENDOR = %sn", buffer);
(clGetDeviceInfo(device, CL_DEVICE_VERSION, sizeof(buffer),
buffer, NULL));
printf(" DEVICE_VERSION = %sn", buffer);
(clGetDeviceInfo(device, CL_DRIVER_VERSION, sizeof(buffer),
buffer, NULL));
printf(" DRIVER_VERSION = %sn", buffer);
(clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(buf_uint), &buf_uint, NULL));
printf(" DEVICE_MAX_COMPUTE_UNITS = %un", (unsigned int)buf_uint);
(clGetDeviceInfo(device, CL_DEVICE_MAX_CLOCK_FREQUENCY,
sizeof(buf_uint), &buf_uint, NULL));
printf(" DEVICE_MAX_CLOCK_FREQUENCY = %un", (unsigned int)buf_uint);
(clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE,
sizeof(buf_ulong), &buf_ulong, NULL));
printf(" DEVICE_GLOBAL_MEM_SIZE = %unn", (unsigned int)buf_ulong);
(clGetDeviceInfo(device, CL_DEVICE_AVAILABLE,
sizeof(buf_bool), &buf_bool, NULL));
printf(" DEVICE_AVAILABLE = %snn", buf_bool?"Yes":"No");
}
if (devices_n == 0)
{
printf("error, on platform 0, there is no GPU devicen");
}
cl_context_properties contextProperties[3]={
CL_CONTEXT_PLATFORM,
(cl_context_properties)firstPlatformId,
0
};
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_ALL,NULL,NULL,&errNum);
if (errNum!= CL_SUCCESS){
cerr<<"Unable to create GPU or CPU context"<<endl;
check_error(errNum);
return NULL;
}
cout<<"Created CPU context"<<endl;
return context;
}
为什么OpenCL说,设备是可用的,但当它应该创建上下文时,却以"设备不可用"失败?
因此,一种可能的解释可能是,正如文章中所解释的,这是由于英特尔SDK造成的。引用主要思想:
Intel OpenCL CPU至少需要SSE 4.1。Core 2 Duo只上升至SSSE3。
给出的解决方案是:
安装AMD OpenCL CPU驱动程序。它只需要SSE2。
不使用clCreateContextFromType()
,只使用clCreateContext()
并将从clGetDeviceIDs()
返回的CPU设备的设备id传递给它。
相关文章:
- 使用std::vector的OpenCL矩阵乘法
- #为""定义宏;静态";针对不同的上下文
- 与互斥锁相比,旋转锁可以保证上下文切换
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- 为什么我不能使用 EGL 创建无头 OpenGl 上下文?
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 为什么在逗号分隔符上下文中将预增量的结果强制转换为void
- 错误"Could not find Boost"(缺少:上下文标头)
- 使用 mod_gsoap 部署服务时,如何在 Gsoap 中更改 soap 上下文的模式?
- 将有状态的 lambda 传递到 C 样式函数中,而无需上下文参数
- OpenCL 内核参数中的字符***?
- 安排带有上下文的协同程序
- 从cl_context创建 OpenCL 上下文,而无需获得所有权
- 类成员的 OpenCL 上下文作用域
- 如何在使用 OpenCL 时指定上下文(平台/设备信息)
- 如何在 OSX 上使用 glfw3 在 OpenGL 和 OpenCL 之间创建共享上下文
- OpenCL C++上下文属性语法
- OpenCL OpenGL 互操作上下文创建失败
- 设备表示它可用,但无法在 OpenCL 中创建上下文
- OpenCL - c++包装器-动态库中的上下文取消初始化导致访问冲突