diff options
author | Junyan He <junyan.he@intel.com> | 2016-11-10 13:44:45 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2016-12-16 17:24:41 +0800 |
commit | a0df1bc208246ec5f4ee672b8d2bfbde21ced8f2 (patch) | |
tree | 5b31907778f1fdcb090fccc7501b517b49bc2e68 | |
parent | 2a2a72712194c2b3bf9081893ecf051789824bd6 (diff) |
Add helper functions for device list check.
We need to consider device list rather than just
one single device. Need to check every device on
the device list.
Signed-off-by: Junyan He <junyan.he@intel.com>
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r-- | src/cl_device_id.c | 51 | ||||
-rw-r--r-- | src/cl_device_id.h | 4 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/cl_device_id.c b/src/cl_device_id.c index 444f3e23..b88194b7 100644 --- a/src/cl_device_id.c +++ b/src/cl_device_id.c @@ -1578,3 +1578,54 @@ cl_get_kernel_subgroup_info(cl_kernel kernel, error: return err; } + +LOCAL cl_int +cl_devices_list_check(cl_uint num_devices, const cl_device_id *devices) +{ + cl_uint i; + + if (devices == NULL) + return CL_INVALID_DEVICE; + + assert(num_devices > 0); + for (i = 0; i < num_devices; i++) { + if (!CL_OBJECT_IS_DEVICE(devices[i])) { + return CL_INVALID_DEVICE; + } + + if (devices[i]->available == CL_FALSE) { + return CL_DEVICE_NOT_AVAILABLE; + } + + // We now just support one platform. + if (devices[i]->platform != cl_get_platform_default()) { + return CL_INVALID_DEVICE; + } + + // TODO: We now just support Gen Device. + if (devices[i] != cl_get_gt_device()) { + return CL_INVALID_DEVICE; + } + } + + return CL_SUCCESS; +} + +LOCAL cl_int +cl_devices_list_include_check(cl_uint num_devices, const cl_device_id *devices, + cl_uint num_to_check, const cl_device_id *devices_to_check) +{ + cl_uint i, j; + + for (i = 0; i < num_to_check; i++) { + for (j = 0; j < num_devices; j++) { + if (devices_to_check[i] == devices[j]) + break; + } + + if (j == num_devices) + return CL_INVALID_DEVICE; + } + + return CL_SUCCESS; +} diff --git a/src/cl_device_id.h b/src/cl_device_id.h index 69aeeac0..aeb43a5b 100644 --- a/src/cl_device_id.h +++ b/src/cl_device_id.h @@ -182,5 +182,9 @@ extern cl_int cl_get_kernel_subgroup_info(cl_kernel kernel, extern cl_int cl_device_get_version(cl_device_id device, cl_int *ver); extern size_t cl_get_kernel_max_wg_sz(cl_kernel); +extern cl_int cl_devices_list_check(cl_uint num_devices, const cl_device_id *devices); +extern cl_int cl_devices_list_include_check(cl_uint num_devices, const cl_device_id *devices, + cl_uint num_to_check, const cl_device_id *devices_to_check); + #endif /* __CL_DEVICE_ID_H__ */ |