[Beignet] [PATCH 2/3] Refine error check in clGetDeviceIDs()
Ruiling Song
ruiling.song at intel.com
Thu Jun 6 00:07:17 PDT 2013
move error check to api level. correctly handle mixed device type.
Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
src/cl_api.c | 37 +++++++++++++++++++++++++++++++++++++
src/cl_device_id.c | 24 ------------------------
2 files changed, 37 insertions(+), 24 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index e710147..6887add 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -37,6 +37,24 @@
#include <string.h>
#include <assert.h>
+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,
@@ -75,6 +93,20 @@ clGetDeviceIDs(cl_platform_id platform,
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 != intel_platform))
+ 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,
@@ -149,6 +181,11 @@ clCreateContextFromType(const cl_context_properties * properties,
cl_device_id devices[1];
cl_uint num_devices = 1;
+ err = cl_check_device_type(device_type);
+ if(err != CL_SUCCESS) {
+ goto error;
+ }
+
err = cl_get_device_ids(NULL,
device_type,
1,
diff --git a/src/cl_device_id.c b/src/cl_device_id.c
index e3a4c76..7669602 100644
--- a/src/cl_device_id.c
+++ b/src/cl_device_id.c
@@ -107,30 +107,6 @@ cl_get_device_ids(cl_platform_id platform,
{
cl_device_id device;
- /* Check parameter consistency */
- if (UNLIKELY(devices == NULL && num_devices == NULL))
- return CL_SUCCESS;
- if (UNLIKELY(platform && platform != intel_platform))
- return CL_INVALID_PLATFORM;
- if (UNLIKELY(
- device_type != CL_DEVICE_TYPE_GPU &&
- device_type != CL_DEVICE_TYPE_DEFAULT &&
- device_type != CL_DEVICE_TYPE_ALL
- ))
- {
- if (num_devices)
- *num_devices = 0;
-
- if (device_type == CL_DEVICE_TYPE_CPU ||
- device_type == CL_DEVICE_TYPE_ACCELERATOR
- )
- return CL_DEVICE_NOT_FOUND;
- else
- return CL_INVALID_DEVICE_TYPE;
- }
- if (UNLIKELY(devices && num_entries == 0))
- return CL_INVALID_VALUE;
-
/* Do we have a usable device? */
device = cl_get_gt_device();
if (!device) {
--
1.7.9.5
More information about the Beignet
mailing list