[Beignet] [PATCH 33/57] Implement all device related API in cl_api_device_id.c

junyan.he at inbox.com junyan.he at inbox.com
Sun Jun 11 05:50:19 UTC 2017


From: Junyan He <junyan.he at intel.com>

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 runtime/cl_api_device_id.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
 create mode 100644 runtime/cl_api_device_id.c

diff --git a/runtime/cl_api_device_id.c b/runtime/cl_api_device_id.c
new file mode 100644
index 0000000..68bbf92
--- /dev/null
+++ b/runtime/cl_api_device_id.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "cl_device_id.h"
+#include "cl_platform_id.h"
+
+cl_int
+clGetDeviceIDs(cl_platform_id platform,
+               cl_device_type device_type,
+               cl_uint num_entries,
+               cl_device_id *devices,
+               cl_uint *num_devices)
+{
+  const cl_device_type valid_type = CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_CPU |
+                                    CL_DEVICE_TYPE_ACCELERATOR | CL_DEVICE_TYPE_DEFAULT |
+                                    CL_DEVICE_TYPE_CUSTOM;
+
+  /* Check parameter consistency */
+  if (UNLIKELY(devices == NULL && num_devices == NULL))
+    return CL_INVALID_VALUE;
+  if (UNLIKELY(platform && platform != cl_get_platform_default()))
+    return CL_INVALID_PLATFORM;
+  if (UNLIKELY(devices && num_entries == 0))
+    return CL_INVALID_VALUE;
+  if ((device_type & valid_type) == 0)
+    return CL_INVALID_DEVICE_TYPE;
+
+  return cl_device_get_ids(platform, device_type, num_entries, devices, num_devices);
+}
+
+cl_int
+clGetDeviceInfo(cl_device_id device,
+                cl_device_info param_name,
+                size_t param_value_size,
+                void *param_value,
+                size_t *param_value_size_ret)
+{
+  if (!CL_OBJECT_IS_DEVICE(device)) {
+    return CL_INVALID_DEVICE;
+  }
+
+  return cl_device_get_info(device, param_name, param_value_size,
+                            param_value, param_value_size_ret);
+}
+
+cl_int
+clRetainDevice(cl_device_id device)
+{
+  // XXX stub for C++ Bindings
+  return CL_SUCCESS;
+}
+
+cl_int
+clReleaseDevice(cl_device_id device)
+{
+  // XXX stub for C++ Bindings
+  return CL_SUCCESS;
+}
+
+cl_int
+clCreateSubDevices(cl_device_id in_device,
+                   const cl_device_partition_property *properties,
+                   cl_uint num_devices,
+                   cl_device_id *out_devices,
+                   cl_uint *num_devices_ret)
+{
+  /* Check parameter consistency */
+  if (UNLIKELY(out_devices == NULL && num_devices_ret == NULL))
+    return CL_INVALID_VALUE;
+  if (UNLIKELY(in_device == NULL && properties == NULL))
+    return CL_INVALID_VALUE;
+
+  *num_devices_ret = 0;
+  return CL_INVALID_DEVICE_PARTITION_COUNT;
+}
-- 
2.7.4





More information about the Beignet mailing list