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

xionghu.luo at intel.com xionghu.luo at intel.com
Wed Sep 10 15:34:12 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.

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

diff --git a/src/cl_kernel.c b/src/cl_kernel.c
index 5ab9c55..8eec907 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,6 +137,9 @@ 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 (!mem_in_buffers(mem, ctx->buffers))
+        return CL_INVALID_ARG_VALUE;
+
       if (UNLIKELY(mem->magic != CL_MAGIC_MEM_HEADER))
         return CL_INVALID_MEM_OBJECT;
 
diff --git a/src/cl_mem.c b/src/cl_mem.c
index 11411d9..d4bbe2c 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -289,6 +289,18 @@ error:
 
 }
 
+LOCAL cl_bool
+mem_in_buffers(cl_mem mem, cl_mem buffers)
+{
+  cl_mem tmp = buffers;
+  while(tmp){
+    if(mem == tmp)
+      return CL_TRUE;
+    tmp = tmp->next;
+  }
+  return CL_FALSE;
+}
+
 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..3bcad18 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_bool mem_in_buffers(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