[Beignet] [PATCH OCL20 5/5] Runtime: Add support for clGetMemObjectInfo

Xiuli Pan xiuli.pan at intel.com
Fri Mar 4 02:05:24 UTC 2016


From: Pan Xiuli <xiuli.pan at intel.com>

clGetMemObjectInfo with CL_MEM_ASSOCIATED_MEMOBJECT should return
the mem in cl_image_desc. As in CL_MEM_OBJECT_IMAGE1D_BUFFER we
copy the buffer, add a workaround for it.

Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 src/cl_mem.c | 14 ++++++++++----
 src/cl_mem.h |  1 +
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/cl_mem.c b/src/cl_mem.c
index c41417c..eebe8da 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -118,12 +118,16 @@ cl_get_mem_object_info(cl_mem mem,
     *((cl_context *)param_value) = mem->ctx;
     break;
   case CL_MEM_ASSOCIATED_MEMOBJECT:
-    if(mem->type != CL_MEM_SUBBUFFER_TYPE) {
-      *((cl_mem *)param_value) = NULL;
-    } else {
+    if(mem->type == CL_MEM_SUBBUFFER_TYPE) {
       struct _cl_mem_buffer* buf = (struct _cl_mem_buffer*)mem;
       *((cl_mem *)param_value) = (cl_mem)(buf->parent);
-    }
+    } else if (mem->type == CL_MEM_IMAGE_TYPE) {
+      *((cl_mem *)param_value) = mem;
+    } else if (mem->type == CL_MEM_BUFFER1D_IMAGE_TYPE) {
+      struct _cl_mem_buffer1d_image* image_buffer = (struct _cl_mem_buffer1d_image*)mem;
+      *((cl_mem *)param_value) = image_buffer->descbuffer;
+    } else
+      *((cl_mem *)param_value) = NULL;
     break;
   case CL_MEM_OFFSET:
     if(mem->type != CL_MEM_SUBBUFFER_TYPE) {
@@ -1282,6 +1286,8 @@ _cl_mem_new_image_from_buffer(cl_context ctx,
     memcpy(dst, src, mem_buffer->base.size);
     cl_mem_unmap(image);
     cl_mem_unmap(buffer);
+    struct _cl_mem_buffer1d_image* image_buffer = (struct _cl_mem_buffer1d_image*)image;
+    image_buffer->descbuffer = buffer;
   }
   else
     assert(0);
diff --git a/src/cl_mem.h b/src/cl_mem.h
index 6e729ac..2a47c46 100644
--- a/src/cl_mem.h
+++ b/src/cl_mem.h
@@ -138,6 +138,7 @@ struct _cl_mem_gl_image {
 struct _cl_mem_buffer1d_image {
   struct _cl_mem_image base;
   uint32_t size;
+  _cl_mem * descbuffer;
 };
 
 inline static void
-- 
2.5.0



More information about the Beignet mailing list