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

Zhigang Gong zhigang.gong at linux.intel.com
Wed Sep 18 01:38:46 PDT 2013


LGTM, pushed, thanks.

On Wed, Sep 18, 2013 at 05:09:29PM +0800, Yang Rong wrote:
> 
> 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
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list