[Beignet] [PATCH 1/2] Add helper functions for device list check.
junyan.he at inbox.com
junyan.he at inbox.com
Thu Nov 10 05:44:45 UTC 2016
From: Junyan He <junyan.he at intel.com>
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 at intel.com>
---
src/cl_device_id.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/cl_device_id.h | 4 ++++
2 files changed, 55 insertions(+)
diff --git a/src/cl_device_id.c b/src/cl_device_id.c
index 88284c6..2bc172c 100644
--- a/src/cl_device_id.c
+++ b/src/cl_device_id.c
@@ -1581,3 +1581,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 19e367b..510db9e 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__ */
--
2.7.4
More information about the Beignet
mailing list