diff --git a/opencl/khronos/headers/opencl2.2/CL/cl.hpp b/opencl/khronos/headers/opencl2.2/CL/cl.hpp index 71e55e0678..0ffc16b51d 100644 --- a/opencl/khronos/headers/opencl2.2/CL/cl.hpp +++ b/opencl/khronos/headers/opencl2.2/CL/cl.hpp @@ -2240,17 +2240,22 @@ public: return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); } cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); - if (err != CL_SUCCESS) { + if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) { return detail::errHandler(err, __GET_DEVICE_IDS_ERR); } - cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); - err = ::clGetDeviceIDs(object_, type, n, ids, NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + if (n > 0) { + cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); + err = ::clGetDeviceIDs(object_, type, n, ids, NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } + + devices->assign(&ids[0], &ids[n]); + } else { + devices->clear(); } - devices->assign(&ids[0], &ids[n]); return CL_SUCCESS; } diff --git a/opencl/khronos/headers/opencl2.2/CL/cl2.hpp b/opencl/khronos/headers/opencl2.2/CL/cl2.hpp index 09764a0060..77653dad50 100644 --- a/opencl/khronos/headers/opencl2.2/CL/cl2.hpp +++ b/opencl/khronos/headers/opencl2.2/CL/cl2.hpp @@ -2349,14 +2349,16 @@ public: return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); } cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); - if (err != CL_SUCCESS) { + if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) { return detail::errHandler(err, __GET_DEVICE_IDS_ERR); } vector ids(n); - err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + if (n>0) { + err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL); + if (err != CL_SUCCESS) { + return detail::errHandler(err, __GET_DEVICE_IDS_ERR); + } } // Cannot trivially assign because we need to capture intermediates