diff options
author | Zhigang Gong <zhigang.gong@intel.com> | 2014-06-18 14:53:06 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2014-06-20 15:53:25 +0800 |
commit | 5745447ce9b56504aeb95e2bf03b93c4d3a9d5dc (patch) | |
tree | c0caabaa376551be18d79aeac87cd17396dd2e70 | |
parent | 74252fdc7b3e211bcbe22e4411f313e978f25def (diff) |
cl/runtime: fixup 1D array image region and origins.
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@intel.com>
Reviewed-by: He Junyan <junyan.he@inbox.com>
-rw-r--r-- | src/cl_api.c | 39 | ||||
-rw-r--r-- | 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 c4a8730a..3b118a88 100644 --- a/src/cl_api.c +++ b/src/cl_api.c @@ -2065,8 +2065,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, @@ -2079,6 +2079,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; @@ -2144,8 +2146,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, @@ -2158,6 +2160,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; @@ -2223,9 +2227,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) @@ -2238,6 +2242,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; @@ -2307,8 +2314,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, @@ -2320,6 +2327,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; @@ -2372,8 +2381,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) @@ -2384,6 +2393,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; @@ -2575,8 +2586,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, @@ -2591,6 +2602,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 fa900a76..26cf329e 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)) { \ |