[Beignet] [PATCH 1/2] Move Device related APIs to new file

junyan.he at inbox.com junyan.he at inbox.com
Mon Dec 19 05:18:40 UTC 2016


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

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/cl_api.c           | 82 --------------------------------------------------
 src/cl_api_device_id.c | 56 ++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 82 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index 6a4f4ec..1bc181c 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -67,24 +67,6 @@ typedef intptr_t cl_device_partition_property;
 	  return RET; \
 	} while(0)
 
-static cl_int
-cl_check_device_type(cl_device_type device_type)
-{
-  const cl_device_type valid =  CL_DEVICE_TYPE_GPU
-                              | CL_DEVICE_TYPE_CPU
-                              | CL_DEVICE_TYPE_ACCELERATOR
-                              | CL_DEVICE_TYPE_DEFAULT
-                              | CL_DEVICE_TYPE_CUSTOM;
-
-  if( (device_type & valid) == 0) {
-    return CL_INVALID_DEVICE_TYPE;
-  }
-  if(UNLIKELY(!(device_type & CL_DEVICE_TYPE_DEFAULT) && !(device_type & CL_DEVICE_TYPE_GPU)))
-    return CL_DEVICE_NOT_FOUND;
-
-  return CL_SUCCESS;
-}
-
 cl_int
 clGetPlatformIDs(cl_uint          num_entries,
                  cl_platform_id * platforms,
@@ -98,70 +80,6 @@ clGetPlatformIDs(cl_uint          num_entries,
   return cl_get_platform_ids(num_entries, platforms, num_platforms);
 }
 
-cl_int
-clGetDeviceIDs(cl_platform_id platform,
-               cl_device_type device_type,
-               cl_uint        num_entries,
-               cl_device_id * devices,
-               cl_uint *      num_devices)
-{
-  cl_int err = CL_SUCCESS;
-
-  /* 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;
-
-  err = cl_check_device_type(device_type);
-  if(err != CL_SUCCESS)
-    return err;
-
-  return cl_get_device_ids(platform,
-                           device_type,
-                           num_entries,
-                           devices,
-                           num_devices);
-}
-
-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;
-}
-
-cl_int
-clRetainDevice(cl_device_id device)
-{
-  // XXX stub for C++ Bindings
-  return CL_SUCCESS;
-}
-
-cl_int
-clReleaseDevice(cl_device_id device)
-{
-#ifdef HAS_CMRT
-  if (device->cmrt_device != NULL)
-    cmrt_destroy_device(device);
-#endif
-
-  // XXX stub for C++ Bindings
-  return CL_SUCCESS;
-}
-
 cl_command_queue
 clCreateCommandQueueWithProperties(cl_context                         context,
                                    cl_device_id                       device,
diff --git a/src/cl_api_device_id.c b/src/cl_api_device_id.c
index 4b67dc3..4ffef78 100644
--- a/src/cl_api_device_id.c
+++ b/src/cl_api_device_id.c
@@ -17,6 +17,31 @@
  */
 
 #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_get_device_ids(platform, device_type, num_entries, devices, num_devices);
+}
 
 cl_int
 clGetDeviceInfo(cl_device_id device,
@@ -32,3 +57,34 @@ clGetDeviceInfo(cl_device_id device,
   return cl_get_device_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