From 0779b034c488c6a1bede49523aacae87584b3dbf Mon Sep 17 00:00:00 2001 From: Vlad Sytchenko Date: Fri, 10 Apr 2020 16:22:53 -0400 Subject: [PATCH] Cherry pick 5c6b85 from KhronosGroup/OpenCL-CLHPP Updates cl2.hpp and cl.hpp to handle case of platform with zero devices without error. Change-Id: I6190c65ebf894b3a26579c54e96881c334346358 --- opencl/khronos/headers/opencl2.2/CL/cl.hpp | 17 +++++++++++------ opencl/khronos/headers/opencl2.2/CL/cl2.hpp | 10 ++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) 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