【问题标题】:OpenCL clGetDeviceIDs returns -1 when GPU and 0 when CPUOpenCL clGetDeviceIDs 在 GPU 时返回 -1,在 CPU 时返回 0
【发布时间】:2020-06-10 03:44:09
【问题描述】:

我在 Ubuntu 14.04.2 LTS(NVIDIA Corporation GM204 [GeForce GTX 980])上运行我的 OpenCL/C++ 代码。 它在 CPU 上正常工作,但当我将 CL_DEVICE_TYPE_CPU 更改为 CL_DEVICE_TYPE_GPU 时,clGetDeviceIDs 方法返回 -1。

有问题的代码:

ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices);
cout << ret;
checkError(ret, "clGetDeviceIDs");

输出 -1。

但是如下:

ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_CPU, 1, &device_id, &ret_num_devices);
cout << ret;
checkError(ret, "clGetDeviceIDs");

输出 0。

为什么?

【问题讨论】:

  • 这应该更多是您的 Ubunto 操作系统和某些设备驱动程序安装之间的冲突,而不是 OpenCL 编码问题。
  • 谢谢@Christian,我该如何检查/解决这个问题?

标签: opencl gpu


【解决方案1】:

我根据this link中的代码做了一些修改:

cl_int ret = clGetPlatformIDs(2, platforms, &ret_num_platforms);
cout << ret;
//ret = clGetDeviceIDs( platforms[0], CL_DEVICE_TYPE_CPU, 1, &device_id, &ret_num_devices);  // Execute me on CPU
ret = clGetDeviceIDs(platforms[1], CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices); // Execute me on GPU

【讨论】:

    猜你喜欢
    • 2016-10-27
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 2022-12-14
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多