From 7292362dce62b3f39d6c35e9601b5c12ab770a3f Mon Sep 17 00:00:00 2001 From: Sheri Zhang Date: Tue, 27 Oct 2020 10:19:41 +0000 Subject: COMPMID-3737: Remove OpenCL padding: CLWidthConcatenate2TensorsKernel Remove padding from CLWidthConcatenate2TensorsKernel Remove padding from CLWidthConcatenate4TensorsKernel Change-Id: I2142618e87bf11f831fe3b9375c4a7efda8d3a21 Signed-off-by: Sheri Zhang Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4266 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio --- src/core/CL/cl_kernels/concatenate.cl | 103 ++++++++++----------- .../kernels/CLWidthConcatenate2TensorsKernel.cpp | 45 +++------ .../kernels/CLWidthConcatenate4TensorsKernel.cpp | 75 +++------------ 3 files changed, 75 insertions(+), 148 deletions(-) diff --git a/src/core/CL/cl_kernels/concatenate.cl b/src/core/CL/cl_kernels/concatenate.cl index 7c6c8d211a..19494b109f 100644 --- a/src/core/CL/cl_kernels/concatenate.cl +++ b/src/core/CL/cl_kernels/concatenate.cl @@ -53,7 +53,9 @@ inline VEC_QUANT requantize(VEC_QUANT input, float in_offset, float out_offset, #error "Element size not supported" #endif // ELEMENT_SIZE -#if VEC_SIZE == 2 +#if VEC_SIZE == 1 +#define SEQ ((int)(0)) +#elif VEC_SIZE == 2 #define SEQ ((int2)(0, 1)) #elif VEC_SIZE == 4 #define SEQ ((int4)(0, 1, 2, 3)) @@ -69,7 +71,7 @@ inline VEC_QUANT requantize(VEC_QUANT input, float in_offset, float out_offset, * * @note The data type has to be passed at compile time using -DDATA_TYPE. i.e. -DDATA_TYPE=float * @note Vector size has to be passed at compile time using -DVEC_SIZE. i.e. -DVEC_SIZE=16 - * @note The offset for the first spatial dimension has to be passed at compile time using -DWIDTH_OFFSET. i.e. -DWIDTH_OFFSET=128 + * @note Leftover vector size has to be passed at compile time using -DVEC_SIZE_LEFTOVER. e.g. -DVEC_SIZE_LEFTOVER=3. It is defined as the remainder between the input's first dimension and VEC_SIZE * @note Tensor depth should be given as a preprocessor argument using -DDEPTH=size. e.g. -DDEPTH=16 * @note First input tensor width should be given as a preprocessor argument using -DINPUT1_WIDTH=width. e.g. -DINPUT1_WIDTH=8 * @@ -103,34 +105,29 @@ inline VEC_QUANT requantize(VEC_QUANT input, float in_offset, float out_offset, * @param[in] dst_stride_w Stride of the destination tensor in Z dimension (in bytes) * @param[in] dst_step_w output_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor - * @param[in] src1_pad_right Right paddings of the first input tensor in unit of elements - * @param[in] src1_pad_left Left paddings of the second input tensor in unit of elements */ __kernel void concatenate_width_x2( TENSOR4D_DECLARATION(src1), TENSOR4D_DECLARATION(src2), - TENSOR4D_DECLARATION(dst), - uint src1_pad_right, - uint src2_pad_left) + TENSOR4D_DECLARATION(dst)) { - Tensor4D dst = CONVERT_TO_TENSOR4D_STRUCT(dst, DEPTH); - // Calculate input indices - const int x = get_global_id(0) * (int)VEC_SIZE; + const int x = max((int)(get_global_id(0) * VEC_SIZE - (VEC_SIZE - VEC_SIZE_LEFTOVER) % VEC_SIZE), 0); const int y = get_global_id(1); const int z = get_global_id(2) % (int)DEPTH; const int w = get_global_id(2) / (int)DEPTH; - const int x1 = min(x, (int)INPUT1_WIDTH + (int)src1_pad_right - (int)VEC_SIZE); - const int x2 = max(x - (int)INPUT1_WIDTH, -(int)src2_pad_left); + const int x1 = min(x, (int)INPUT1_WIDTH - (int)VEC_SIZE); + const int x2 = max(x - (int)INPUT1_WIDTH, 0); // Calculate inputs and output addresses - const __global uchar *in1_ptr = src1_ptr + (int)src1_offset_first_element_in_bytes + x1 * (int)src1_stride_x + y * (int)src1_stride_y + z * (int)src1_stride_z + w * (int)src1_stride_w; - const __global uchar *in2_ptr = src2_ptr + (int)src2_offset_first_element_in_bytes + x2 * (int)src2_stride_x + y * (int)src2_stride_y + z * (int)src2_stride_z + w * (int)src2_stride_w; + const __global uchar *dst_addr = dst_ptr + (int)dst_offset_first_element_in_bytes + x * sizeof(DATA_TYPE) + y * (int)dst_stride_y + z * (int)dst_stride_z + w * (int)dst_stride_w; + const __global uchar *src1_addr = src1_ptr + (int)src1_offset_first_element_in_bytes + x1 * sizeof(DATA_TYPE) + y * (int)src1_stride_y + z * (int)src1_stride_z + w * (int)src1_stride_w; + const __global uchar *src2_addr = src2_ptr + (int)src2_offset_first_element_in_bytes + x2 * sizeof(DATA_TYPE) + y * (int)src2_stride_y + z * (int)src2_stride_z + w * (int)src2_stride_w; VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) - src1_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in1_ptr); + src1_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src1_addr); VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) - src2_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in2_ptr); + src2_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src2_addr); #if defined(OFFSET_IN1) && defined(OFFSET_IN2) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_IN2) && defined(SCALE_OUT) src1_values = requantize(src1_values, OFFSET_IN1, OFFSET_OUT, SCALE_IN1, SCALE_OUT); @@ -138,10 +135,14 @@ __kernel void concatenate_width_x2( #endif /* defined(OFFSET_IN1) && defined(OFFSET_IN2) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_IN2) && defined(SCALE_OUT) */ const VEC_DATA_TYPE(int, VEC_SIZE) x_coords = SEQ + (VEC_DATA_TYPE(int, VEC_SIZE))(x); const VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE) cond = CONVERT(x_coords < (VEC_DATA_TYPE(int, VEC_SIZE))(INPUT1_WIDTH), VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE)); - const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) values = select(src2_values, src1_values, cond); - VSTORE(VEC_SIZE) - (values, 0, (__global DATA_TYPE *)dst.ptr); + // Rotate src1/2_values, if values0 is a combination of src1_values and src2_values. + src1_values = (x < INPUT1_WIDTH && x1 == INPUT1_WIDTH - VEC_SIZE) ? ROTATE(src1_values, VEC_SIZE, INPUT1_ROTATE_N) : src1_values; + src2_values = (x < INPUT1_WIDTH && x1 == INPUT1_WIDTH - VEC_SIZE) ? ROTATE(src2_values, VEC_SIZE, INPUT1_ROTATE_N) : src2_values; + + const VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) values0 = select(src2_values, src1_values, cond); + + STORE_VECTOR_SELECT(values, DATA_TYPE, dst_addr, VEC_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0) } #if defined(INPUT2_WIDTH) && defined(INPUT3_WIDTH) @@ -149,7 +150,7 @@ __kernel void concatenate_width_x2( * * @note The data type has to be passed at compile time using -DDATA_TYPE. i.e. -DDATA_TYPE=float * @note Vector size has to be passed at compile time using -DVEC_SIZE. i.e. -DVEC_SIZE=16 - * @note The offset for the first spatial dimension has to be passed at compile time using -DWIDTH_OFFSET. i.e. -DWIDTH_OFFSET=128 + * @note Leftover vector size has to be passed at compile time using -DVEC_SIZE_LEFTOVER. e.g. -DVEC_SIZE_LEFTOVER=3. It is defined as the remainder between the input's first dimension and VEC_SIZE * @note Tensor depth should be given as a preprocessor argument using -DDEPTH=size. e.g. -DDEPTH=16 * @note First input tensor width should be given as a preprocessor argument using -DINPUT1_WIDTH=width. e.g. -DINPUT1_WIDTH=8 * @note Second input tensor width should be given as a preprocessor argument using -DINPUT2_WIDTH=width. e.g. -DINPUT2_WIDTH=8 @@ -205,53 +206,40 @@ __kernel void concatenate_width_x2( * @param[in] dst_stride_w Stride of the destination tensor in Z dimension (in bytes) * @param[in] dst_step_w output_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor - * @param[in] src1_pad_right Right paddings of the first input tensor in unit of elements - * @param[in] src2_pad_left Left paddings of the second input tensor in unit of elements - * @param[in] src2_pad_right Right paddings of the second input tensor in unit of elements - * @param[in] src3_pad_left Left paddings of the third input tensor in unit of elements - * @param[in] src3_pad_right Right paddings of the third input tensor in unit of elements - * @param[in] src4_pad_left Left paddings of the fourth input tensor in unit of elements */ __kernel void concatenate_width_x4( TENSOR4D_DECLARATION(src1), TENSOR4D_DECLARATION(src2), TENSOR4D_DECLARATION(src3), TENSOR4D_DECLARATION(src4), - TENSOR4D_DECLARATION(dst), - uint src1_pad_right, - uint src2_pad_left, - uint src2_pad_right, - uint src3_pad_left, - uint src3_pad_right, - uint src4_pad_left) + TENSOR4D_DECLARATION(dst)) { - Tensor4D dst = CONVERT_TO_TENSOR4D_STRUCT(dst, DEPTH); - // Calculate input indices - const int x = get_global_id(0) * (int)VEC_SIZE; + const int x = max((int)(get_global_id(0) * VEC_SIZE - (VEC_SIZE - VEC_SIZE_LEFTOVER) % VEC_SIZE), 0); const int y = get_global_id(1); const int z = get_global_id(2) % (int)DEPTH; const int w = get_global_id(2) / (int)DEPTH; - const int x1 = min(x, (int)INPUT1_WIDTH + (int)src1_pad_right - (int)VEC_SIZE); - const int x2 = min(max(x - (int)INPUT1_WIDTH, -(int)src2_pad_left), (int)INPUT2_WIDTH + (int)src2_pad_right - (int)VEC_SIZE); - const int x3 = min(max(x - (int)INPUT1_WIDTH - (int)INPUT2_WIDTH, -(int)src3_pad_left), (int)INPUT3_WIDTH + (int)src3_pad_right - (int)VEC_SIZE); - const int x4 = max(x - (int)INPUT1_WIDTH - (int)INPUT2_WIDTH - (int)INPUT3_WIDTH, -(int)src4_pad_left); + const int x1 = min(x, (int)INPUT1_WIDTH - (int)VEC_SIZE); + const int x2 = min(max(x - (int)INPUT1_WIDTH, 0), (int)INPUT2_WIDTH - (int)VEC_SIZE); + const int x3 = min(max(x - (int)INPUT1_WIDTH - (int)INPUT2_WIDTH, 0), (int)INPUT3_WIDTH - (int)VEC_SIZE); + const int x4 = max(x - (int)INPUT1_WIDTH - (int)INPUT2_WIDTH - (int)INPUT3_WIDTH, 0); // Calculate inputs and output addresses - const __global uchar *in1_ptr = src1_ptr + (int)src1_offset_first_element_in_bytes + x1 * (int)src1_stride_x + y * (int)src1_stride_y + z * (int)src1_stride_z + w * (int)src1_stride_w; - const __global uchar *in2_ptr = src2_ptr + (int)src2_offset_first_element_in_bytes + x2 * (int)src2_stride_x + y * (int)src2_stride_y + z * (int)src2_stride_z + w * (int)src2_stride_w; - const __global uchar *in3_ptr = src3_ptr + (int)src3_offset_first_element_in_bytes + x3 * (int)src3_stride_x + y * (int)src3_stride_y + z * (int)src3_stride_z + w * (int)src3_stride_w; - const __global uchar *in4_ptr = src4_ptr + (int)src4_offset_first_element_in_bytes + x4 * (int)src4_stride_x + y * (int)src4_stride_y + z * (int)src4_stride_z + w * (int)src4_stride_w; + const __global uchar *dst_addr = dst_ptr + (int)dst_offset_first_element_in_bytes + x * sizeof(DATA_TYPE) + y * (int)dst_stride_y + z * (int)dst_stride_z + w * (int)dst_stride_w; + const __global uchar *src1_addr = src1_ptr + (int)src1_offset_first_element_in_bytes + x1 * sizeof(DATA_TYPE) + y * (int)src1_stride_y + z * (int)src1_stride_z + w * (int)src1_stride_w; + const __global uchar *src2_addr = src2_ptr + (int)src2_offset_first_element_in_bytes + x2 * sizeof(DATA_TYPE) + y * (int)src2_stride_y + z * (int)src2_stride_z + w * (int)src2_stride_w; + const __global uchar *src3_addr = src3_ptr + (int)src3_offset_first_element_in_bytes + x3 * sizeof(DATA_TYPE) + y * (int)src3_stride_y + z * (int)src3_stride_z + w * (int)src3_stride_w; + const __global uchar *src4_addr = src4_ptr + (int)src4_offset_first_element_in_bytes + x4 * sizeof(DATA_TYPE) + y * (int)src4_stride_y + z * (int)src4_stride_z + w * (int)src4_stride_w; VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) - src1_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in1_ptr); + src1_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src1_addr); VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) - src2_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in2_ptr); + src2_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src2_addr); VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) - src3_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in3_ptr); + src3_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src3_addr); VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) - src4_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)in4_ptr); + src4_values = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)src4_addr); #if defined(OFFSET_IN1) && defined(OFFSET_OUT) && defined(SCALE_IN1) && defined(SCALE_OUT) && defined(OFFSET_IN2) && defined(SCALE_IN2) && defined(OFFSET_IN3) && defined(SCALE_IN3) && defined(OFFSET_IN4) && defined(SCALE_IN4) src1_values = requantize(src1_values, OFFSET_IN1, OFFSET_OUT, SCALE_IN1, SCALE_OUT); @@ -266,13 +254,22 @@ __kernel void concatenate_width_x4( const VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE) cond_in3 = CONVERT(x_coords < (VEC_DATA_TYPE(int, VEC_SIZE))(INPUT1_WIDTH + INPUT2_WIDTH), VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE)); const VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE) cond_in4 = CONVERT(x_coords < (VEC_DATA_TYPE(int, VEC_SIZE))(INPUT1_WIDTH + INPUT2_WIDTH + INPUT3_WIDTH), VEC_DATA_TYPE(COND_DATA_TYPE, VEC_SIZE)); + // Rotate src1/2_values, if values0 is a combination of src1_values and src2_values. + src1_values = (x < INPUT1_WIDTH && x1 == INPUT1_WIDTH - VEC_SIZE) ? ROTATE(src1_values, VEC_SIZE, INPUT1_ROTATE_N) : src1_values; + src2_values = (x < INPUT1_WIDTH && x1 == INPUT1_WIDTH - VEC_SIZE) ? ROTATE(src2_values, VEC_SIZE, INPUT1_ROTATE_N) : src2_values; + // Rotate src2/3_values, if values0 is a combination of src2_values and src3_values. + src2_values = (x < INPUT1_WIDTH + INPUT2_WIDTH && x2 == INPUT2_WIDTH - VEC_SIZE) ? ROTATE(src2_values, VEC_SIZE, INPUT2_ROTATE_N) : src2_values; + src3_values = (x < INPUT1_WIDTH + INPUT2_WIDTH && x2 == INPUT2_WIDTH - VEC_SIZE) ? ROTATE(src3_values, VEC_SIZE, INPUT2_ROTATE_N) : src3_values; + // Rotate src3/4_values, if values0 is a combination of src3_values and src4_values. + src3_values = (x < INPUT1_WIDTH + INPUT2_WIDTH + INPUT3_WIDTH && x3 == INPUT3_WIDTH - VEC_SIZE) ? ROTATE(src3_values, VEC_SIZE, INPUT3_ROTATE_N) : src3_values; + src4_values = (x < INPUT1_WIDTH + INPUT2_WIDTH + INPUT3_WIDTH && x3 == INPUT3_WIDTH - VEC_SIZE) ? ROTATE(src4_values, VEC_SIZE, INPUT3_ROTATE_N) : src4_values; + VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE) - values = select(src2_values, src1_values, cond_in2); - values = select(src3_values, values, cond_in3); - values = select(src4_values, values, cond_in4); + values0 = select(src2_values, src1_values, cond_in2); + values0 = select(src3_values, values0, cond_in3); + values0 = select(src4_values, values0, cond_in4); - VSTORE(VEC_SIZE) - (values, 0, (__global DATA_TYPE *)dst.ptr); + STORE_VECTOR_SELECT(values, DATA_TYPE, dst_addr, VEC_SIZE, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0) } #endif /* defined(INPUT2_WIDTH) && defined(INPUT3_WIDTH) */ #endif /* defined(INPUT1_WIDTH) */ diff --git a/src/core/CL/kernels/CLWidthConcatenate2TensorsKernel.cpp b/src/core/CL/kernels/CLWidthConcatenate2TensorsKernel.cpp index 27c650894c..a7a3463f59 100644 --- a/src/core/CL/kernels/CLWidthConcatenate2TensorsKernel.cpp +++ b/src/core/CL/kernels/CLWidthConcatenate2TensorsKernel.cpp @@ -28,7 +28,6 @@ #include "arm_compute/core/CL/ICLTensor.h" #include "arm_compute/core/Utils.h" #include "arm_compute/core/utils/misc/ShapeCalculator.h" -#include "src/core/AccessWindowStatic.h" #include "src/core/CL/CLValidate.h" #include "src/core/helpers/WindowHelpers.h" #include "src/core/utils/helpers/tensor_info.h" @@ -40,25 +39,6 @@ namespace arm_compute { namespace { -constexpr unsigned int num_elems_processed_per_iteration = 8; - -std::pair validate_and_configure_window(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output) -{ - // The window needs to be based on the output - Window win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); - AccessWindowStatic input1_access(input1, 0, 0, ceil_to_multiple(input1->dimension(0), num_elems_processed_per_iteration), input1->dimension(1)); - const unsigned int input2_right_padding = ((output->dimension(0) / num_elems_processed_per_iteration) * num_elems_processed_per_iteration - input1->dimension(0) - input2->dimension( - 0)) % num_elems_processed_per_iteration; - AccessWindowStatic input2_access(input2, -(input1->dimension(0) % num_elems_processed_per_iteration), - 0, input2->dimension(0) + input2_right_padding, input2->dimension(1)); - AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); - bool window_changed = update_window_and_padding(win, input1_access, input2_access, output_access); - - Window win_collapsed = win.collapse(win, Window::DimZ); - - Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; - return std::make_pair(err, win_collapsed); -} Status validate_arguments(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) { ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output); @@ -81,7 +61,6 @@ Status validate_arguments(const ITensorInfo *input1, const ITensorInfo *input2, Status CLWidthConcatenate2TensorsKernel::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output) { ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input1, input2, output)); - ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input1->clone().get(), input2->clone().get(), output->clone().get()).first); return Status{}; } @@ -90,13 +69,22 @@ void CLWidthConcatenate2TensorsKernel::configure(const CLCompileContext &compile ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output); ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input1, input2, output)); + auto padding_info = get_padding_info({ input1, input2, output }); + + const unsigned int min_dimension = std::min(input1->dimension(0), input2->dimension(0)); + const unsigned int num_elems_processed_per_iteration = adjust_vec_size(8, min_dimension); + const unsigned int vec_size_leftover = output->dimension(0) % num_elems_processed_per_iteration; + // Add build options CLBuildOptions build_opts; build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input1->data_type())); build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration)); + build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_leftover)); build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input1->dimension(2))); build_opts.add_option("-DINPUT1_WIDTH=" + support::cpp11::to_string(input1->dimension(0))); + build_opts.add_option("-DINPUT2_WIDTH=" + support::cpp11::to_string(input2->dimension(0))); build_opts.add_option("-DELEMENT_SIZE=" + support::cpp11::to_string(input1->element_size())); + build_opts.add_option("-DINPUT1_ROTATE_N=" + support::cpp11::to_string((input1->dimension(0) - vec_size_leftover) % num_elems_processed_per_iteration)); // If input have different quantization info set quantization parameters needed for the re-quantization process const bool have_different_qinfo = helpers::tensor_info::tensors_have_different_quantization_info(output, input1, input2); @@ -118,21 +106,12 @@ void CLWidthConcatenate2TensorsKernel::configure(const CLCompileContext &compile _kernel = create_kernel(compile_context, "concatenate_width_x2", build_opts.options()); // Configure kernel window - auto win_config = validate_and_configure_window(input1, input2, output); - ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config)); - - ICLKernel::configure_internal(std::get<1>(win_config)); + Window win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); + ICLKernel::configure_internal(win.collapse(win, Window::DimZ)); // Set output valid region output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape())); - - // Pass paddings as arguments to the kernel - const unsigned int input1_width = input1->dimension(0); - const unsigned int input1_right_padding = ceil_to_multiple(input1_width, num_elems_processed_per_iteration) - input1_width; - const unsigned int input2_left_padding = input1_width % num_elems_processed_per_iteration; - unsigned int idx0 = 3 * num_arguments_per_4D_tensor(); - _kernel.setArg(idx0++, input1_right_padding); - _kernel.setArg(idx0++, input2_left_padding); + ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); // Set config_id for enabling LWS tuning _config_id = "concatenate_width_x2_"; diff --git a/src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp b/src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp index 5ef2cc46ee..1c8fef2db3 100644 --- a/src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp +++ b/src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp @@ -28,7 +28,6 @@ #include "arm_compute/core/CL/ICLTensor.h" #include "arm_compute/core/Helpers.h" #include "arm_compute/core/Utils.h" -#include "src/core/AccessWindowStatic.h" #include "src/core/CL/CLValidate.h" #include "src/core/helpers/WindowHelpers.h" #include "src/core/utils/helpers/tensor_info.h" @@ -40,41 +39,6 @@ namespace arm_compute { namespace { -constexpr unsigned int num_elems_processed_per_iteration = 8; - -std::pair validate_and_configure_window(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *input3, ITensorInfo *input4, ITensorInfo *output) -{ - const unsigned int input1_width = input1->dimension(0); - const unsigned int input2_width = input2->dimension(0); - const unsigned int input3_width = input3->dimension(0); - const unsigned int input4_width = input4->dimension(0); - - // The window needs to be based on the output - Window win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); - AccessWindowStatic input1_access(input1, 0, 0, ceil_to_multiple(input1_width, num_elems_processed_per_iteration), input1->dimension(1)); - - const unsigned int input2_left_padding = input1_width % num_elems_processed_per_iteration; - const unsigned int input2_right_padding = ((input1_width + input2_width) / num_elems_processed_per_iteration) * num_elems_processed_per_iteration - input1_width + num_elems_processed_per_iteration - - input2_width; - AccessWindowStatic input2_access(input2, -input2_left_padding, 0, input2_width + input2_right_padding, input2->dimension(1)); - - const unsigned int input3_left_padding = (input1_width + input2_width) % num_elems_processed_per_iteration; - const unsigned int input3_right_padding = ((input1_width + input2_width + input3_width) / num_elems_processed_per_iteration) * num_elems_processed_per_iteration - input1_width - input2_width + - num_elems_processed_per_iteration - input3_width; - AccessWindowStatic input3_access(input3, -input3_left_padding, 0, input3_width + input3_right_padding, input3->dimension(1)); - - const unsigned int input4_left_padding = (input1_width + input2_width + input3_width) % num_elems_processed_per_iteration; - const unsigned int input4_right_padding = (output->dimension(0) / num_elems_processed_per_iteration) * num_elems_processed_per_iteration + num_elems_processed_per_iteration - output->dimension(0); - AccessWindowStatic input4_access(input4, -input4_left_padding, 0, input4_width + input4_right_padding, input4->dimension(1)); - - AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); - bool window_changed = update_window_and_padding(win, input1_access, input2_access, input3_access, input4_access, output_access); - - Window win_collapsed = win.collapse(win, Window::DimZ); - - Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; - return std::make_pair(err, win_collapsed); -} Status validate_arguments(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *input3, const ITensorInfo *input4, const ITensorInfo *output) { ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, input3, input4, output); @@ -103,7 +67,6 @@ CLWidthConcatenate4TensorsKernel::CLWidthConcatenate4TensorsKernel() Status CLWidthConcatenate4TensorsKernel::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *input3, const ITensorInfo *input4, const ITensorInfo *output) { ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input1, input2, input3, input4, output)); - ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input1->clone().get(), input2->clone().get(), input3->clone().get(), input4->clone().get(), output->clone().get()).first); return Status{}; } @@ -115,15 +78,25 @@ void CLWidthConcatenate4TensorsKernel::configure(const CLCompileContext &compile ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, input3, input4, output); ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input1, input2, input3, input4, output)); + auto padding_info = get_padding_info({ input1, input2, input3, input4, output }); + const unsigned int min_dimension = std::min(std::min(input1->dimension(0), input2->dimension(0)), std::min(input3->dimension(0), input4->dimension(0))); + const unsigned int num_elems_processed_per_iteration = adjust_vec_size(8, min_dimension); + const unsigned int vec_size_leftover = output->dimension(0) % num_elems_processed_per_iteration; + // Add build options CLBuildOptions build_opts; build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input1->data_type())); build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration)); + build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_leftover)); build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input1->dimension(2))); build_opts.add_option("-DINPUT1_WIDTH=" + support::cpp11::to_string(input1->dimension(0))); build_opts.add_option("-DINPUT2_WIDTH=" + support::cpp11::to_string(input2->dimension(0))); build_opts.add_option("-DINPUT3_WIDTH=" + support::cpp11::to_string(input3->dimension(0))); + build_opts.add_option("-DINPUT4_WIDTH=" + support::cpp11::to_string(input4->dimension(0))); build_opts.add_option("-DELEMENT_SIZE=" + support::cpp11::to_string(input1->element_size())); + build_opts.add_option("-DINPUT1_ROTATE_N=" + support::cpp11::to_string((input1->dimension(0) - vec_size_leftover) % num_elems_processed_per_iteration)); + build_opts.add_option("-DINPUT2_ROTATE_N=" + support::cpp11::to_string((input1->dimension(0) + input2->dimension(0) - vec_size_leftover) % num_elems_processed_per_iteration)); + build_opts.add_option("-DINPUT3_ROTATE_N=" + support::cpp11::to_string((input1->dimension(0) + input2->dimension(0) + input3->dimension(0) - vec_size_leftover) % num_elems_processed_per_iteration)); // If input have different quantization info set quantization parameters needed for the re-quantization process const bool have_different_qinfo = helpers::tensor_info::tensors_have_different_quantization_info(output, input1, input2, input3, input4); @@ -151,34 +124,12 @@ void CLWidthConcatenate4TensorsKernel::configure(const CLCompileContext &compile _kernel = create_kernel(compile_context, "concatenate_width_x4", build_opts.options()); // Configure kernel window - auto win_config = validate_and_configure_window(input1, input2, input3, input4, output); - ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config)); - - ICLKernel::configure_internal(std::get<1>(win_config)); + Window win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); + ICLKernel::configure_internal(win.collapse(win, Window::DimZ)); // Set output valid region output->set_valid_region(ValidRegion(Coordinates(), output->tensor_shape())); - - // Pass paddings as arguments to the kernel - const unsigned int input1_width = input1->dimension(0); - const unsigned int input2_width = input2->dimension(0); - const unsigned int input3_width = input3->dimension(0); - - const unsigned int input1_right_padding = ceil_to_multiple(input1_width, num_elems_processed_per_iteration) - input1_width; - const unsigned int input2_left_padding = input1_width % num_elems_processed_per_iteration; - const unsigned int input2_right_padding = ((input1_width + input2_width) / num_elems_processed_per_iteration) * num_elems_processed_per_iteration - input1_width + num_elems_processed_per_iteration - - input2_width; - const unsigned int input3_left_padding = (input1_width + input2_width) % num_elems_processed_per_iteration; - const unsigned int input3_right_padding = ((input1_width + input2_width + input3_width) / num_elems_processed_per_iteration) * num_elems_processed_per_iteration - input1_width - input2_width + - num_elems_processed_per_iteration - input3_width; - const unsigned int input4_left_padding = (input1_width + input2_width + input3_width) % num_elems_processed_per_iteration; - unsigned int idx0 = 5 * num_arguments_per_4D_tensor(); - _kernel.setArg(idx0++, input1_right_padding); - _kernel.setArg(idx0++, input2_left_padding); - _kernel.setArg(idx0++, input2_right_padding); - _kernel.setArg(idx0++, input3_left_padding); - _kernel.setArg(idx0++, input3_right_padding); - _kernel.setArg(idx0++, input4_left_padding); + ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); // Set config_id for enabling LWS tuning _config_id = "concatenate_width_x4_"; -- cgit v1.2.1