[Beignet] [PATCH] fix piglit cl-api-set-kernel-arg fail.

xionghu.luo at intel.com xionghu.luo at intel.com
Wed Sep 10 17:43:54 PDT 2014


From: Luo Xionghu <xionghu.luo at intel.com>

the memory object should be checked whether valid in context buffers before being set as kernel arguments.

v2: rename the function from mem_in_buffers to is_valid_mem, move the
magic header check into it.

Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
 src/cl_kernel.c |    3 ++-
 src/cl_mem.c    |   15 +++++++++++++++
 src/cl_mem.h    |    3 +++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/cl_kernel.c b/src/cl_kernel.c
index 5ab9c55..d7c2f7c 100644
--- a/src/cl_kernel.c
+++ b/src/cl_kernel.c
@@ -99,6 +99,7 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
   enum gbe_arg_type arg_type; /* kind of argument */
   size_t arg_sz;              /* size of the argument */
   cl_mem mem = NULL;          /* for __global, __constant and image arguments */
+  cl_context ctx = k->program->ctx;
 
   if (UNLIKELY(index >= k->arg_n))
     return CL_INVALID_ARG_INDEX;
@@ -136,7 +137,7 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
     if(value != NULL)
       mem = *(cl_mem*)value;
     if(value != NULL && mem) {
-      if (UNLIKELY(mem->magic != CL_MAGIC_MEM_HEADER))
+      if( CL_SUCCESS != is_valid_mem(mem, ctx->buffers))
         return CL_INVALID_MEM_OBJECT;
 
       if (UNLIKELY((arg_type == GBE_ARG_IMAGE && !IS_IMAGE(mem))
diff --git a/src/cl_mem.c b/src/cl_mem.c
index 11411d9..077f1d7 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -289,6 +289,21 @@ error:
 
 }
 
+LOCAL cl_int
+is_valid_mem(cl_mem mem, cl_mem buffers)
+{
+  cl_mem tmp = buffers;
+  while(tmp){
+    if(mem == tmp){
+      if (UNLIKELY(mem->magic != CL_MAGIC_MEM_HEADER))
+        return CL_INVALID_MEM_OBJECT;
+      return CL_SUCCESS;
+    }
+    tmp = tmp->next;
+  }
+  return CL_INVALID_MEM_OBJECT;
+}
+
 LOCAL cl_mem
 cl_mem_new_buffer(cl_context ctx,
                   cl_mem_flags flags,
diff --git a/src/cl_mem.h b/src/cl_mem.h
index 57f38f1..0ccbb5d 100644
--- a/src/cl_mem.h
+++ b/src/cl_mem.h
@@ -177,6 +177,9 @@ extern cl_int cl_get_mem_object_info(cl_mem, cl_mem_info, size_t, void *, size_t
 /* 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 is_valid_mem(cl_mem mem, cl_mem buffers);
+
 /* Create a new memory object and initialize it with possible user data */
 extern cl_mem cl_mem_new_buffer(cl_context, cl_mem_flags, size_t, void*, cl_int*);
 
-- 
1.7.9.5



More information about the Beignet mailing list