Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 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 | */ |
| 24 | #include "arm_compute/core/CL/kernels/CLReductionOperationKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/AccessWindowStatic.h" |
| 27 | #include "arm_compute/core/CL/CLHelpers.h" |
| 28 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 29 | #include "arm_compute/core/CL/ICLTensor.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Helpers.h" |
| 31 | #include "arm_compute/core/TensorInfo.h" |
| 32 | #include "arm_compute/core/Utils.h" |
| 33 | #include "arm_compute/core/Validate.h" |
| 34 | #include "arm_compute/core/Window.h" |
| 35 | |
| 36 | #include "support/ToolchainSupport.h" |
| 37 | |
| 38 | using namespace arm_compute; |
| 39 | |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 40 | namespace |
| 41 | { |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 42 | // OpenCL kernel requires input width to be a power of 2 for x-axis. |
Michalis Spyrou | 25747e2 | 2018-08-08 17:12:38 +0100 | [diff] [blame] | 43 | constexpr unsigned int border_val = 64; |
| 44 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 45 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op, unsigned int width) |
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); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 48 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
Michalis Spyrou | 8aaf93e | 2018-10-11 17:33:32 +0100 | [diff] [blame] | 49 | 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] | 50 | 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] | 51 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(axis > 3, "Unsupported reduction axis"); |
| 52 | ARM_COMPUTE_RETURN_ERROR_ON(op == ReductionOperation::MEAN_SUM && axis == 0 && width == 0 && input->data_type() != DataType::QASYMM8); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 53 | |
| 54 | if(output->total_size() != 0) |
| 55 | { |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 56 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, output); |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 57 | if(op == ReductionOperation::ARG_IDX_MAX || op == ReductionOperation::ARG_IDX_MIN) |
| 58 | { |
| 59 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->data_type() == DataType::QASYMM8, "Not supported operation for QASYMM8"); |
| 60 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U32); |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Isabella Gottardi | e82cb04 | 2019-02-14 18:07:36 +0000 | [diff] [blame] | 65 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output); |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 66 | } |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | return Status{}; |
| 70 | } |
| 71 | |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 72 | std::tuple<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, unsigned int axis, ReductionOperation op) |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 73 | { |
| 74 | // Output tensor auto initialization if not yet initialized |
| 75 | TensorShape output_shape{ input->tensor_shape() }; |
| 76 | output_shape.set(axis, 1); |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 77 | const bool is_arg_min_max = (op == ReductionOperation::ARG_IDX_MIN || op == ReductionOperation::ARG_IDX_MAX); |
| 78 | DataType output_data_type = is_arg_min_max ? DataType::U32 : input->data_type(); |
Isabella Gottardi | e82cb04 | 2019-02-14 18:07:36 +0000 | [diff] [blame] | 79 | auto_init_if_empty(*output, output_shape, 1, output_data_type, input->quantization_info()); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 80 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 81 | const unsigned int num_elems_processed_per_iteration = (is_data_type_quantized(input->data_type()) && (axis == 0)) ? 1 : 16; |
| 82 | Window win = calculate_max_window(*input, Steps(num_elems_processed_per_iteration)); |
| 83 | bool window_changed = false; |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 84 | const bool is_serial_op = (op == ReductionOperation::ARG_IDX_MAX || op == ReductionOperation::ARG_IDX_MIN || is_data_type_quantized(input->data_type())); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 85 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 86 | switch(axis) |
| 87 | { |
| 88 | case 0: |
| 89 | { |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 90 | if(is_serial_op) |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 91 | { |
| 92 | AccessWindowHorizontal input_access(input, 0, input->dimension(0)); |
| 93 | AccessWindowHorizontal output_access(output, 0, 1); |
| 94 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 95 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | const unsigned int border_width = ((input->dimension(0) % border_val) != 0) ? border_val - input->dimension(0) % border_val : 0; |
| 100 | AccessWindowStatic input_access(input, 0, 0, input->dimension(0) + border_width, 1); |
| 101 | AccessWindowHorizontal output_access(output, 0, 1); |
| 102 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 103 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 104 | } |
| 105 | } |
| 106 | break; |
| 107 | case 1: |
| 108 | case 2: |
| 109 | case 3: |
| 110 | { |
| 111 | AccessWindowHorizontal input_access(input, 0, num_elems_processed_per_iteration); |
| 112 | AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); |
| 113 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 114 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 115 | } |
| 116 | break; |
| 117 | default: |
| 118 | ARM_COMPUTE_ERROR("Not supported"); |
| 119 | } |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 120 | |
| 121 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 122 | |
| 123 | return std::make_tuple(err, win); |
| 124 | } |
| 125 | } // namespace |
| 126 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 127 | CLReductionOperationKernel::CLReductionOperationKernel() |
| 128 | : _input(nullptr), _output(nullptr), _reduction_axis(0), _op(ReductionOperation::SUM_SQUARE), _border_size() |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | BorderSize CLReductionOperationKernel::border_size() const |
| 133 | { |
| 134 | return _border_size; |
| 135 | } |
| 136 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 137 | void CLReductionOperationKernel::configure(const ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op, unsigned int width) |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 138 | { |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 139 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 140 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 141 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), axis, op, width)); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 142 | |
| 143 | _input = input; |
| 144 | _output = output; |
| 145 | _reduction_axis = axis; |
| 146 | _op = op; |
Michalis Spyrou | 343722b | 2018-06-05 13:04:40 +0100 | [diff] [blame] | 147 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 148 | // Set build options |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 149 | CLBuildOptions build_opts; |
| 150 | std::string data_type_promoted = get_cl_type_from_data_type(input->info()->data_type()); |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 151 | if(is_data_type_quantized(input->info()->data_type())) |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 152 | { |
| 153 | data_type_promoted = "uint"; |
| 154 | } |
| 155 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())); |
| 156 | build_opts.add_option("-DDATA_TYPE_PROMOTED=" + data_type_promoted); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 157 | build_opts.add_option_if(op == ReductionOperation::SUM_SQUARE, "-DSUM_SQUARE"); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 158 | build_opts.add_option_if(op == ReductionOperation::MEAN_SUM, "-DMEAN"); |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 159 | build_opts.add_option_if(op == ReductionOperation::ARG_IDX_MAX, "-DARG_MAX"); |
| 160 | build_opts.add_option_if(op == ReductionOperation::ARG_IDX_MIN, "-DARG_MIN"); |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 161 | build_opts.add_option_if(op == ReductionOperation::PROD, "-DPROD"); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 162 | |
| 163 | switch(op) |
| 164 | { |
| 165 | case ReductionOperation::SUM_SQUARE: |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 166 | build_opts.add_option(("-DOPERATION=square_sum")); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 167 | break; |
| 168 | case ReductionOperation::SUM: |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 169 | case ReductionOperation::MEAN_SUM: |
| 170 | build_opts.add_option(("-DOPERATION=sum")); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 171 | break; |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 172 | case ReductionOperation::ARG_IDX_MAX: |
| 173 | case ReductionOperation::ARG_IDX_MIN: |
| 174 | break; |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 175 | case ReductionOperation::PROD: |
| 176 | build_opts.add_option(("-DOPERATION=product")); |
| 177 | break; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 178 | default: |
| 179 | ARM_COMPUTE_ERROR("Unsupported reduction operation"); |
| 180 | } |
| 181 | |
| 182 | // Create kernel |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 183 | cl::NDRange lws_hint = CLKernelLibrary::get().default_ndrange(); |
| 184 | std::string kernel_axis_name; |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 185 | const bool is_serial_op = (op == ReductionOperation::ARG_IDX_MAX || op == ReductionOperation::ARG_IDX_MIN || is_data_type_quantized(input->info()->data_type())); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 186 | switch(axis) |
| 187 | { |
| 188 | case 0: |
| 189 | { |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 190 | if(is_serial_op) |
| 191 | { |
| 192 | build_opts.add_option("-DWIDTH=" + support::cpp11::to_string(input->info()->dimension(0))); |
| 193 | build_opts.add_option_if_else(_input->info()->data_type() == DataType::F32, "-DCOND_DATA_TYPE=int", "-DCOND_DATA_TYPE=short"); |
| 194 | kernel_axis_name = "non_parallel_x"; |
| 195 | } |
| 196 | else |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 197 | { |
| 198 | build_opts.add_option_if(op == ReductionOperation::MEAN_SUM, "-DWIDTH=" + support::cpp11::to_string(width)); |
| 199 | const unsigned int width_leftover = input->info()->dimension(0) % border_val; |
| 200 | const unsigned int border_width = (width_leftover != 0) ? border_val - width_leftover : 0; |
| 201 | const unsigned int num_of_threads = ((input->info()->dimension(0) + border_width) / 16); |
| 202 | kernel_axis_name = "x"; |
| 203 | |
| 204 | // Set the number of WG based on the input size. If input width is < 128 |
| 205 | // we can use fewer threads than 8. |
| 206 | lws_hint = cl::NDRange(std::min(8U, num_of_threads)); |
| 207 | _border_size = BorderSize(0, border_width, 0, 0); |
| 208 | } |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 209 | } |
| 210 | break; |
| 211 | case 1: |
| 212 | build_opts.add_option("-DHEIGHT=" + support::cpp11::to_string(input->info()->dimension(1))); |
| 213 | kernel_axis_name = "y"; |
| 214 | break; |
| 215 | case 2: |
| 216 | build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input->info()->dimension(2))); |
| 217 | kernel_axis_name = "z"; |
| 218 | break; |
| 219 | case 3: |
| 220 | build_opts.add_option("-DDEPTH=" + support::cpp11::to_string(input->info()->dimension(2))); |
| 221 | build_opts.add_option("-DBATCH=" + support::cpp11::to_string(input->info()->dimension(3))); |
| 222 | kernel_axis_name = "w"; |
| 223 | break; |
| 224 | default: |
| 225 | ARM_COMPUTE_ERROR("Not supported"); |
| 226 | } |
| 227 | _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("reduction_operation_" + kernel_axis_name, build_opts.options())); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 228 | |
| 229 | // Configure kernel window |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 230 | auto win_config = validate_and_configure_window(_input->info(), _output->info(), axis, op); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 231 | |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 232 | ARM_COMPUTE_ERROR_THROW_ON(std::get<0>(win_config)); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 233 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 234 | ICLKernel::configure_internal(std::get<1>(win_config), lws_hint); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 235 | } |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 236 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 237 | Status CLReductionOperationKernel::validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op, unsigned int width) |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 238 | { |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 239 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, axis, op, width)); |
Michalis Spyrou | 7930db4 | 2018-11-22 17:36:28 +0000 | [diff] [blame] | 240 | ARM_COMPUTE_RETURN_ON_ERROR(std::get<0>(validate_and_configure_window(input->clone().get(), output->clone().get(), axis, op))); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 241 | |
| 242 | return Status{}; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void CLReductionOperationKernel::run(const Window &window, cl::CommandQueue &queue) |
| 246 | { |
| 247 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 248 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 249 | |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 250 | const bool is_serial_op = (_op == ReductionOperation::ARG_IDX_MAX || _op == ReductionOperation::ARG_IDX_MIN || is_data_type_quantized(_input->info()->data_type())); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 251 | switch(_reduction_axis) |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 252 | { |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 253 | case 0: |
| 254 | { |
| 255 | // We use parallel reduction only in non quantized types |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 256 | if(is_serial_op) |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 257 | { |
| 258 | // Get first input and output slices |
| 259 | Window window_in{ window }; |
| 260 | window_in.set(Window::DimX, Window::Dimension(0, _input->info()->dimension(0), _input->info()->dimension(0))); |
| 261 | |
| 262 | Window in_slice = window.first_slice_window_1D(); |
| 263 | Window out_slice = window.first_slice_window_1D(); |
| 264 | |
| 265 | do |
| 266 | { |
| 267 | unsigned int idx = 0; |
| 268 | add_1D_tensor_argument(idx, _input, in_slice); |
| 269 | add_1D_tensor_argument(idx, _output, out_slice); |
| 270 | enqueue(queue, *this, in_slice); |
| 271 | } |
| 272 | while(window_in.slide_window_slice_1D(in_slice) && window.slide_window_slice_1D(out_slice)); |
| 273 | } |
Manuel Bottini | b412fab | 2018-12-10 17:40:23 +0000 | [diff] [blame] | 274 | else |
| 275 | { |
| 276 | // Set out window |
| 277 | Window out_window(window); |
| 278 | out_window.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 279 | |
| 280 | // Get first input and output slices |
| 281 | Window in_slice = window.first_slice_window_2D(); |
| 282 | Window out_slice = out_window.first_slice_window_2D(); |
| 283 | |
| 284 | // Reshape window |
| 285 | const unsigned int border_width = ((in_slice.x().end() % border_val) != 0) ? border_val - in_slice.x().end() % border_val : 0; |
| 286 | in_slice.set(Window::DimX, Window::Dimension(in_slice.x().start(), in_slice.x().end() + border_width, in_slice.x().step())); |
| 287 | |
| 288 | // Set local sums buffer |
| 289 | unsigned int local_res_size = lws_hint()[0] * _input->info()->element_size(); |
| 290 | _kernel.setArg(num_arguments_per_2D_tensor() * 2, local_res_size, nullptr); |
| 291 | |
| 292 | do |
| 293 | { |
| 294 | unsigned int idx = 0; |
| 295 | add_2D_tensor_argument(idx, _input, in_slice); |
| 296 | add_2D_tensor_argument(idx, _output, out_slice); |
| 297 | enqueue(queue, *this, in_slice, lws_hint()); |
| 298 | } |
| 299 | while(window.slide_window_slice_2D(in_slice) && window.slide_window_slice_2D(out_slice)); |
| 300 | } |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 301 | } |
| 302 | break; |
| 303 | case 1: |
| 304 | { |
| 305 | // Get first input and output slices |
| 306 | Window window_in{ window }; |
| 307 | window_in.set(Window::DimY, Window::Dimension(0, _input->info()->dimension(1), _input->info()->dimension(1))); |
| 308 | Window in_slice = window_in.first_slice_window_2D(); |
| 309 | Window out_slice = window.first_slice_window_2D(); |
| 310 | |
| 311 | do |
| 312 | { |
| 313 | unsigned int idx = 0; |
| 314 | add_2D_tensor_argument(idx, _input, in_slice); |
| 315 | add_2D_tensor_argument(idx, _output, out_slice); |
| 316 | enqueue(queue, *this, in_slice); |
| 317 | } |
| 318 | while(window_in.slide_window_slice_2D(in_slice) && window.slide_window_slice_2D(out_slice)); |
| 319 | } |
| 320 | break; |
| 321 | case 2: |
| 322 | { |
| 323 | // Get first input and output slices |
| 324 | Window window_in{ window }; |
| 325 | window_in.set(Window::DimZ, Window::Dimension(0, _input->info()->dimension(2), _input->info()->dimension(2))); |
| 326 | Window in_slice = window_in.first_slice_window_3D(); |
| 327 | Window out_slice = window.first_slice_window_3D(); |
| 328 | |
| 329 | do |
| 330 | { |
| 331 | unsigned int idx = 0; |
| 332 | add_3D_tensor_argument(idx, _input, in_slice); |
| 333 | add_3D_tensor_argument(idx, _output, out_slice); |
| 334 | enqueue(queue, *this, in_slice); |
| 335 | } |
| 336 | while(window_in.slide_window_slice_3D(in_slice) && window.slide_window_slice_3D(out_slice)); |
| 337 | } |
| 338 | break; |
| 339 | case 3: |
| 340 | { |
| 341 | // Get first input and output slices |
| 342 | Window window_in{ window }; |
| 343 | window_in.set(3, Window::Dimension(0, 1, 1)); |
| 344 | Window in_slice = window_in.first_slice_window_4D(); |
| 345 | Window out_slice = window.first_slice_window_4D(); |
| 346 | |
| 347 | do |
| 348 | { |
| 349 | unsigned int idx = 0; |
| 350 | add_4D_tensor_argument(idx, _input, in_slice); |
| 351 | add_4D_tensor_argument(idx, _output, out_slice); |
| 352 | enqueue(queue, *this, in_slice); |
| 353 | } |
| 354 | while(window_in.slide_window_slice_4D(in_slice) && window.slide_window_slice_4D(out_slice)); |
| 355 | } |
| 356 | break; |
| 357 | default: |
| 358 | ARM_COMPUTE_ERROR("Not supported"); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 359 | } |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 360 | } |