[Beignet] [PATCH 4/7] Modify clGetKernelInfo using cl_get_info_helper.

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


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

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/cl_api.c             | 35 -----------------------------------
 src/cl_api_kernel.c      | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 src/cl_api_platform_id.c | 12 ++++++------
 3 files changed, 52 insertions(+), 43 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index 3a7c962..0ab03ea 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -1184,41 +1184,6 @@ error:
 }
 
 cl_int
-clGetKernelInfo(cl_kernel        kernel,
-                cl_kernel_info   param_name,
-                size_t           param_value_size,
-                void *           param_value,
-                size_t *         param_value_size_ret)
-{
-  cl_int err;
-
-  CHECK_KERNEL(kernel);
-
-  if (param_name == CL_KERNEL_CONTEXT) {
-    FILL_GETINFO_RET (cl_context, 1, &kernel->program->ctx, CL_SUCCESS);
-  } else if (param_name == CL_KERNEL_PROGRAM) {
-    FILL_GETINFO_RET (cl_program, 1, &kernel->program, CL_SUCCESS);
-  } else if (param_name == CL_KERNEL_NUM_ARGS) {
-    cl_uint n = kernel->arg_n;
-    FILL_GETINFO_RET (cl_uint, 1, &n, CL_SUCCESS);
-  } else if (param_name == CL_KERNEL_REFERENCE_COUNT) {
-    cl_int ref = CL_OBJECT_GET_REF(kernel);
-    FILL_GETINFO_RET (cl_int, 1, &ref, CL_SUCCESS);
-  } else if (param_name == CL_KERNEL_FUNCTION_NAME) {
-    const char * n = cl_kernel_get_name(kernel);
-    FILL_GETINFO_RET (cl_char, strlen(n)+1, n, CL_SUCCESS);
-  } else if (param_name == CL_KERNEL_ATTRIBUTES) {
-    const char * n = cl_kernel_get_attributes(kernel);
-    FILL_GETINFO_RET (cl_char, strlen(n)+1, n, CL_SUCCESS);
-  } else {
-    return CL_INVALID_VALUE;
-  }
-
-error:
-  return err;
-}
-
-cl_int
 clGetKernelWorkGroupInfo(cl_kernel                   kernel,
                          cl_device_id                device,
                          cl_kernel_work_group_info   param_name,
diff --git a/src/cl_api_kernel.c b/src/cl_api_kernel.c
index 1fd687b..fcc1931 100644
--- a/src/cl_api_kernel.c
+++ b/src/cl_api_kernel.c
@@ -28,6 +28,50 @@
 #include <string.h>
 
 cl_int
+clGetKernelInfo(cl_kernel kernel,
+                cl_kernel_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_KERNEL(kernel)) {
+    return CL_INVALID_KERNEL;
+  }
+
+  if (param_name == CL_KERNEL_CONTEXT) {
+    src_ptr = &kernel->program->ctx;
+    src_size = sizeof(cl_context);
+  } else if (param_name == CL_KERNEL_PROGRAM) {
+    src_ptr = &kernel->program;
+    src_size = sizeof(cl_program);
+  } else if (param_name == CL_KERNEL_NUM_ARGS) {
+    cl_uint n = kernel->arg_n;
+    src_ptr = &n;
+    src_size = sizeof(cl_uint);
+  } else if (param_name == CL_KERNEL_REFERENCE_COUNT) {
+    cl_int ref = CL_OBJECT_GET_REF(kernel);
+    src_ptr = &ref;
+    src_size = sizeof(cl_int);
+  } else if (param_name == CL_KERNEL_FUNCTION_NAME) {
+    const char *str = cl_kernel_get_name(kernel);
+    src_ptr = str;
+    src_size = strlen(str) + 1;
+  } else if (param_name == CL_KERNEL_ATTRIBUTES) {
+    const char *str = cl_kernel_get_attributes(kernel);
+    src_ptr = str;
+    src_size = strlen(str) + 1;
+  } else {
+    return CL_INVALID_VALUE;
+  }
+
+  return cl_get_info_helper(src_ptr, src_size,
+                            param_value, param_value_size, param_value_size_ret);
+}
+
+cl_int
 clEnqueueNDRangeKernel(cl_command_queue command_queue,
                        cl_kernel kernel,
                        cl_uint work_dim,
@@ -140,8 +184,8 @@ clEnqueueNDRangeKernel(cl_command_queue command_queue,
         if (realGroupSize % 8 != 0 && warn_no_good_localsize) {
           warn_no_good_localsize = 0;
           DEBUGP(DL_WARNING, "unable to find good values for local_work_size[i], please provide\n"
-                 " local_work_size[] explicitly, you can find good values with\n"
-                 " trial-and-error method.");
+                             " local_work_size[] explicitly, you can find good values with\n"
+                             " trial-and-error method.");
         }
       }
     }
diff --git a/src/cl_api_platform_id.c b/src/cl_api_platform_id.c
index 656dea3..10d8894 100644
--- a/src/cl_api_platform_id.c
+++ b/src/cl_api_platform_id.c
@@ -26,7 +26,7 @@ clGetPlatformInfo(cl_platform_id platform,
                   void *param_value,
                   size_t *param_value_size_ret)
 {
-  void *src_ptr = NULL;
+  const void *src_ptr = NULL;
   size_t src_size = 0;
 
   if (!CL_OBJECT_IS_PLATFORM(platform)) {
@@ -39,22 +39,22 @@ clGetPlatformInfo(cl_platform_id platform,
   }
 
   if (param_name == CL_PLATFORM_PROFILE) {
-    src_ptr = (void *)platform->profile;
+    src_ptr = platform->profile;
     src_size = platform->profile_sz;
   } else if (param_name == CL_PLATFORM_VERSION) {
-    src_ptr = (void *)platform->version;
+    src_ptr = platform->version;
     src_size = platform->version_sz;
   } else if (param_name == CL_PLATFORM_NAME) {
-    src_ptr = (void *)platform->name;
+    src_ptr = platform->name;
     src_size = platform->name_sz;
   } else if (param_name == CL_PLATFORM_VENDOR) {
-    src_ptr = (void *)platform->vendor;
+    src_ptr = 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_ptr = platform->icd_suffix_khr;
     src_size = platform->icd_suffix_khr_sz;
   } else {
     return CL_INVALID_VALUE;
-- 
2.7.4





More information about the Beignet mailing list