[Beignet] [PATCH 2/2] Fix bug of clEnqueueCopyBufferToImage and clEnqueueCopyImageToBuffer.
Yang, Rong R
rong.r.yang at intel.com
Thu May 25 05:58:08 UTC 2017
Can you write a function to decide the alignment? Then it could be reused by cl_mem_copy_buffer_to_image and cl_mem_copy_image_to_buffer.
> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> yan.wang at linux.intel.com
> Sent: Thursday, May 25, 2017 10:57
> To: beignet at lists.freedesktop.org
> Cc: Yan Wang <yan.wang at linux.intel.com>
> Subject: [Beignet] [PATCH 2/2] Fix bug of clEnqueueCopyBufferToImage and
> clEnqueueCopyImageToBuffer.
>
> From: Yan Wang <yan.wang at linux.intel.com>
>
> "imagedim_non_pow_2" cases of basic modudle of confrmance shows
> regression after use TILE_Y mode for large image by previous patch.
> This bug comes from the non-align16 kernel of
> clEnqueueCopyBufferToImage and clEnqueueCopyImageToBuffer.
> It will force CL_RGBA/CL_UNORM_INT8/8191x8192 image of conformance
> test to CL_R/CL_UNSIGNED_INT8/32764x8192 image for copying.
> So it makes width as 8191 x 4 = 32764 and its width will exceed the maximum
> width (16 x 1024 = 16384) of GEN surface state structure which only has 14
> bits.
> So use align4 copy kernel to avoid this bug.
>
> Signed-off-by: Yan Wang <yan.wang at linux.intel.com>
> ---
> src/CMakeLists.txt | 1 +
> src/cl_context.h | 2 ++
> src/cl_mem.c | 32 ++++++++++++++++++++++
> .../cl_internal_copy_buffer_to_image_2d_align4.cl | 18
> ++++++++++++ .../cl_internal_copy_image_2d_to_buffer_align4.cl | 18
> ++++++++++++
> 5 files changed, 71 insertions(+)
> create mode 100644
> src/kernels/cl_internal_copy_buffer_to_image_2d_align4.cl
> create mode 100644
> src/kernels/cl_internal_copy_image_2d_to_buffer_align4.cl
>
> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77a1c87..6433566
> 100644
> --- a/src/CMakeLists.txt
> +++ b/src/CMakeLists.txt
> @@ -53,6 +53,7 @@ cl_internal_copy_image_2d_array_to_2d_array
> cl_internal_copy_image_2d_array_to_2
> cl_internal_copy_image_2d_array_to_3d
> cl_internal_copy_image_3d_to_2d_array
> cl_internal_copy_image_2d_to_buffer
> cl_internal_copy_image_2d_to_buffer_align16
> cl_internal_copy_image_3d_to_buffer
> cl_internal_copy_buffer_to_image_2d
> cl_internal_copy_buffer_to_image_2d_align16
> cl_internal_copy_buffer_to_image_3d
> +cl_internal_copy_buffer_to_image_2d_align4
> +cl_internal_copy_image_2d_to_buffer_align4
> cl_internal_fill_buf_align8 cl_internal_fill_buf_align4
> cl_internal_fill_buf_align2 cl_internal_fill_buf_unalign
> cl_internal_fill_buf_align128 cl_internal_fill_image_1d diff --git
> a/src/cl_context.h b/src/cl_context.h index 8ba499f..75bf895 100644
> --- a/src/cl_context.h
> +++ b/src/cl_context.h
> @@ -62,9 +62,11 @@ enum _cl_internal_ker_type {
> CL_ENQUEUE_COPY_IMAGE_3D_TO_2D_ARRAY, //copy image 3d to
> image 2d array
> CL_ENQUEUE_COPY_IMAGE_2D_TO_BUFFER, //copy image 2d to buffer
> CL_ENQUEUE_COPY_IMAGE_2D_TO_BUFFER_ALIGN16,
> + CL_ENQUEUE_COPY_IMAGE_2D_TO_BUFFER_ALIGN4,
> CL_ENQUEUE_COPY_IMAGE_3D_TO_BUFFER, //copy image 3d tobuffer
> CL_ENQUEUE_COPY_BUFFER_TO_IMAGE_2D, //copy buffer to image 2d
> CL_ENQUEUE_COPY_BUFFER_TO_IMAGE_2D_ALIGN16,
> + CL_ENQUEUE_COPY_BUFFER_TO_IMAGE_2D_ALIGN4,
> CL_ENQUEUE_COPY_BUFFER_TO_IMAGE_3D, //copy buffer to image 3d
> CL_ENQUEUE_FILL_BUFFER_UNALIGN, //fill buffer with 1 aligne pattern,
> pattern size=1
> CL_ENQUEUE_FILL_BUFFER_ALIGN2, //fill buffer with 2 aligne pattern,
> pattern size=2
> diff --git a/src/cl_mem.c b/src/cl_mem.c index 0c49c3d..3b9a3be 100644
> --- a/src/cl_mem.c
> +++ b/src/cl_mem.c
> @@ -2159,6 +2159,7 @@
> cl_mem_copy_image_to_buffer(cl_command_queue queue, cl_event
> event, struct _cl_m
> size_t origin0, region0;
> size_t kn_dst_offset;
> int align16 = 0;
> + int align4 = 0;
> size_t align_size = 1;
> size_t w_saved;
>
> @@ -2183,6 +2184,13 @@
> cl_mem_copy_image_to_buffer(cl_command_queue queue, cl_event
> event, struct _cl_m
> align16 = 1;
> align_size = 16;
> }
> + else if((image->image_type == CL_MEM_OBJECT_IMAGE2D) && ((image-
> >w * image->bpp) % 4 == 0) &&
> + ((src_origin[0] * bpp) % 4 == 0) && (region0 % 4 == 0) && (dst_offset % 4
> == 0)){
> + fmt.image_channel_order = CL_R;
> + fmt.image_channel_data_type = CL_UNSIGNED_INT32;
> + align4 = 1;
> + align_size = 4;
> + }
> else{
> fmt.image_channel_order = CL_R;
> fmt.image_channel_data_type = CL_UNSIGNED_INT8; @@ -2206,6
> +2214,14 @@ cl_mem_copy_image_to_buffer(cl_command_queue queue,
> cl_event event, struct _cl_m
> cl_internal_copy_image_2d_to_buffer_align16_str,
> (size_t)cl_internal_copy_image_2d_to_buffer_align16_str_size,
> NULL);
> }
> + else if(align4){
> + extern char cl_internal_copy_image_2d_to_buffer_align4_str[];
> + extern size_t
> + cl_internal_copy_image_2d_to_buffer_align4_str_size;
> +
> + ker = cl_context_get_static_kernel_from_bin(queue->ctx,
> CL_ENQUEUE_COPY_IMAGE_2D_TO_BUFFER_ALIGN4,
> + cl_internal_copy_image_2d_to_buffer_align4_str,
> + (size_t)cl_internal_copy_image_2d_to_buffer_align4_str_size,
> NULL);
> + }
> else{
> extern char cl_internal_copy_image_2d_to_buffer_str[];
> extern size_t cl_internal_copy_image_2d_to_buffer_str_size;
> @@ -2263,6 +2279,7 @@
> cl_mem_copy_buffer_to_image(cl_command_queue queue, cl_event
> event, cl_mem buffe
> size_t origin0, region0;
> size_t kn_src_offset;
> int align16 = 0;
> + int align4 = 0;
> size_t align_size = 1;
> size_t w_saved = 0;
>
> @@ -2287,6 +2304,13 @@
> cl_mem_copy_buffer_to_image(cl_command_queue queue, cl_event
> event, cl_mem buffe
> align16 = 1;
> align_size = 16;
> }
> + else if((image->image_type == CL_MEM_OBJECT_IMAGE2D) && ((image-
> >w * image->bpp) % 4 == 0) &&
> + ((dst_origin[0] * bpp) % 4 == 0) && (region0 % 4 == 0) && (src_offset % 4
> == 0)){
> + fmt.image_channel_order = CL_R;
> + fmt.image_channel_data_type = CL_UNSIGNED_INT32;
> + align4 = 1;
> + align_size = 4;
> + }
> else{
> fmt.image_channel_order = CL_R;
> fmt.image_channel_data_type = CL_UNSIGNED_INT8; @@ -2310,6
> +2334,14 @@ cl_mem_copy_buffer_to_image(cl_command_queue queue,
> cl_event event, cl_mem buffe
> cl_internal_copy_buffer_to_image_2d_align16_str,
> (size_t)cl_internal_copy_buffer_to_image_2d_align16_str_size,
> NULL);
> }
> + else if(align4){
> + extern char cl_internal_copy_buffer_to_image_2d_align4_str[];
> + extern size_t
> + cl_internal_copy_buffer_to_image_2d_align4_str_size;
> +
> + ker = cl_context_get_static_kernel_from_bin(queue->ctx,
> CL_ENQUEUE_COPY_BUFFER_TO_IMAGE_2D_ALIGN4,
> + cl_internal_copy_buffer_to_image_2d_align4_str,
> + (size_t)cl_internal_copy_buffer_to_image_2d_align4_str_size,
> NULL);
> + }
> else{
> extern char cl_internal_copy_buffer_to_image_2d_str[];
> extern size_t cl_internal_copy_buffer_to_image_2d_str_size;
> diff --git a/src/kernels/cl_internal_copy_buffer_to_image_2d_align4.cl
> b/src/kernels/cl_internal_copy_buffer_to_image_2d_align4.cl
> new file mode 100644
> index 0000000..79a3d8c
> --- /dev/null
> +++ b/src/kernels/cl_internal_copy_buffer_to_image_2d_align4.cl
> @@ -0,0 +1,18 @@
> +kernel void __cl_copy_buffer_to_image_2d_align4(__write_only
> image2d_t image, global uint* buffer,
> + unsigned int region0, unsigned int region1, unsigned int
> region2,
> + unsigned int dst_origin0, unsigned int dst_origin1,
> unsigned int dst_origin2,
> + unsigned int src_offset) {
> + int i = get_global_id(0);
> + int j = get_global_id(1);
> + uint4 color = (uint4)(0);
> + int2 dst_coord;
> + if((i >= region0) || (j>= region1))
> + return;
> + dst_coord.x = dst_origin0 + i;
> + dst_coord.y = dst_origin1 + j;
> + src_offset += j * region0 + i;
> + color.x = buffer[src_offset];
> + write_imageui(image, dst_coord, color.x); }
> +
> diff --git a/src/kernels/cl_internal_copy_image_2d_to_buffer_align4.cl
> b/src/kernels/cl_internal_copy_image_2d_to_buffer_align4.cl
> new file mode 100644
> index 0000000..dc76e02
> --- /dev/null
> +++ b/src/kernels/cl_internal_copy_image_2d_to_buffer_align4.cl
> @@ -0,0 +1,18 @@
> +kernel void __cl_copy_image_2d_to_buffer_align4( __read_only
> image2d_t image, global uint* buffer,
> + unsigned int region0, unsigned int region1, unsigned int
> region2,
> + unsigned int src_origin0, unsigned int src_origin1,
> unsigned int src_origin2,
> + unsigned int dst_offset) {
> +
> + int i = get_global_id(0);
> + int j = get_global_id(1);
> + if((i >= region0) || (j>= region1))
> + return;
> + uint4 color;
> + const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE |
> +CLK_ADDRESS_NONE | CLK_FILTER_NEAREST;
> + int2 src_coord;
> + src_coord.x = src_origin0 + i;
> + src_coord.y = src_origin1 + j;
> + color = read_imageui(image, sampler, src_coord);
> + *(buffer + dst_offset + region0*j + i) = color.x; }
> --
> 2.7.4
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list