[Beignet] [PATCH v3 7/7] Optimize clEnqueueWriteImageByKernel and clEnqueuReadImageByKernel.
yan.wang at linux.intel.com
yan.wang at linux.intel.com
Wed Jun 7 07:55:56 UTC 2017
From: Yan Wang <yan.wang at linux.intel.com>
1. Only copy the data by origin and region defined.
2. Add clFinish to guarantee the kernel copying is finished when blocking writing.
Signed-off-by: Yan Wang <yan.wang at linux.intel.com>
---
src/cl_api_mem.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/cl_api_mem.c b/src/cl_api_mem.c
index a450e19..46672b7 100644
--- a/src/cl_api_mem.c
+++ b/src/cl_api_mem.c
@@ -1843,8 +1843,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;
@@ -1859,7 +1860,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
@@ -2050,14 +2051,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