Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 702dc0c | 2021-03-19 15:06:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 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" |
| 31 | #include "arm_compute/core/Utils.h" |
| 32 | #include "arm_compute/core/Validate.h" |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 34 | #include "src/core/AccessWindowStatic.h" |
| 35 | #include "src/core/CL/CLValidate.h" |
| 36 | #include "src/core/helpers/AutoConfiguration.h" |
| 37 | #include "src/core/helpers/WindowHelpers.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 38 | |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 39 | #include "support/StringSupport.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 40 | |
Michele Di Giorgio | 9637b2e | 2019-09-23 16:49:49 +0100 | [diff] [blame] | 41 | namespace arm_compute |
| 42 | { |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 43 | namespace |
| 44 | { |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 45 | 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] | 46 | { |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 47 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | 8f5802f | 2019-02-22 11:08:32 +0000 | [diff] [blame] | 48 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 49 | if(input->num_channels() == 1) |
| 50 | { |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 51 | 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] | 52 | } |
| 53 | else |
| 54 | { |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 55 | 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] | 56 | ARM_COMPUTE_RETURN_ERROR_ON(axis == 0); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 57 | } |
Michalis Spyrou | 8aaf93e | 2018-10-11 17:33:32 +0100 | [diff] [blame] | 58 | 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] | 59 | 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] | 60 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(axis > 3, "Unsupported reduction axis"); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 61 | ARM_COMPUTE_RETURN_ERROR_ON((op == ReductionOperation::MEAN_SUM) && (axis == 0) && (input->dimension(0) == 0) && (input->data_type() != DataType::QASYMM8) |
| 62 | && (input->data_type() != DataType::QASYMM8_SIGNED)); |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 63 | 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] | 64 | |
| 65 | if(output->total_size() != 0) |
| 66 | { |
Manuel Bottini | 7b9998d | 2019-10-21 17:59:07 +0100 | [diff] [blame] | 67 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 68 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | return Status{}; |
| 72 | } |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 73 | } // namespace |
| 74 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 75 | CLReductionOperationKernel::CLReductionOperationKernel() |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 76 | : _input(nullptr), _output(nullptr), _reduction_axis(0), _op(ReductionOperation::SUM_SQUARE) |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 77 | { |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 78 | _type = CLKernelType::ELEMENTWISE; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 81 | 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] | 82 | { |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 83 | configure(CLKernelLibrary::get().get_compile_context(), input, output, axis, op); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 86 | 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] | 87 | { |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 88 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 89 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 90 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), axis, op)); |
| 91 | |
| 92 | auto padding_info = get_padding_info({ input, output }); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 93 | |
| 94 | _input = input; |
| 95 | _output = output; |
| 96 | _reduction_axis = axis; |
| 97 | _op = op; |
Michalis Spyrou | 343722b | 2018-06-05 13:04:40 +0100 | [diff] [blame] | 98 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 99 | const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_reduced_shape(input->info()->tensor_shape(), axis, true); |
| 100 | auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape).reset_padding().set_is_resizable(true)); |
| 101 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 102 | // Set build options |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 103 | CLBuildOptions build_opts; |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 104 | DataType data_type = input->info()->data_type(); |
| 105 | std::string data_type_promoted{}; |
| 106 | |
| 107 | if(is_data_type_quantized(data_type)) |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 108 | { |
Michalis Spyrou | 9bd49f9 | 2020-02-07 15:25:17 +0000 | [diff] [blame] | 109 | data_type_promoted = "int"; |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 110 | } |
| 111 | else |
| 112 | { |
| 113 | data_type_promoted = get_cl_type_from_data_type(data_type); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 114 | } |
Michalis Spyrou | b9626ab | 2019-05-13 17:41:01 +0100 | [diff] [blame] | 115 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 116 | const unsigned int width = input->info()->dimension(0) * input->info()->num_channels(); |
| 117 | unsigned int vec_size = (is_data_type_quantized(input->info()->data_type()) && (axis == 0)) ? 1 : 16; |
| 118 | vec_size = adjust_vec_size(vec_size, width); |
| 119 | const unsigned int vec_size_leftover = width % vec_size; |
| 120 | |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 121 | 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] | 122 | build_opts.add_option("-DDATA_TYPE_PROMOTED=" + data_type_promoted); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 123 | build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size)); |
| 124 | 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] | 125 | 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] | 126 | build_opts.add_option_if(op == ReductionOperation::SUM_SQUARE, "-DSUM_SQUARE"); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 127 | build_opts.add_option_if(op == ReductionOperation::MEAN_SUM, "-DMEAN"); |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 128 | build_opts.add_option_if(op == ReductionOperation::SUM, "-DSUM"); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 129 | build_opts.add_option_if(op == ReductionOperation::PROD, "-DPROD"); |
Usama Arif | b289050 | 2019-05-21 11:48:37 +0100 | [diff] [blame] | 130 | build_opts.add_option_if(op == ReductionOperation::MIN, "-DMIN"); |
Usama Arif | 048b0f3 | 2019-05-22 16:32:27 +0100 | [diff] [blame] | 131 | build_opts.add_option_if(op == ReductionOperation::MAX, "-DMAX"); |
Michalis Spyrou | 0b18d97 | 2020-01-30 18:11:13 +0000 | [diff] [blame] | 132 | build_opts.add_option_if(is_data_type_quantized(data_type), "-DOFFSET=" + support::cpp11::to_string(input->info()->quantization_info().uniform().offset)); |
| 133 | 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] | 134 | |
| 135 | switch(op) |
| 136 | { |
| 137 | case ReductionOperation::SUM_SQUARE: |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 138 | build_opts.add_option(("-DOPERATION=square_sum")); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 139 | break; |
| 140 | case ReductionOperation::SUM: |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 141 | case ReductionOperation::MEAN_SUM: |
| 142 | build_opts.add_option(("-DOPERATION=sum")); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 143 | break; |
Usama Arif | b289050 | 2019-05-21 11:48:37 +0100 | [diff] [blame] | 144 | case ReductionOperation::MIN: |
Usama Arif | 048b0f3 | 2019-05-22 16:32:27 +0100 | [diff] [blame] | 145 | case ReductionOperation::MAX: |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 146 | break; |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 147 | case ReductionOperation::PROD: |
| 148 | build_opts.add_option(("-DOPERATION=product")); |
| 149 | break; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 150 | default: |
| 151 | ARM_COMPUTE_ERROR("Unsupported reduction operation"); |
| 152 | } |
| 153 | |
| 154 | // Create kernel |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 155 | std::string kernel_axis_name; |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 156 | const bool is_serial_op = needs_serialized_reduction(_op, _input->info()->data_type(), _reduction_axis); |
| 157 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 158 | switch(axis) |
| 159 | { |
| 160 | case 0: |
| 161 | { |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 162 | build_opts.add_option("-DWIDTH=" + support::cpp11::to_string(width)); |
Giorgio Arena | 1fac037 | 2021-04-30 15:09:46 +0100 | [diff] [blame] | 163 | kernel_axis_name = ((is_serial_op) ? "non_parallel_x" : "x"); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 164 | } |
| 165 | break; |
| 166 | case 1: |
| 167 | build_opts.add_option("-DHEIGHT=" + support::cpp11::to_string(input->info()->dimension(1))); |
| 168 | kernel_axis_name = "y"; |
| 169 | break; |
| 170 | case 2: |
| 171 | build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input->info()->dimension(2))); |
| 172 | kernel_axis_name = "z"; |
| 173 | break; |
| 174 | case 3: |
| 175 | build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input->info()->dimension(2))); |
| 176 | build_opts.add_option("-DBATCH=" + support::cpp11::to_string(input->info()->dimension(3))); |
| 177 | kernel_axis_name = "w"; |
| 178 | break; |
| 179 | default: |
| 180 | ARM_COMPUTE_ERROR("Not supported"); |
| 181 | } |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 182 | _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] | 183 | |
| 184 | // Configure kernel window |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 185 | Window win = calculate_max_window(*input->info(), Steps(vec_size)); |
| 186 | win.set(Window::DimX, Window::Dimension(win.x().start(), win.x().end() * _input->info()->num_channels(), win.x().step())); |
| 187 | ICLKernel::configure_internal(win); |
Manuel Bottini | 34f88dd | 2019-10-18 10:37:46 +0000 | [diff] [blame] | 188 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 189 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 190 | } |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 191 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 192 | 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] | 193 | { |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 194 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, axis, op)); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 195 | return Status{}; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void CLReductionOperationKernel::run(const Window &window, cl::CommandQueue &queue) |
| 199 | { |
| 200 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 201 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
Manuel Bottini | 34f88dd | 2019-10-18 10:37:46 +0000 | [diff] [blame] | 202 | |
Sang-Hoon Park | 2697fd8 | 2019-10-15 16:49:24 +0100 | [diff] [blame] | 203 | 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] | 204 | switch(_reduction_axis) |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 205 | { |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 206 | case 0: |
| 207 | { |
| 208 | // We use parallel reduction only in non quantized types |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 209 | if(is_serial_op) |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 210 | { |
| 211 | // Get first input and output slices |
| 212 | Window window_in{ window }; |
| 213 | window_in.set(Window::DimX, Window::Dimension(0, _input->info()->dimension(0), _input->info()->dimension(0))); |
| 214 | |
Michele Di Giorgio | 0333704 | 2020-02-26 17:47:55 +0000 | [diff] [blame] | 215 | Window out_window{ window }; |
| 216 | out_window.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 217 | |
| 218 | Window in_slice = window_in.first_slice_window_1D(); |
| 219 | Window out_slice = out_window.first_slice_window_1D(); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 220 | |
| 221 | do |
| 222 | { |
| 223 | unsigned int idx = 0; |
| 224 | add_1D_tensor_argument(idx, _input, in_slice); |
| 225 | add_1D_tensor_argument(idx, _output, out_slice); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 226 | enqueue(queue, *this, in_slice); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 227 | } |
Michele Di Giorgio | 0333704 | 2020-02-26 17:47:55 +0000 | [diff] [blame] | 228 | 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] | 229 | } |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 230 | else |
| 231 | { |
| 232 | // Set out window |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 233 | bool has_collapsed = true; |
Giorgio Arena | 1fac037 | 2021-04-30 15:09:46 +0100 | [diff] [blame] | 234 | Window window_in = window.collapse_if_possible(window, 2, &has_collapsed); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 235 | ARM_COMPUTE_ERROR_ON(!has_collapsed); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 236 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 237 | Window window_out = window_in; |
| 238 | window_out.set(0, Window::Dimension()); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 239 | |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 240 | unsigned int idx = 0; |
Giorgio Arena | 1fac037 | 2021-04-30 15:09:46 +0100 | [diff] [blame] | 241 | add_3D_tensor_argument(idx, _input, window_in); |
| 242 | add_3D_tensor_argument(idx, _output, window_out); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 243 | enqueue(queue, *this, window_in); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 244 | } |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 245 | } |
| 246 | break; |
| 247 | case 1: |
| 248 | { |
| 249 | // Get first input and output slices |
| 250 | Window window_in{ window }; |
| 251 | window_in.set(Window::DimY, Window::Dimension(0, _input->info()->dimension(1), _input->info()->dimension(1))); |
| 252 | Window in_slice = window_in.first_slice_window_2D(); |
| 253 | Window out_slice = window.first_slice_window_2D(); |
| 254 | |
| 255 | do |
| 256 | { |
| 257 | unsigned int idx = 0; |
| 258 | add_2D_tensor_argument(idx, _input, in_slice); |
| 259 | add_2D_tensor_argument(idx, _output, out_slice); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 260 | enqueue(queue, *this, in_slice); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 261 | } |
| 262 | while(window_in.slide_window_slice_2D(in_slice) && window.slide_window_slice_2D(out_slice)); |
| 263 | } |
| 264 | break; |
| 265 | case 2: |
| 266 | { |
| 267 | // Get first input and output slices |
| 268 | Window window_in{ window }; |
| 269 | window_in.set(Window::DimZ, Window::Dimension(0, _input->info()->dimension(2), _input->info()->dimension(2))); |
| 270 | Window in_slice = window_in.first_slice_window_3D(); |
| 271 | Window out_slice = window.first_slice_window_3D(); |
| 272 | |
| 273 | do |
| 274 | { |
| 275 | unsigned int idx = 0; |
| 276 | add_3D_tensor_argument(idx, _input, in_slice); |
| 277 | add_3D_tensor_argument(idx, _output, out_slice); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 278 | enqueue(queue, *this, in_slice); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 279 | } |
| 280 | while(window_in.slide_window_slice_3D(in_slice) && window.slide_window_slice_3D(out_slice)); |
| 281 | } |
| 282 | break; |
| 283 | case 3: |
| 284 | { |
| 285 | // Get first input and output slices |
| 286 | Window window_in{ window }; |
| 287 | window_in.set(3, Window::Dimension(0, 1, 1)); |
| 288 | Window in_slice = window_in.first_slice_window_4D(); |
| 289 | Window out_slice = window.first_slice_window_4D(); |
| 290 | |
| 291 | do |
| 292 | { |
| 293 | unsigned int idx = 0; |
| 294 | add_4D_tensor_argument(idx, _input, in_slice); |
| 295 | add_4D_tensor_argument(idx, _output, out_slice); |
Giorgio Arena | 3ecf9fe | 2021-04-28 16:11:51 +0100 | [diff] [blame] | 296 | enqueue(queue, *this, in_slice); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 297 | } |
| 298 | while(window_in.slide_window_slice_4D(in_slice) && window.slide_window_slice_4D(out_slice)); |
| 299 | } |
| 300 | break; |
| 301 | default: |
| 302 | ARM_COMPUTE_ERROR("Not supported"); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 303 | } |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 304 | } |
Manuel Bottini | 34f88dd | 2019-10-18 10:37:46 +0000 | [diff] [blame] | 305 | } // namespace arm_compute |