Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2017-2021, 2023 Arm Limited. |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 24 | #include "src/core/CL/kernels/CLReductionOperationKernel.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 25 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 28 | #include "arm_compute/core/CL/ICLTensor.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/TensorInfo.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/Validate.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame^] | 32 | #include "arm_compute/core/utils/helpers/AdjustVecSize.h" |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame^] | 34 | #include "arm_compute/core/utils/StringUtils.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 35 | #include "src/core/AccessWindowStatic.h" |
| 36 | #include "src/core/CL/CLValidate.h" |
| 37 | #include "src/core/helpers/AutoConfiguration.h" |
| 38 | #include "src/core/helpers/WindowHelpers.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 39 | |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 40 | #include "support/StringSupport.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 41 | |
Michele Di Giorgio | 9637b2e | 2019-09-23 16:49:49 +0100 | [diff] [blame] | 42 | namespace arm_compute |
| 43 | { |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 44 | namespace |
| 45 | { |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 46 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op) |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 47 | { |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 48 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | 8f5802f | 2019-02-22 11:08:32 +0000 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 50 | if(input->num_channels() == 1) |
| 51 | { |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 52 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::S32, DataType::F16, DataType::F32); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 53 | } |
| 54 | else |
| 55 | { |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 56 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 2, DataType::F16, DataType::F32); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 57 | ARM_COMPUTE_RETURN_ERROR_ON(axis == 0); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 58 | } |
Michalis Spyrou | 8aaf93e | 2018-10-11 17:33:32 +0100 | [diff] [blame] | 59 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(op == ReductionOperation::SUM_SQUARE && input->data_type() == DataType::QASYMM8, "Not supported reduction operation for QASYMM8"); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 60 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(axis >= TensorShape::num_max_dimensions, "Reduction axis greater than max number of dimensions"); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 61 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(axis > 3, "Unsupported reduction axis"); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 62 | ARM_COMPUTE_RETURN_ERROR_ON((op == ReductionOperation::MEAN_SUM) && (axis == 0) && (input->dimension(0) == 0) && (input->data_type() != DataType::QASYMM8) |
| 63 | && (input->data_type() != DataType::QASYMM8_SIGNED)); |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 64 | ARM_COMPUTE_RETURN_ERROR_ON_MSG((op == ReductionOperation::ARG_IDX_MAX) || (op == ReductionOperation::ARG_IDX_MIN), "Not supported reduction operation, use CLArgMinMaxLayer"); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 65 | |
| 66 | if(output->total_size() != 0) |
| 67 | { |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 68 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 69 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | return Status{}; |
| 73 | } |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 74 | } // namespace |
| 75 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 76 | CLReductionOperationKernel::CLReductionOperationKernel() |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 77 | : _input(nullptr), _output(nullptr), _reduction_axis(0), _op(ReductionOperation::SUM_SQUARE) |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 78 | { |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 79 | _type = CLKernelType::ELEMENTWISE; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 82 | void CLReductionOperationKernel::configure(const ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op) |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 83 | { |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 84 | configure(CLKernelLibrary::get().get_compile_context(), input, output, axis, op); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 87 | void CLReductionOperationKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op) |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 88 | { |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 89 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 90 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 91 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), axis, op)); |
| 92 | |
| 93 | auto padding_info = get_padding_info({ input, output }); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 94 | |
| 95 | _input = input; |
| 96 | _output = output; |
| 97 | _reduction_axis = axis; |
| 98 | _op = op; |
Michalis Spyrou | 343722b | 2018-06-05 13:04:40 +0100 | [diff] [blame] | 99 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 100 | const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_reduced_shape(input->info()->tensor_shape(), axis, true); |
| 101 | auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape).reset_padding().set_is_resizable(true)); |
| 102 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 103 | // Set build options |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 104 | CLBuildOptions build_opts; |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 105 | DataType data_type = input->info()->data_type(); |
| 106 | std::string data_type_promoted{}; |
| 107 | |
| 108 | if(is_data_type_quantized(data_type)) |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 109 | { |
Michalis Spyrou | 9bd49f9 | 2020-02-07 15:25:17 +0000 | [diff] [blame] | 110 | data_type_promoted = "int"; |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 111 | } |
| 112 | else |
| 113 | { |
| 114 | data_type_promoted = get_cl_type_from_data_type(data_type); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 115 | } |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 116 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 117 | const unsigned int width = input->info()->dimension(0) * input->info()->num_channels(); |
| 118 | unsigned int vec_size = (is_data_type_quantized(input->info()->data_type()) && (axis == 0)) ? 1 : 16; |
| 119 | vec_size = adjust_vec_size(vec_size, width); |
| 120 | const unsigned int vec_size_leftover = width % vec_size; |
| 121 | |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 122 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 123 | build_opts.add_option("-DDATA_TYPE_PROMOTED=" + data_type_promoted); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 124 | build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size)); |
| 125 | build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_leftover)); |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 126 | build_opts.add_option_if(is_data_type_float(data_type), "-DFLOAT_DATA_TYPE"); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 127 | build_opts.add_option_if(op == ReductionOperation::SUM_SQUARE, "-DSUM_SQUARE"); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 128 | build_opts.add_option_if(op == ReductionOperation::MEAN_SUM, "-DMEAN"); |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 129 | build_opts.add_option_if(op == ReductionOperation::SUM, "-DSUM"); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 130 | build_opts.add_option_if(op == ReductionOperation::PROD, "-DPROD"); |
Usama Arif | b289050 | 2019-05-21 11:48:37 +0100 | [diff] [blame] | 131 | build_opts.add_option_if(op == ReductionOperation::MIN, "-DMIN"); |
Usama Arif | 048b0f3 | 2019-05-22 16:32:27 +0100 | [diff] [blame] | 132 | build_opts.add_option_if(op == ReductionOperation::MAX, "-DMAX"); |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 133 | build_opts.add_option_if(is_data_type_quantized(data_type), "-DOFFSET=" + support::cpp11::to_string(input->info()->quantization_info().uniform().offset)); |
| 134 | build_opts.add_option_if(is_data_type_quantized(data_type), "-DSCALE=" + float_to_string_with_full_precision(input->info()->quantization_info().uniform().scale)); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 135 | |
| 136 | switch(op) |
| 137 | { |
| 138 | case ReductionOperation::SUM_SQUARE: |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 139 | build_opts.add_option(("-DOPERATION=square_sum")); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 140 | break; |
| 141 | case ReductionOperation::SUM: |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 142 | case ReductionOperation::MEAN_SUM: |
| 143 | build_opts.add_option(("-DOPERATION=sum")); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 144 | break; |
Usama Arif | b289050 | 2019-05-21 11:48:37 +0100 | [diff] [blame] | 145 | case ReductionOperation::MIN: |
Usama Arif | 048b0f3 | 2019-05-22 16:32:27 +0100 | [diff] [blame] | 146 | case ReductionOperation::MAX: |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 147 | break; |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 148 | case ReductionOperation::PROD: |
| 149 | build_opts.add_option(("-DOPERATION=product")); |
| 150 | break; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 151 | default: |
| 152 | ARM_COMPUTE_ERROR("Unsupported reduction operation"); |
| 153 | } |
| 154 | |
| 155 | // Create kernel |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 156 | std::string kernel_axis_name; |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 157 | const bool is_serial_op = needs_serialized_reduction(_op, _input->info()->data_type(), _reduction_axis); |
| 158 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 159 | switch(axis) |
| 160 | { |
| 161 | case 0: |
| 162 | { |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 163 | build_opts.add_option("-DWIDTH=" + support::cpp11::to_string(width)); |
Giorgio Arena | 1fac037 | 2021-04-30 15:09:46 +0100 | [diff] [blame] | 164 | kernel_axis_name = ((is_serial_op) ? "non_parallel_x" : "x"); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 165 | } |
| 166 | break; |
| 167 | case 1: |
| 168 | build_opts.add_option("-DHEIGHT=" + support::cpp11::to_string(input->info()->dimension(1))); |
| 169 | kernel_axis_name = "y"; |
| 170 | break; |
| 171 | case 2: |
| 172 | build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input->info()->dimension(2))); |
| 173 | kernel_axis_name = "z"; |
| 174 | break; |
| 175 | case 3: |
| 176 | build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input->info()->dimension(2))); |
| 177 | build_opts.add_option("-DBATCH=" + support::cpp11::to_string(input->info()->dimension(3))); |
| 178 | kernel_axis_name = "w"; |
| 179 | break; |
| 180 | default: |
| 181 | ARM_COMPUTE_ERROR("Not supported"); |
| 182 | } |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 183 | _kernel = create_kernel(compile_context, "reduction_operation_" + kernel_axis_name, build_opts.options()); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 184 | |
| 185 | // Configure kernel window |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 186 | Window win = calculate_max_window(*input->info(), Steps(vec_size)); |
| 187 | win.set(Window::DimX, Window::Dimension(win.x().start(), win.x().end() * _input->info()->num_channels(), win.x().step())); |
| 188 | ICLKernel::configure_internal(win); |
Manuel Bottini | 34f88dd | 2019-10-18 10:37:46 +0000 | [diff] [blame] | 189 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 190 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 191 | } |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 192 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 193 | Status CLReductionOperationKernel::validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op) |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 194 | { |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 195 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, axis, op)); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 196 | return Status{}; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void CLReductionOperationKernel::run(const Window &window, cl::CommandQueue &queue) |
| 200 | { |
| 201 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 202 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
Manuel Bottini | 34f88dd | 2019-10-18 10:37:46 +0000 | [diff] [blame] | 203 | |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 204 | const bool is_serial_op = needs_serialized_reduction(_op, _input->info()->data_type(), _reduction_axis); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 205 | switch(_reduction_axis) |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 206 | { |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 207 | case 0: |
| 208 | { |
| 209 | // We use parallel reduction only in non quantized types |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 210 | if(is_serial_op) |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 211 | { |
| 212 | // Get first input and output slices |
| 213 | Window window_in{ window }; |
| 214 | window_in.set(Window::DimX, Window::Dimension(0, _input->info()->dimension(0), _input->info()->dimension(0))); |
| 215 | |
Michele Di Giorgio | 0333704 | 2020-02-26 17:47:55 +0000 | [diff] [blame] | 216 | Window out_window{ window }; |
| 217 | out_window.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 218 | |
| 219 | Window in_slice = window_in.first_slice_window_1D(); |
| 220 | Window out_slice = out_window.first_slice_window_1D(); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 221 | |
| 222 | do |
| 223 | { |
| 224 | unsigned int idx = 0; |
| 225 | add_1D_tensor_argument(idx, _input, in_slice); |
| 226 | add_1D_tensor_argument(idx, _output, out_slice); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 227 | enqueue(queue, *this, in_slice); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 228 | } |
Michele Di Giorgio | 0333704 | 2020-02-26 17:47:55 +0000 | [diff] [blame] | 229 | while(window_in.slide_window_slice_1D(in_slice) && out_window.slide_window_slice_1D(out_slice)); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 230 | } |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 231 | else |
| 232 | { |
| 233 | // Set out window |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 234 | bool has_collapsed = true; |
Giorgio Arena | 1fac037 | 2021-04-30 15:09:46 +0100 | [diff] [blame] | 235 | Window window_in = window.collapse_if_possible(window, 2, &has_collapsed); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 236 | ARM_COMPUTE_ERROR_ON(!has_collapsed); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 237 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 238 | Window window_out = window_in; |
| 239 | window_out.set(0, Window::Dimension()); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 240 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 241 | unsigned int idx = 0; |
Giorgio Arena | 1fac037 | 2021-04-30 15:09:46 +0100 | [diff] [blame] | 242 | add_3D_tensor_argument(idx, _input, window_in); |
| 243 | add_3D_tensor_argument(idx, _output, window_out); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 244 | enqueue(queue, *this, window_in); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 245 | } |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 246 | } |
| 247 | break; |
| 248 | case 1: |
| 249 | { |
| 250 | // Get first input and output slices |
| 251 | Window window_in{ window }; |
| 252 | window_in.set(Window::DimY, Window::Dimension(0, _input->info()->dimension(1), _input->info()->dimension(1))); |
| 253 | Window in_slice = window_in.first_slice_window_2D(); |
| 254 | Window out_slice = window.first_slice_window_2D(); |
| 255 | |
| 256 | do |
| 257 | { |
| 258 | unsigned int idx = 0; |
| 259 | add_2D_tensor_argument(idx, _input, in_slice); |
| 260 | add_2D_tensor_argument(idx, _output, out_slice); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 261 | enqueue(queue, *this, in_slice); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 262 | } |
| 263 | while(window_in.slide_window_slice_2D(in_slice) && window.slide_window_slice_2D(out_slice)); |
| 264 | } |
| 265 | break; |
| 266 | case 2: |
| 267 | { |
| 268 | // Get first input and output slices |
| 269 | Window window_in{ window }; |
| 270 | window_in.set(Window::DimZ, Window::Dimension(0, _input->info()->dimension(2), _input->info()->dimension(2))); |
| 271 | Window in_slice = window_in.first_slice_window_3D(); |
| 272 | Window out_slice = window.first_slice_window_3D(); |
| 273 | |
| 274 | do |
| 275 | { |
| 276 | unsigned int idx = 0; |
| 277 | add_3D_tensor_argument(idx, _input, in_slice); |
| 278 | add_3D_tensor_argument(idx, _output, out_slice); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 279 | enqueue(queue, *this, in_slice); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 280 | } |
| 281 | while(window_in.slide_window_slice_3D(in_slice) && window.slide_window_slice_3D(out_slice)); |
| 282 | } |
| 283 | break; |
| 284 | case 3: |
| 285 | { |
| 286 | // Get first input and output slices |
| 287 | Window window_in{ window }; |
| 288 | window_in.set(3, Window::Dimension(0, 1, 1)); |
| 289 | Window in_slice = window_in.first_slice_window_4D(); |
| 290 | Window out_slice = window.first_slice_window_4D(); |
| 291 | |
| 292 | do |
| 293 | { |
| 294 | unsigned int idx = 0; |
| 295 | add_4D_tensor_argument(idx, _input, in_slice); |
| 296 | add_4D_tensor_argument(idx, _output, out_slice); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 297 | enqueue(queue, *this, in_slice); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 298 | } |
| 299 | while(window_in.slide_window_slice_4D(in_slice) && window.slide_window_slice_4D(out_slice)); |
| 300 | } |
| 301 | break; |
| 302 | default: |
| 303 | ARM_COMPUTE_ERROR("Not supported"); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 304 | } |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 305 | } |
Manuel Bottini | 34f88dd | 2019-10-18 10:37:46 +0000 | [diff] [blame] | 306 | } // namespace arm_compute |