[Beignet] [PATCH v2 1/3] cl/runtime: fixup 1D array image region and origins.
Zhigang Gong
zhigang.gong at intel.com
Thu Jun 19 00:36:35 PDT 2014
As we treat 1D array image as a 2d array image with height 1
internally, we need to fixup region and origins passed in
from external APIs.
Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
src/cl_api.c | 39 ++++++++++++++++++++++++++-------------
src/cl_utils.h | 29 +++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 13 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index 327f02b..b17cc52 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -2046,8 +2046,8 @@ cl_int
clEnqueueReadImage(cl_command_queue command_queue,
cl_mem mem,
cl_bool blocking_read,
- const size_t * origin,
- const size_t * region,
+ const size_t * porigin,
+ const size_t * pregion,
size_t row_pitch,
size_t slice_pitch,
void * ptr,
@@ -2060,6 +2060,8 @@ clEnqueueReadImage(cl_command_queue command_queue,
CHECK_QUEUE(command_queue);
CHECK_IMAGE(mem, image);
+ FIXUP_IMAGE_REGION(image, pregion, region);
+ FIXUP_IMAGE_ORIGIN(image, porigin, origin);
if (command_queue->ctx != mem->ctx) {
err = CL_INVALID_CONTEXT;
goto error;
@@ -2125,8 +2127,8 @@ cl_int
clEnqueueWriteImage(cl_command_queue command_queue,
cl_mem mem,
cl_bool blocking_write,
- const size_t * origin,
- const size_t * region,
+ const size_t * porigin,
+ const size_t * pregion,
size_t row_pitch,
size_t slice_pitch,
const void * ptr,
@@ -2139,6 +2141,8 @@ clEnqueueWriteImage(cl_command_queue command_queue,
CHECK_QUEUE(command_queue);
CHECK_IMAGE(mem, image);
+ FIXUP_IMAGE_REGION(image, pregion, region);
+ FIXUP_IMAGE_ORIGIN(image, porigin, origin);
if (command_queue->ctx != mem->ctx) {
err = CL_INVALID_CONTEXT;
goto error;
@@ -2204,9 +2208,9 @@ cl_int
clEnqueueCopyImage(cl_command_queue command_queue,
cl_mem src_mem,
cl_mem dst_mem,
- const size_t * src_origin,
- const size_t * dst_origin,
- const size_t * region,
+ const size_t * psrc_origin,
+ const size_t * pdst_origin,
+ const size_t * pregion,
cl_uint num_events_in_wait_list,
const cl_event * event_wait_list,
cl_event * event)
@@ -2219,6 +2223,9 @@ clEnqueueCopyImage(cl_command_queue command_queue,
CHECK_QUEUE(command_queue);
CHECK_IMAGE(src_mem, src_image);
CHECK_IMAGE(dst_mem, dst_image);
+ FIXUP_IMAGE_REGION(src_image, pregion, region);
+ FIXUP_IMAGE_ORIGIN(src_image, psrc_origin, src_origin);
+ FIXUP_IMAGE_ORIGIN(dst_image, pdst_origin, dst_origin);
if (command_queue->ctx != src_mem->ctx ||
command_queue->ctx != dst_mem->ctx) {
err = CL_INVALID_CONTEXT;
@@ -2288,8 +2295,8 @@ cl_int
clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
cl_mem src_mem,
cl_mem dst_buffer,
- const size_t * src_origin,
- const size_t * region,
+ const size_t * psrc_origin,
+ const size_t * pregion,
size_t dst_offset,
cl_uint num_events_in_wait_list,
const cl_event * event_wait_list,
@@ -2301,6 +2308,8 @@ clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
CHECK_QUEUE(command_queue);
CHECK_IMAGE(src_mem, src_image);
CHECK_MEM(dst_buffer);
+ FIXUP_IMAGE_REGION(src_image, pregion, region);
+ FIXUP_IMAGE_ORIGIN(src_image, psrc_origin, src_origin);
if (command_queue->ctx != src_mem->ctx ||
command_queue->ctx != dst_buffer->ctx) {
err = CL_INVALID_CONTEXT;
@@ -2353,8 +2362,8 @@ clEnqueueCopyBufferToImage(cl_command_queue command_queue,
cl_mem src_buffer,
cl_mem dst_mem,
size_t src_offset,
- const size_t * dst_origin,
- const size_t * region,
+ const size_t * pdst_origin,
+ const size_t * pregion,
cl_uint num_events_in_wait_list,
const cl_event * event_wait_list,
cl_event * event)
@@ -2365,6 +2374,8 @@ clEnqueueCopyBufferToImage(cl_command_queue command_queue,
CHECK_QUEUE(command_queue);
CHECK_MEM(src_buffer);
CHECK_IMAGE(dst_mem, dst_image);
+ FIXUP_IMAGE_REGION(dst_image, pregion, region);
+ FIXUP_IMAGE_ORIGIN(dst_image, pdst_origin, dst_origin);
if (command_queue->ctx != src_buffer->ctx ||
command_queue->ctx != dst_mem->ctx) {
err = CL_INVALID_CONTEXT;
@@ -2556,8 +2567,8 @@ clEnqueueMapImage(cl_command_queue command_queue,
cl_mem mem,
cl_bool blocking_map,
cl_map_flags map_flags,
- const size_t * origin,
- const size_t * region,
+ const size_t * porigin,
+ const size_t * pregion,
size_t * image_row_pitch,
size_t * image_slice_pitch,
cl_uint num_events_in_wait_list,
@@ -2572,6 +2583,8 @@ clEnqueueMapImage(cl_command_queue command_queue,
CHECK_QUEUE(command_queue);
CHECK_IMAGE(mem, image);
+ FIXUP_IMAGE_REGION(image, pregion, region);
+ FIXUP_IMAGE_ORIGIN(image, porigin, origin);
if (command_queue->ctx != mem->ctx) {
err = CL_INVALID_CONTEXT;
goto error;
diff --git a/src/cl_utils.h b/src/cl_utils.h
index fa900a7..26cf329 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -149,6 +149,35 @@ do { \
struct _cl_mem_image *IMAGE; \
IMAGE = cl_mem_image(MEM); \
+#define FIXUP_IMAGE_REGION(IMAGE, PREGION, REGION) \
+const size_t *REGION; \
+size_t REGION ##_REC[3]; \
+do { \
+ if (IMAGE->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) { \
+ REGION ##_REC[0] = PREGION[0]; \
+ REGION ##_REC[1] = 1; \
+ REGION ##_REC[2] = PREGION[1]; \
+ REGION = REGION ##_REC; \
+ } else { \
+ REGION = PREGION; \
+ } \
+} while(0)
+
+#define FIXUP_IMAGE_ORIGIN(IMAGE, PREGION, REGION) \
+const size_t *REGION; \
+size_t REGION ##_REC[3]; \
+do { \
+ if (IMAGE->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY) { \
+ REGION ##_REC[0] = PREGION[0]; \
+ REGION ##_REC[1] = 0; \
+ REGION ##_REC[2] = PREGION[1]; \
+ REGION = REGION ##_REC; \
+ } else { \
+ REGION = PREGION; \
+ } \
+} while(0)
+
+
#define CHECK_EVENT(EVENT) \
do { \
if (UNLIKELY(EVENT == NULL)) { \
--
1.8.3.2
More information about the Beignet
mailing list