[Beignet] [PATCH] Unmap the cl_mem in driver when application map a cl_mem and release without unmap.

Yang Rong rong.r.yang at intel.com
Wed Sep 18 02:09:29 PDT 2013


Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
 src/cl_mem.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/cl_mem.c b/src/cl_mem.c
index d901f9f..769e1cb 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -536,6 +536,7 @@ cl_mem_new_image(cl_context context,
 LOCAL void
 cl_mem_delete(cl_mem mem)
 {
+  cl_int i;
   if (UNLIKELY(mem == NULL))
     return;
   if (atomic_dec(&mem->ref_n) > 1)
@@ -560,8 +561,17 @@ cl_mem_delete(cl_mem mem)
   pthread_mutex_unlock(&mem->ctx->buffer_lock);
   cl_context_delete(mem->ctx);
 
-  /* Someone still mapped? */
-  assert(!mem->map_ref);
+  /* Someone still mapped, unmap */
+  if(mem->map_ref > 0) {
+    assert(mem->mapped_ptr);
+    for(i=0; i<mem->mapped_ptr_sz; i++) {
+      if(mem->mapped_ptr[i].ptr != NULL) {
+        mem->map_ref--;
+        cl_mem_unmap_gtt(mem);
+      }
+    }
+    assert(mem->map_ref == 0);
+  }
 
   if (mem->mapped_ptr)
     free(mem->mapped_ptr);
-- 
1.8.1.2



More information about the Beignet mailing list