[Beignet] [PATCH v2 2/2] Fix bug of size of tmp_ker_buf for TILE_Y copying of large image.
yan.wang at linux.intel.com
yan.wang at linux.intel.com
Sat May 27 05:36:08 UTC 2017
From: Yan Wang <yan.wang at linux.intel.com>
1. The size should be calculated based region and bpp of image instead
of the whole image size.
2. When use blocking mode, the copying kernel need be finished.
Otherwise, it will cause allocations of conformance test failed.
Signed-off-by: Yan Wang <yan.wang at linux.intel.com>
---
src/cl_api_mem.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/src/cl_api_mem.c b/src/cl_api_mem.c
index 7b58236..96f3272 100644
--- a/src/cl_api_mem.c
+++ b/src/cl_api_mem.c
@@ -371,6 +371,10 @@ clEnqueueUnmapMemObjectForKernel(cl_command_queue command_queue,
return err;
}
+ err = clFinish(command_queue);
+ if (err != CL_SUCCESS)
+ return err;
+
err = clEnqueueUnmapMemObject(command_queue, image->tmp_ker_buf, mapped_ptr,
num_events_in_wait_list, event_wait_list, event);
@@ -1537,12 +1541,13 @@ clEnqueueMapImageByKernel(cl_command_queue command_queue,
if (image->tmp_ker_buf)
clReleaseMemObject(image->tmp_ker_buf);
+ size_t buf_size = region[0] * region[1] * region[2] * image->bpp;
if(mem->flags & CL_MEM_USE_HOST_PTR)
image->tmp_ker_buf =
- clCreateBuffer(command_queue->ctx, CL_MEM_USE_HOST_PTR, mem->size, mem->host_ptr, &err);
+ clCreateBuffer(command_queue->ctx, CL_MEM_USE_HOST_PTR, buf_size, mem->host_ptr, &err);
else
image->tmp_ker_buf =
- clCreateBuffer(command_queue->ctx, CL_MEM_ALLOC_HOST_PTR, mem->size, NULL, &err);
+ clCreateBuffer(command_queue->ctx, CL_MEM_ALLOC_HOST_PTR, buf_size, NULL, &err);
if (image->tmp_ker_buf == NULL || err != CL_SUCCESS) {
image->tmp_ker_buf = NULL;
*errcode_ret = err;
@@ -1559,7 +1564,7 @@ clEnqueueMapImageByKernel(cl_command_queue command_queue,
}
return clEnqueueMapBuffer(command_queue, image->tmp_ker_buf, blocking_map, map_flags, 0,
- mem->size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
+ buf_size, num_events_in_wait_list, event_wait_list, event, errcode_ret);
}
void *
@@ -1778,8 +1783,9 @@ clEnqueueReadImageByKernel(cl_command_queue command_queue,
if (image->tmp_ker_buf)
clReleaseMemObject(image->tmp_ker_buf);
+ size_t buf_size = region[0] * region[1] * region[2] * image->bpp;
image->tmp_ker_buf = clCreateBuffer(command_queue->ctx, CL_MEM_ALLOC_HOST_PTR,
- mem->size, NULL, &err);
+ buf_size, NULL, &err);
if (image->tmp_ker_buf == NULL || err != CL_SUCCESS) {
image->tmp_ker_buf = NULL;
return err;
@@ -1794,7 +1800,7 @@ clEnqueueReadImageByKernel(cl_command_queue command_queue,
}
return clEnqueueReadBuffer(command_queue, image->tmp_ker_buf, blocking_read, 0,
- mem->size, ptr, num_events_in_wait_list, event_wait_list, event);
+ buf_size, ptr, num_events_in_wait_list, event_wait_list, event);
}
cl_int
@@ -1985,14 +1991,20 @@ clEnqueueWriteImageByKernel(cl_command_queue command_queue,
if (image->tmp_ker_buf)
clReleaseMemObject(image->tmp_ker_buf);
- image->tmp_ker_buf = clCreateBuffer(command_queue->ctx, CL_MEM_USE_HOST_PTR, mem->size, (void*)ptr, &err);
+ size_t buf_size = region[0] * region[1] * region[2] * image->bpp;
+ image->tmp_ker_buf = clCreateBuffer(command_queue->ctx, CL_MEM_USE_HOST_PTR, buf_size, (void*)ptr, &err);
if (image->tmp_ker_buf == NULL || err != CL_SUCCESS) {
image->tmp_ker_buf = NULL;
return err;
}
- return clEnqueueCopyBufferToImage(command_queue, image->tmp_ker_buf, mem, 0, origin, region,
+ err = clEnqueueCopyBufferToImage(command_queue, image->tmp_ker_buf, mem, 0, origin, region,
num_events_in_wait_list, event_wait_list, event);
+
+ if (blocking_write)
+ err = clFinish(command_queue);
+
+ return err;
}
cl_int
--
2.7.4
More information about the Beignet
mailing list