[Beignet] [PATCH 3/7] Modify clGetPlatformInfo using cl_get_info_helper.

junyan.he at inbox.com junyan.he at inbox.com
Sat Oct 8 08:47:52 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             | 18 --------------
 src/cl_api_platform_id.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/cl_platform_id.c     | 51 -------------------------------------
 src/cl_platform_id.h     |  7 ------
 src/cl_utils.c           |  2 +-
 src/cl_utils.h           |  2 +-
 7 files changed, 68 insertions(+), 78 deletions(-)
 create mode 100644 src/cl_api_platform_id.c

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 069a3c4..61aaddc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -68,6 +68,7 @@ set(OPENCL_SRC
     ${KERNEL_STR_FILES}
     cl_base_object.c
     cl_api.c
+    cl_api_platform_id.c
     cl_api_mem.c
     cl_api_kernel.c
     cl_api_command_queue.c
diff --git a/src/cl_api.c b/src/cl_api.c
index 5e2d4e3..3a7c962 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -106,24 +106,6 @@ clGetPlatformIDs(cl_uint          num_entries,
 }
 
 cl_int
-clGetPlatformInfo(cl_platform_id    platform,
-                  cl_platform_info  param_name,
-                  size_t            param_value_size,
-                  void *            param_value,
-                  size_t *          param_value_size_ret)
-{
-  /* Only one platform. This is easy */
-  if (UNLIKELY(platform != NULL && platform != cl_get_platform_default()))
-    return CL_INVALID_PLATFORM;
-
-  return cl_get_platform_info(platform,
-                              param_name,
-                              param_value_size,
-                              param_value,
-                              param_value_size_ret);
-}
-
-cl_int
 clGetDeviceIDs(cl_platform_id platform,
                cl_device_type device_type,
                cl_uint        num_entries,
diff --git a/src/cl_api_platform_id.c b/src/cl_api_platform_id.c
new file mode 100644
index 0000000..656dea3
--- /dev/null
+++ b/src/cl_api_platform_id.c
@@ -0,0 +1,65 @@
+/*
+ * 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_platform_id.h"
+#include "CL/cl_ext.h"
+
+cl_int
+clGetPlatformInfo(cl_platform_id platform,
+                  cl_platform_info param_name,
+                  size_t param_value_size,
+                  void *param_value,
+                  size_t *param_value_size_ret)
+{
+  void *src_ptr = NULL;
+  size_t src_size = 0;
+
+  if (!CL_OBJECT_IS_PLATFORM(platform)) {
+    return CL_INVALID_PLATFORM;
+  }
+
+  /* Only one platform now. */
+  if (platform != cl_get_platform_default()) {
+    return CL_INVALID_PLATFORM;
+  }
+
+  if (param_name == CL_PLATFORM_PROFILE) {
+    src_ptr = (void *)platform->profile;
+    src_size = platform->profile_sz;
+  } else if (param_name == CL_PLATFORM_VERSION) {
+    src_ptr = (void *)platform->version;
+    src_size = platform->version_sz;
+  } else if (param_name == CL_PLATFORM_NAME) {
+    src_ptr = (void *)platform->name;
+    src_size = platform->name_sz;
+  } else if (param_name == CL_PLATFORM_VENDOR) {
+    src_ptr = (void *)platform->vendor;
+    src_size = platform->vendor_sz;
+  } else if (param_name == CL_PLATFORM_EXTENSIONS) {
+    src_ptr = platform->extensions;
+    src_size = platform->extensions_sz;
+  } else if (param_name == CL_PLATFORM_ICD_SUFFIX_KHR) {
+    src_ptr = (void *)platform->icd_suffix_khr;
+    src_size = platform->icd_suffix_khr_sz;
+  } else {
+    return CL_INVALID_VALUE;
+  }
+
+  return cl_get_info_helper(src_ptr, src_size,
+                            param_value, param_value_size, param_value_size_ret);
+}
diff --git a/src/cl_platform_id.c b/src/cl_platform_id.c
index 400f6f7..1f21f5d 100644
--- a/src/cl_platform_id.c
+++ b/src/cl_platform_id.c
@@ -69,54 +69,3 @@ cl_get_platform_ids(cl_uint          num_entries,
 
   return CL_SUCCESS;
 }
-
-#define DECL_FIELD(CASE,FIELD)                                  \
-  case JOIN(CL_,CASE):                                          \
-    if (param_value_size < cl_get_platform_default()->JOIN(FIELD,_sz))     \
-      return CL_INVALID_VALUE;                                  \
-    if (param_value_size_ret != NULL)                           \
-      *param_value_size_ret = cl_get_platform_default()->JOIN(FIELD,_sz);  \
-    memcpy(param_value,                                         \
-           cl_get_platform_default()->FIELD,                               \
-           cl_get_platform_default()->JOIN(FIELD,_sz));                    \
-      return CL_SUCCESS;
-
-#define GET_FIELD_SZ(CASE,FIELD)                                \
-  case JOIN(CL_,CASE):                                          \
-    if (param_value_size_ret != NULL)                           \
-      *param_value_size_ret = cl_get_platform_default()->JOIN(FIELD,_sz);  \
-    return CL_SUCCESS;
-
-LOCAL cl_int
-cl_get_platform_info(cl_platform_id    platform,
-                     cl_platform_info  param_name,
-                     size_t            param_value_size,
-                     void *            param_value,
-                     size_t *          param_value_size_ret)
-{
-  if (param_value == NULL) {
-    switch (param_name) {
-      GET_FIELD_SZ (PLATFORM_PROFILE,    profile);
-      GET_FIELD_SZ (PLATFORM_VERSION,    version);
-      GET_FIELD_SZ (PLATFORM_NAME,       name);
-      GET_FIELD_SZ (PLATFORM_VENDOR,     vendor);
-      GET_FIELD_SZ (PLATFORM_EXTENSIONS, extensions);
-      GET_FIELD_SZ (PLATFORM_ICD_SUFFIX_KHR, icd_suffix_khr);
-      default: return CL_INVALID_VALUE;
-    }
-  }
-
-  /* Fetch the platform inform */
-  switch (param_name) {
-    DECL_FIELD (PLATFORM_PROFILE,    profile);
-    DECL_FIELD (PLATFORM_VERSION,    version);
-    DECL_FIELD (PLATFORM_NAME,       name);
-    DECL_FIELD (PLATFORM_VENDOR,     vendor);
-    DECL_FIELD (PLATFORM_EXTENSIONS, extensions);
-    DECL_FIELD (PLATFORM_ICD_SUFFIX_KHR, icd_suffix_khr);
-    default: return CL_INVALID_VALUE;
-  }
-}
-
-#undef DECL_FIELD
-
diff --git a/src/cl_platform_id.h b/src/cl_platform_id.h
index aaba624..3fdb920 100644
--- a/src/cl_platform_id.h
+++ b/src/cl_platform_id.h
@@ -57,13 +57,6 @@ extern cl_int cl_get_platform_ids(cl_uint          num_entries,
                                   cl_platform_id * platforms,
                                   cl_uint *        num_platforms);
 
-/* Return information for the current platform */
-extern cl_int cl_get_platform_info(cl_platform_id    platform,
-                                   cl_platform_info  param_name,
-                                   size_t            param_value_size,
-                                   void *            param_value,
-                                   size_t *          param_value_size_ret);
-
 #define _STR(x) #x
 #define _JOINT(x, y) _STR(x) "." _STR(y)
 #define _JOINT3(x, y, z) _STR(x) "." _STR(y) "." _STR(z)
diff --git a/src/cl_utils.c b/src/cl_utils.c
index dd0f146..295210f 100644
--- a/src/cl_utils.c
+++ b/src/cl_utils.c
@@ -20,7 +20,7 @@
 #include <string.h>
 
 LOCAL cl_int
-cl_get_info_helper(void *src, size_t src_size, void *dst, size_t dst_size, size_t *ret_size)
+cl_get_info_helper(const void *src, size_t src_size, void *dst, size_t dst_size, size_t *ret_size)
 {
   if (dst && dst_size < src_size)
     return CL_INVALID_VALUE;
diff --git a/src/cl_utils.h b/src/cl_utils.h
index b2fa6a6..829b774 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -451,5 +451,5 @@ static inline void list_splice_tail(struct list_head *list, struct list_head *he
   for (pos = (head)->next, n = pos->next; pos != (head); \
        pos = n, n = pos->next)
 
-extern cl_int cl_get_info_helper(void *src, size_t src_size, void *dst, size_t dst_size, size_t *ret_size);
+extern cl_int cl_get_info_helper(const void *src, size_t src_size, void *dst, size_t dst_size, size_t *ret_size);
 #endif /* __CL_UTILS_H__ */
-- 
2.7.4





More information about the Beignet mailing list