[Beignet] [PATCH 6/7] Modify clGetContextInfo using cl_get_info_helper.

junyan.he at inbox.com junyan.he at inbox.com
Sat Oct 8 08:47:55 UTC 2016


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

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/CMakeLists.txt   |  1 +
 src/cl_api.c         | 33 ----------------------------
 src/cl_api_context.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 33 deletions(-)
 create mode 100644 src/cl_api_context.c

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 61aaddc..1980a9b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -73,6 +73,7 @@ set(OPENCL_SRC
     cl_api_kernel.c
     cl_api_command_queue.c
     cl_api_event.c
+	cl_api_context.c
     cl_alloc.c
     cl_kernel.c
     cl_program.c
diff --git a/src/cl_api.c b/src/cl_api.c
index 0a69aca..ab51152 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -275,39 +275,6 @@ error:
   return err;
 }
 
-cl_int
-clGetContextInfo(cl_context      context,
-                 cl_context_info param_name,
-                 size_t          param_value_size,
-                 void *          param_value,
-                 size_t *        param_value_size_ret)
-{
-  cl_int err = CL_SUCCESS;
-  CHECK_CONTEXT (context);
-
-  if (param_name == CL_CONTEXT_DEVICES) {
-    FILL_GETINFO_RET (cl_device_id, 1, &context->device, CL_SUCCESS);
-  } else if (param_name == CL_CONTEXT_NUM_DEVICES) {
-    cl_uint n = 1;
-    FILL_GETINFO_RET (cl_uint, 1, &n, CL_SUCCESS);
-  } else if (param_name == CL_CONTEXT_REFERENCE_COUNT) {
-    cl_uint ref = CL_OBJECT_GET_REF(context);
-    FILL_GETINFO_RET (cl_uint, 1, &ref, CL_SUCCESS);
-  } else if (param_name == CL_CONTEXT_PROPERTIES) {
-    if(context->prop_len > 0) {
-      FILL_GETINFO_RET (cl_context_properties, context->prop_len, context->prop_user, CL_SUCCESS);
-    } else {
-      cl_context_properties n = 0;
-      FILL_GETINFO_RET (cl_context_properties, 1, &n, CL_SUCCESS);
-    }
-  } else {
-    return CL_INVALID_VALUE;
-  }
-
-error:
-  return err;
-}
-
 cl_command_queue
 clCreateCommandQueue(cl_context                   context,
                      cl_device_id                 device,
diff --git a/src/cl_api_context.c b/src/cl_api_context.c
new file mode 100644
index 0000000..d2adb41
--- /dev/null
+++ b/src/cl_api_context.c
@@ -0,0 +1,61 @@
+/*
+ * 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_context.h"
+
+cl_int
+clGetContextInfo(cl_context context,
+                 cl_context_info param_name,
+                 size_t param_value_size,
+                 void *param_value,
+                 size_t *param_value_size_ret)
+{
+  const void *src_ptr = NULL;
+  size_t src_size = 0;
+
+  if (!CL_OBJECT_IS_CONTEXT(context)) {
+    return CL_INVALID_CONTEXT;
+  }
+
+  if (param_name == CL_CONTEXT_DEVICES) {
+    src_ptr = &context->device;
+    src_size = sizeof(cl_device_id);
+  } else if (param_name == CL_CONTEXT_NUM_DEVICES) {
+    cl_uint n = 1;
+    src_ptr = &n;
+    src_size = sizeof(cl_uint);
+  } else if (param_name == CL_CONTEXT_REFERENCE_COUNT) {
+    cl_uint ref = CL_OBJECT_GET_REF(context);
+    src_ptr = &ref;
+    src_size = sizeof(cl_uint);
+  } else if (param_name == CL_CONTEXT_PROPERTIES) {
+    if (context->prop_len > 0) {
+      src_ptr = context->prop_user;
+      src_size = sizeof(cl_context_properties) * context->prop_len;
+    } else {
+      cl_context_properties n = 0;
+      src_ptr = &n;
+      src_size = sizeof(cl_context_properties);
+    }
+  } else {
+    return CL_INVALID_VALUE;
+  }
+
+  return cl_get_info_helper(src_ptr, src_size,
+                            param_value, param_value_size, param_value_size_ret);
+}
-- 
2.7.4





More information about the Beignet mailing list