我在Ubuntu 14.04.2 LTS(NVIDIA Corporation GM204 [GeForce GTX 980])上运行OpenCL / C ++代码。它在CPU上正常工作,但是当我将clGetDeviceIDs
更改为CL_DEVICE_TYPE_CPU
时,CL_DEVICE_TYPE_GPU
方法返回-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。
为什么?
我根据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