【问题标题】:Device says it is available, but can't create context in OpenCL设备说它可用,但无法在 OpenCL 中创建上下文
【发布时间】:2013-06-28 17:39:47
【问题描述】:

我尝试在我的 Intel 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 = %s\n", buffer);
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_VERSION,10240, buffer,NULL);
printf("  VERSION = %s\n", buffer);
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_NAME,10240, buffer,NULL);
printf("  NAME = %s\n", buffer);
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_VENDOR,10240, buffer,NULL);
printf("  VENDOR = %s\n", buffer);
clGetPlatformInfo(firstPlatformId,CL_PLATFORM_EXTENSIONS,10240, buffer,NULL);
printf("  VENDOR = %s\n", buffer);
//  clGetPlatformInfo(platforms[i],CL_PLATFORM_EXTENSIONS,10240,buffer,NULL);
//  printf("  EXTENSIONS = %s\n", 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 IDS\n");
printf("  === %d OpenCL device(s) found on platform: 0\n\n", 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 = %s\n", buffer);
  (clGetDeviceInfo(device, CL_DEVICE_VENDOR, sizeof(buffer), 
       buffer, NULL));
  printf("    DEVICE_VENDOR = %s\n", buffer);
  (clGetDeviceInfo(device, CL_DEVICE_VERSION, sizeof(buffer), 
       buffer, NULL));
  printf("    DEVICE_VERSION = %s\n", buffer);
  (clGetDeviceInfo(device, CL_DRIVER_VERSION, sizeof(buffer), 
       buffer, NULL));
  printf("    DRIVER_VERSION = %s\n", buffer);
  (clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, 
       sizeof(buf_uint), &buf_uint, NULL));
  printf("    DEVICE_MAX_COMPUTE_UNITS = %u\n", (unsigned int)buf_uint);
  (clGetDeviceInfo(device, CL_DEVICE_MAX_CLOCK_FREQUENCY, 
       sizeof(buf_uint), &buf_uint, NULL));
  printf("    DEVICE_MAX_CLOCK_FREQUENCY = %u\n", (unsigned int)buf_uint);
  (clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE, 
       sizeof(buf_ulong), &buf_ulong, NULL));
  printf("    DEVICE_GLOBAL_MEM_SIZE = %u\n\n", (unsigned int)buf_ulong);
  (clGetDeviceInfo(device, CL_DEVICE_AVAILABLE, 
       sizeof(buf_bool), &buf_bool, NULL));
  printf("    DEVICE_AVAILABLE = %s\n\n", buf_bool?"Yes":"No");
}
if (devices_n == 0)
{
  printf("error, on platform 0, there is no GPU device\n");
}

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 说设备可用,但在应该创建上下文时却失败并显示“设备不可用”?

【问题讨论】:

  • 它似乎是OpenCL device(s) found on platform: 0,但在行首有一个无关紧要的1。我不知道这是否相关,但我想我会指出这一点。
  • 这只是表示它在平台 0 上找到了 1 个设备(从 0 开始计数设备和平台,因此这是第一个平台)
  • 啊 - 考虑到以下部分是有道理的。

标签: c++ c opencl intel


【解决方案1】:

因此,一个可能的解释可能是由于英特尔 SDK,正如 post 中所解释的那样。引用主要思想:

Intel OpenCL CPU 至少需要 SSE 4.1。 Core 2 Duo 只涨了 到 SSSE3。

给出的解决方案是:

安装 AMD OpenCL CPU 驱动程序。它只需要 SSE2。

【讨论】:

  • 我会试试这个,但是根据 CPU-flags 和 intel 文档,我的 CPU 有 sse 4.1。
  • 好的,它适用于 AMD。我对此并不满意,但它确实有效。谢谢。
【解决方案2】:

不使用clCreateContextFromType(),只需使用clCreateContext() 并将clGetDeviceIDs() 返回的CPU 设备的设备ID 传递给它。

【讨论】:

  • 如果平台找到了一个opencl设备并返回了这个CPU,说明这个CPU是兼容的。顺便说一句,英特尔酷睿 2 双核处理器,8000 系列在列表中,只是有一个错字;它写的是 Dou 而不是 Duo。如果您使用基于该词的自动搜索,这或许可以解释为什么您没有找到它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-20
  • 2015-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-31
相关资源
最近更新 更多