[Beignet] [PATCH OCL2.0 3/6] OCL20: Fix svm bugs

Xiuli Pan xiuli.pan at intel.com
Tue Mar 1 00:40:01 UTC 2016


From: Yang Rong <rong.r.yang at intel.com>

1. correct the context's svm list when delete.
2. Set svm sub buffer's offset when bind buffer.

Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
 src/cl_command_queue.c |  6 +++++-
 src/cl_mem.c           | 18 +++++++++++++++---
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/cl_command_queue.c b/src/cl_command_queue.c
index effb30b..50b85de 100644
--- a/src/cl_command_queue.c
+++ b/src/cl_command_queue.c
@@ -170,7 +170,11 @@ cl_command_queue_bind_surface(cl_command_queue queue, cl_kernel k)
       struct _cl_mem_buffer* buffer = (struct _cl_mem_buffer*)k->args[i].mem;
       cl_gpgpu_bind_buf(gpgpu, k->args[i].mem->bo, offset, k->args[i].mem->offset + buffer->sub_offset, k->args[i].mem->size, interp_kernel_get_arg_bti(k->opaque, i));
     } else {
-      cl_gpgpu_bind_buf(gpgpu, k->args[i].mem->bo, offset, k->args[i].mem->offset, k->args[i].mem->size, interp_kernel_get_arg_bti(k->opaque, i));
+      size_t mem_offset = 0; //
+      if(k->args[i].is_svm) {
+        mem_offset = (size_t)k->args[i].ptr - (size_t)k->args[i].mem->host_ptr;
+      }
+      cl_gpgpu_bind_buf(gpgpu, k->args[i].mem->bo, offset, k->args[i].mem->offset + mem_offset, k->args[i].mem->size, interp_kernel_get_arg_bti(k->opaque, i));
     }
   }
 
diff --git a/src/cl_mem.c b/src/cl_mem.c
index 05aa70f..0922e0a 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -1392,15 +1392,27 @@ cl_mem_delete(cl_mem mem)
 
   /* Remove it from the list */
   if (mem->ctx) {
-    pthread_mutex_lock(&mem->ctx->buffer_lock);
+    if(mem->is_svm && mem->type == CL_MEM_SVM_TYPE) {
+      pthread_mutex_lock(&mem->ctx->svm_lock);
+      if (mem->prev)
+        mem->prev->next = mem->next;
+      if (mem->next)
+        mem->next->prev = mem->prev;
+      if (mem->ctx->svm_buffers == mem)
+        mem->ctx->svm_buffers = mem->next;
+      pthread_mutex_unlock(&mem->ctx->svm_lock);
+      cl_context_delete(mem->ctx);
+    } else {
+      pthread_mutex_lock(&mem->ctx->buffer_lock);
       if (mem->prev)
         mem->prev->next = mem->next;
       if (mem->next)
         mem->next->prev = mem->prev;
       if (mem->ctx->buffers == mem)
         mem->ctx->buffers = mem->next;
-    pthread_mutex_unlock(&mem->ctx->buffer_lock);
-    cl_context_delete(mem->ctx);
+      pthread_mutex_unlock(&mem->ctx->buffer_lock);
+      cl_context_delete(mem->ctx);
+    }
   } else {
     assert((mem->prev == 0) && (mem->next == 0));
   }
-- 
2.5.0



More information about the Beignet mailing list