[Beignet] [PATCH 3/4] Modify clGetImageInfo using cl_get_info_helper.

junyan.he at inbox.com junyan.he at inbox.com
Mon Oct 10 07:20:09 UTC 2016


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

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/cl_api.c     |  14 --------
 src/cl_api_mem.c |  84 +++++++++++++++++++++++++++++++++++++++++++++
 src/cl_mem.c     | 101 -------------------------------------------------------
 src/cl_mem.h     |  18 +++++++---
 4 files changed, 98 insertions(+), 119 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index 2560b71..1f45e88 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -498,20 +498,6 @@ error:
 }
 
 cl_int
-clGetImageInfo(cl_mem         mem,
-               cl_image_info  param_name,
-               size_t         param_value_size,
-               void *         param_value,
-               size_t *       param_value_size_ret)
-{
-  return cl_get_image_info(mem,
-                           param_name,
-                           param_value_size,
-                           param_value,
-                           param_value_size_ret);
-}
-
-cl_int
 clSetMemObjectDestructorCallback(cl_mem  memobj,
                                  void (CL_CALLBACK *pfn_notify) (cl_mem, void*),
                                  void * user_data)
diff --git a/src/cl_api_mem.c b/src/cl_api_mem.c
index ae0fb9f..7f1f5c7 100644
--- a/src/cl_api_mem.c
+++ b/src/cl_api_mem.c
@@ -105,6 +105,90 @@ clGetMemObjectInfo(cl_mem memobj,
                             param_value, param_value_size, param_value_size_ret);
 }
 
+cl_int
+clGetImageInfo(cl_mem memobj,
+               cl_image_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;
+  struct _cl_mem_image *image;
+
+  if (!CL_OBJECT_IS_MEM(memobj)) {
+    return CL_INVALID_MEM_OBJECT;
+  }
+  image = cl_mem_image(memobj);
+
+  switch (param_name) {
+  case CL_IMAGE_FORMAT:
+    src_ptr = &image->fmt;
+    src_size = sizeof(cl_image_format);
+    break;
+  case CL_IMAGE_ELEMENT_SIZE:
+    src_ptr = &image->bpp;
+    src_size = sizeof(size_t);
+    break;
+  case CL_IMAGE_ROW_PITCH:
+    src_ptr = &image->row_pitch;
+    src_size = sizeof(size_t);
+    break;
+  case CL_IMAGE_SLICE_PITCH:
+    src_ptr = &image->slice_pitch;
+    src_size = sizeof(size_t);
+    break;
+  case CL_IMAGE_WIDTH:
+    if (memobj->type == CL_MEM_BUFFER1D_IMAGE_TYPE) {
+      struct _cl_mem_buffer1d_image *buffer1d_image = (struct _cl_mem_buffer1d_image *)image;
+      src_ptr = &buffer1d_image->size;
+    } else {
+      src_ptr = &image->w;
+    }
+    src_size = sizeof(size_t);
+    break;
+  case CL_IMAGE_HEIGHT: {
+    size_t height = 0;
+    if (memobj->type != CL_MEM_BUFFER1D_IMAGE_TYPE) {
+      height = IS_1D_IMAGE(image) ? 0 : image->h;
+    }
+    src_ptr = &height;
+    src_size = sizeof(size_t);
+    break;
+  }
+  case CL_IMAGE_DEPTH: {
+    size_t depth = 0;
+    depth = IS_3D_IMAGE(image) ? image->depth : 0;
+    src_ptr = &depth;
+    src_size = sizeof(size_t);
+    break;
+  }
+  case CL_IMAGE_ARRAY_SIZE: {
+    size_t array_sz = 0;
+    array_sz = IS_IMAGE_ARRAY(image) ? image->depth : 0;
+    src_ptr = &array_sz;
+    src_size = sizeof(size_t);
+    break;
+  }
+  case CL_IMAGE_BUFFER:
+    src_ptr = &image->buffer_1d;
+    src_size = sizeof(cl_mem);
+    break;
+  case CL_IMAGE_NUM_MIP_LEVELS:
+  case CL_IMAGE_NUM_SAMPLES: {
+    cl_uint value = 0;
+    src_ptr = &value;
+    src_size = sizeof(cl_uint);
+    break;
+  }
+  default:
+    return CL_INVALID_VALUE;
+  }
+
+  return cl_get_info_helper(src_ptr, src_size,
+                            param_value, param_value_size, param_value_size_ret);
+}
+
 void *
 clEnqueueMapBuffer(cl_command_queue command_queue,
                    cl_mem buffer,
diff --git a/src/cl_mem.c b/src/cl_mem.c
index 2b91515..abf6dd6 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -37,16 +37,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#define FIELD_SIZE(CASE,TYPE)               \
-  case JOIN(CL_,CASE):                      \
-    if(param_value_size_ret)                \
-      *param_value_size_ret = sizeof(TYPE); \
-    if(!param_value)                        \
-      return CL_SUCCESS;                    \
-    if(param_value_size < sizeof(TYPE))     \
-      return CL_INVALID_VALUE;              \
-    break;
-
 #define MAX_TILING_SIZE                             128 * MB
 
 LOCAL cl_mem_object_type
@@ -67,97 +57,6 @@ cl_get_mem_object_type(cl_mem mem)
   }
 }
 
-
-#define IS_1D(image) (image->image_type == CL_MEM_OBJECT_IMAGE1D ||        \
-                      image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ||  \
-                      image->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER)
-
-#define IS_2D(image) (image->image_type == CL_MEM_OBJECT_IMAGE2D ||        \
-                      image->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY)
-
-#define IS_3D(image) (image->image_type == CL_MEM_OBJECT_IMAGE3D)
-
-#define IS_ARRAY(image) (image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY || \
-                         image->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY)
-
-LOCAL cl_int
-cl_get_image_info(cl_mem mem,
-                  cl_image_info param_name,
-                  size_t param_value_size,
-                  void *param_value,
-                  size_t *param_value_size_ret)
-{
-  int err;
-  CHECK_IMAGE(mem, image);
-
-  switch(param_name)
-  {
-    FIELD_SIZE(IMAGE_FORMAT, cl_image_format);
-    FIELD_SIZE(IMAGE_ELEMENT_SIZE, size_t);
-    FIELD_SIZE(IMAGE_ROW_PITCH, size_t);
-    FIELD_SIZE(IMAGE_SLICE_PITCH, size_t);
-    FIELD_SIZE(IMAGE_WIDTH, size_t);
-    FIELD_SIZE(IMAGE_HEIGHT, size_t);
-    FIELD_SIZE(IMAGE_DEPTH, size_t);
-    FIELD_SIZE(IMAGE_ARRAY_SIZE, size_t);
-    FIELD_SIZE(IMAGE_BUFFER, cl_mem);
-    FIELD_SIZE(IMAGE_NUM_MIP_LEVELS, cl_uint);
-    FIELD_SIZE(IMAGE_NUM_SAMPLES, cl_uint);
-  default:
-    return CL_INVALID_VALUE;
-  }
-
-  switch(param_name)
-  {
-  case CL_IMAGE_FORMAT:
-    *(cl_image_format *)param_value = image->fmt;
-    break;
-  case CL_IMAGE_ELEMENT_SIZE:
-    *(size_t *)param_value = image->bpp;
-    break;
-  case CL_IMAGE_ROW_PITCH:
-    *(size_t *)param_value = image->row_pitch;
-    break;
-  case CL_IMAGE_SLICE_PITCH:
-    *(size_t *)param_value = image->slice_pitch;
-    break;
-  case CL_IMAGE_WIDTH:
-
-    if (mem->type == CL_MEM_BUFFER1D_IMAGE_TYPE) {
-      struct _cl_mem_buffer1d_image *buffer1d_image = (struct _cl_mem_buffer1d_image*) image;
-      *(size_t *)param_value = buffer1d_image->size;
-    } else
-      *(size_t *)param_value = image->w;
-    break;
-  case CL_IMAGE_HEIGHT:
-    if (mem->type == CL_MEM_BUFFER1D_IMAGE_TYPE)
-      *(size_t *)param_value = 0;
-    else
-      *(size_t *)param_value = IS_1D(image) ? 0 : image->h;
-    break;
-  case CL_IMAGE_DEPTH:
-    *(size_t *)param_value = IS_3D(image) ? image->depth : 0;
-    break;
-  case CL_IMAGE_ARRAY_SIZE:
-    *(size_t *)param_value = IS_ARRAY(image) ? image->depth : 0;
-    break;
-  case CL_IMAGE_BUFFER:
-    *(cl_mem *)param_value = image->buffer_1d;
-    break;
-  case CL_IMAGE_NUM_MIP_LEVELS:
-  case CL_IMAGE_NUM_SAMPLES:
-    *(cl_mem *)param_value = 0;
-    break;
-  }
-
-  return CL_SUCCESS;
-
-error:
-    return err;
-}
-
-#undef FIELD_SIZE
-
 LOCAL cl_mem
 cl_mem_allocate(enum cl_mem_type type,
                 cl_context ctx,
diff --git a/src/cl_mem.h b/src/cl_mem.h
index 4026028..66ab121 100644
--- a/src/cl_mem.h
+++ b/src/cl_mem.h
@@ -117,7 +117,7 @@ struct _cl_mem_image {
   _cl_mem base;
   cl_image_format fmt;            /* only for images */
   uint32_t intel_fmt;             /* format to provide in the surface state */
-  uint32_t bpp;                   /* number of bytes per pixel */
+  size_t bpp;                     /* number of bytes per pixel */
   cl_mem_object_type image_type;  /* only for images 1D/2D...*/
   size_t w, h, depth;             /* only for images (depth is only for 3D images) */
   size_t row_pitch, slice_pitch;
@@ -142,6 +142,19 @@ struct _cl_mem_buffer1d_image {
   uint32_t size;
 };
 
+#define IS_1D_IMAGE(image) (image->image_type == CL_MEM_OBJECT_IMAGE1D ||        \
+                            image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ||  \
+                            image->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER)
+
+#define IS_2D_IMAGE(image) (image->image_type == CL_MEM_OBJECT_IMAGE2D ||        \
+                            image->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY)
+
+#define IS_3D_IMAGE(image) (image->image_type == CL_MEM_OBJECT_IMAGE3D)
+
+#define IS_IMAGE_ARRAY(image) (image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY || \
+                               image->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY)
+
+
 inline static void
 cl_mem_image_init(struct _cl_mem_image *image, size_t w, size_t h,
                   cl_mem_object_type image_type,
@@ -199,9 +212,6 @@ cl_mem_buffer(cl_mem mem)
 
 extern cl_mem_object_type cl_get_mem_object_type(cl_mem mem);
 
-/* Query information about an image */
-extern cl_int cl_get_image_info(cl_mem, cl_image_info, size_t, void *, size_t *);
-
 /* Query whether mem is in buffers */
 extern cl_int cl_mem_is_valid(cl_mem mem, cl_context ctx);
 
-- 
2.7.4





More information about the Beignet mailing list