[Beignet] [PATCH] GBE: fix kernel arguments uploading bug.

Zhigang Gong zhigang.gong at intel.com
Fri Oct 9 18:10:35 PDT 2015


After the curbe allocation refactor, not all kernel arguments
will be allocated unconditional. If some kernel arguments haven't
been used at all, the corresponding arguments will be ignored
at backend thus we may get a -1 offset. On the runtime driver
side, we need check this situation.

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 src/cl_command_queue_gen7.c | 6 ++++--
 src/cl_kernel.c             | 8 +++++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/cl_command_queue_gen7.c b/src/cl_command_queue_gen7.c
index 8c09615..2edc3be 100644
--- a/src/cl_command_queue_gen7.c
+++ b/src/cl_command_queue_gen7.c
@@ -173,7 +173,8 @@ cl_upload_constant_buffer(cl_command_queue queue, cl_kernel ker)
       uint32_t alignment = interp_kernel_get_arg_align(ker->opaque, arg);
       offset = ALIGN(offset, alignment);
       curbe_offset = interp_kernel_get_curbe_offset(ker->opaque, GBE_CURBE_KERNEL_ARGUMENT, arg);
-      assert(curbe_offset >= 0);
+      if (curbe_offset < 0)
+        continue;
       *(uint32_t *) (ker->curbe + curbe_offset) = offset;
 
       cl_buffer_map(mem->bo, 1);
@@ -228,7 +229,8 @@ cl_curbe_fill(cl_kernel ker,
     assert(align != 0);
     slm_offset = ALIGN(slm_offset, align);
     offset = interp_kernel_get_curbe_offset(ker->opaque, GBE_CURBE_KERNEL_ARGUMENT, arg);
-    assert(offset >= 0);
+    if (offset < 0)
+      continue;
     uint32_t *slmptr = (uint32_t *) (ker->curbe + offset);
     *slmptr = slm_offset;
     slm_offset += ker->args[arg].local_sz;
diff --git a/src/cl_kernel.c b/src/cl_kernel.c
index 5d170c6..58a1224 100644
--- a/src/cl_kernel.c
+++ b/src/cl_kernel.c
@@ -153,9 +153,10 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
   /* Copy the structure or the value directly into the curbe */
   if (arg_type == GBE_ARG_VALUE) {
     offset = interp_kernel_get_curbe_offset(k->opaque, GBE_CURBE_KERNEL_ARGUMENT, index);
-    assert(offset + sz <= k->curbe_sz);
-    if (offset >= 0)
+    if (offset >= 0) {
+      assert(offset + sz <= k->curbe_sz);
       memcpy(k->curbe + offset, value, sz);
+    }
     k->args[index].local_sz = 0;
     k->args[index].is_set = 1;
     k->args[index].mem = NULL;
@@ -193,7 +194,8 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
   if(value == NULL || mem == NULL) {
     /* for buffer object GLOBAL_PTR CONSTANT_PTR, it maybe NULL */
     int32_t offset = interp_kernel_get_curbe_offset(k->opaque, GBE_CURBE_KERNEL_ARGUMENT, index);
-    *((uint32_t *)(k->curbe + offset)) = 0;
+    if (offset >= 0)
+      *((uint32_t *)(k->curbe + offset)) = 0;
     assert(arg_type == GBE_ARG_GLOBAL_PTR || arg_type == GBE_ARG_CONSTANT_PTR);
 
     if (k->args[index].mem)
-- 
1.9.1



More information about the Beignet mailing list