From 68c31b20e54a435975a9008ab93e760bc5cd193c Mon Sep 17 00:00:00 2001 From: Yan Wang Date: Tue, 16 May 2017 19:04:04 +0800 Subject: Implement TILE_Y large image in clEnqueueReadImage. It will fail to copy data from TILE_Y large image to buffer by memcpy. Use clEnqueueCopyImageToBuffer to do this on GPU side. Signed-off-by: Yan Wang Reviewed-by: Yang Rong --- src/cl_api_mem.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/cl_api_mem.c b/src/cl_api_mem.c index 8678bd9c..91525b16 100644 --- a/src/cl_api_mem.c +++ b/src/cl_api_mem.c @@ -1747,6 +1747,56 @@ clEnqueueMapImage(cl_command_queue command_queue, return mem_ptr; } +static cl_int +clEnqueueReadImageByKernel(cl_command_queue command_queue, + cl_mem mem, + cl_bool blocking_read, + const size_t *porigin, + const size_t *pregion, + size_t row_pitch, + size_t slice_pitch, + void *ptr, + cl_uint num_events_in_wait_list, + const cl_event *event_wait_list, + cl_event *event) +{ + cl_int err = CL_SUCCESS; + struct _cl_mem_image *image = NULL; + size_t region[3]; + size_t origin[3]; + + image = cl_mem_image(mem); + + err = check_image_region(image, pregion, region); + if (err != CL_SUCCESS) + return err; + + err = check_image_origin(image, porigin, origin); + if (err != CL_SUCCESS) + return err; + + if (image->tmp_ker_buf) + clReleaseMemObject(image->tmp_ker_buf); + + image->tmp_ker_buf = clCreateBuffer(command_queue->ctx, CL_MEM_ALLOC_HOST_PTR, + mem->size, NULL, &err); + if (image->tmp_ker_buf == NULL || err != CL_SUCCESS) { + image->tmp_ker_buf = NULL; + return err; + } + + err = clEnqueueCopyImageToBuffer(command_queue, mem, image->tmp_ker_buf, origin, + region, 0, 0, NULL, NULL); + if (err != CL_SUCCESS) { + clReleaseMemObject(image->tmp_ker_buf); + image->tmp_ker_buf = NULL; + return err; + } + + return clEnqueueReadBuffer(command_queue, image->tmp_ker_buf, blocking_read, 0, + mem->size, ptr, num_events_in_wait_list, event_wait_list, event); +} + cl_int clEnqueueReadImage(cl_command_queue command_queue, cl_mem mem, @@ -1832,6 +1882,11 @@ clEnqueueReadImage(cl_command_queue command_queue, break; } + if (image->is_ker_copy) { + return clEnqueueReadImageByKernel(command_queue, mem, blocking_read, origin, + region, row_pitch, slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event); + } + err = cl_event_check_waitlist(num_events_in_wait_list, event_wait_list, event, command_queue->ctx); if (err != CL_SUCCESS) { -- cgit v1.2.3