From: Michal Babej Date: Thu, 25 Nov 2021 13:49:47 +0000 (+0200) Subject: [PATCH 43/90] MapBuffer/MapImage: allocate the cl_mem backing buffer if required X-Git-Tag: archive/raspbian/1.8-3+rpi1^2~78 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f18027f3055e8e5fdf43df3bdd115feff2fc1091;p=pocl.git [PATCH 43/90] MapBuffer/MapImage: allocate the cl_mem backing buffer if required Gbp-Pq: Name 0043-MapBuffer-MapImage-allocate-the-cl_mem-backing-buffe.patch --- diff --git a/lib/CL/clEnqueueMapBuffer.c b/lib/CL/clEnqueueMapBuffer.c index f342177..b277dd9 100644 --- a/lib/CL/clEnqueueMapBuffer.c +++ b/lib/CL/clEnqueueMapBuffer.c @@ -104,7 +104,17 @@ POname(clEnqueueMapBuffer)(cl_command_queue command_queue, mapping_info->offset = offset; mapping_info->size = size; - errcode = device->ops->get_mapping_ptr (device->data, mem_id, buffer, + /* because cl_mems are per-context, PoCL delays allocation of + * cl_mem backing memory until it knows which device will need it, + * so the cl_mem might not yet be allocated on this device. However, + * some drivers can avoid unnecessary host memory usage if we + * allocate it now. We can assume it will be used on this device. */ + pocl_mem_identifier *p = &buffer->device_ptrs[device->global_mem_id]; + if (p->mem_ptr == NULL) + errcode = device->ops->alloc_mem_obj (device, buffer, NULL); + + if (errcode == CL_SUCCESS) + errcode = device->ops->get_mapping_ptr (device->data, mem_id, buffer, mapping_info); DL_APPEND (buffer->mappings, mapping_info); ++buffer->map_count; diff --git a/lib/CL/clEnqueueMapImage.c b/lib/CL/clEnqueueMapImage.c index ea71b85..c1f78c9 100644 --- a/lib/CL/clEnqueueMapImage.c +++ b/lib/CL/clEnqueueMapImage.c @@ -152,8 +152,18 @@ CL_API_SUFFIX__VERSION_1_0 assert (start_offset <= end_offset); mapping_info->size = end_offset + 1 - start_offset; - errcode = device->ops->get_mapping_ptr (device->data, mem_id, image, - mapping_info); + /* because cl_mems are per-context, PoCL delays allocation of + * cl_mem backing memory until it knows which device will need it, + * so the cl_mem might not yet be allocated on this device. However, + * some drivers can avoid unnecessary host memory usage if we + * allocate it now. We can assume it will be used on this device. */ + pocl_mem_identifier *p = &image->device_ptrs[device->global_mem_id]; + if (p->mem_ptr == NULL) + errcode = device->ops->alloc_mem_obj (device, image, NULL); + + if (errcode == CL_SUCCESS) + errcode = device->ops->get_mapping_ptr (device->data, mem_id, image, + mapping_info); DL_APPEND (image->mappings, mapping_info); ++image->map_count; POCL_UNLOCK_OBJ (image);