From 8e150a1a74bb4c2d097731f5caf2eab676017c72 Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Fri, 21 Dec 2018 15:20:56 +0000 Subject: COMPMID-1859: Avoid unnecessary padding in CLWidthConcatenate[2,4]TensorsKernel Change-Id: I827f3fe0f013089ee930806c5273089a878435da Reviewed-on: https://review.mlplatform.org/438 Tested-by: Arm Jenkins Reviewed-by: Gian Marco Iodice --- .../kernels/CLWidthConcatenate4TensorsKernel.cpp | 51 ++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp') diff --git a/src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp b/src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp index 75aef9cce0..2db59df7f2 100644 --- a/src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp +++ b/src/core/CL/kernels/CLWidthConcatenate4TensorsKernel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -47,15 +47,29 @@ 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->dimension(0), num_elems_processed_per_iteration) + num_elems_processed_per_iteration, input1->dimension(1)); - AccessWindowStatic input2_access(input2, -num_elems_processed_per_iteration, 0, ceil_to_multiple(input2->dimension(0), num_elems_processed_per_iteration) + num_elems_processed_per_iteration, - input2->dimension(1)); - AccessWindowStatic input3_access(input3, -num_elems_processed_per_iteration, 0, ceil_to_multiple(input3->dimension(0), num_elems_processed_per_iteration) + num_elems_processed_per_iteration, - input3->dimension(1)); - AccessWindowStatic input4_access(input4, -num_elems_processed_per_iteration, 0, ceil_to_multiple(input4->dimension(0), num_elems_processed_per_iteration) + num_elems_processed_per_iteration, - input4->dimension(1)); + 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); @@ -128,6 +142,27 @@ void CLWidthConcatenate4TensorsKernel::configure(const ICLTensor *input1, const ICLKernel::configure_internal(std::get<1>(win_config)); + // Pass paddings as arguments to the kernel + const unsigned int input1_width = input1->info()->dimension(0); + const unsigned int input2_width = input2->info()->dimension(0); + const unsigned int input3_width = input3->info()->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); + // Set config_id for enabling LWS tuning _config_id = "concatenate_width_x4_"; _config_id += lower_string(string_from_data_type(input1->info()->data_type())); -- cgit v1.2.1