Unmap the cl_mem in driver when application map a cl_mem and release without unmap.
authorYang Rong <rong.r.yang@intel.com>
Wed, 18 Sep 2013 09:09:29 +0000 (17:09 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Wed, 18 Sep 2013 08:37:14 +0000 (16:37 +0800)
Signed-off-by: Yang Rong <rong.r.yang@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
src/cl_mem.c

index d901f9f..769e1cb 100644 (file)
@@ -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);