Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | a5eb591 | 2020-01-07 17:37:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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/NEON/kernels/NEScaleKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/AccessWindowStatic.h" |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/CPP/Validate.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Coordinates.h" |
| 29 | #include "arm_compute/core/Error.h" |
| 30 | #include "arm_compute/core/Helpers.h" |
| 31 | #include "arm_compute/core/ITensor.h" |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/NEON/wrapper/wrapper.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/TensorInfo.h" |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 34 | #include "arm_compute/core/Utils.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 35 | #include "arm_compute/core/Validate.h" |
| 36 | #include "arm_compute/core/Window.h" |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 37 | #include "arm_compute/core/utils/misc/Utility.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | |
| 39 | #include <arm_neon.h> |
| 40 | #include <cstddef> |
| 41 | #include <cstdint> |
| 42 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 43 | namespace arm_compute |
| 44 | { |
| 45 | namespace |
| 46 | { |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 47 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, |
| 48 | const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy, |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 49 | BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding, bool align_corners) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 50 | { |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 51 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 52 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16, DataType::F16, DataType::F32, DataType::QASYMM8); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 53 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); |
| 54 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 55 | ARM_COMPUTE_RETURN_ERROR_ON(output == input); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 56 | ARM_COMPUTE_RETURN_ERROR_ON(sampling_policy != SamplingPolicy::CENTER && sampling_policy != SamplingPolicy::TOP_LEFT); |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 57 | ARM_COMPUTE_RETURN_ERROR_ON(!use_padding && border_mode != BorderMode::CONSTANT); |
| 58 | ARM_COMPUTE_UNUSED(constant_border_value); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 59 | |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 60 | const DataLayout data_layout = input->data_layout(); |
| 61 | const auto width_index = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 62 | const auto height_index = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 63 | const auto output_width = output->dimension(width_index); |
| 64 | const auto output_height = output->dimension(height_index); |
| 65 | ARM_COMPUTE_RETURN_ERROR_ON(output_width == 0); |
| 66 | ARM_COMPUTE_RETURN_ERROR_ON(output_height == 0); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 67 | |
| 68 | if(policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 69 | { |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32); |
| 71 | } |
| 72 | |
| 73 | if(policy == InterpolationPolicy::BILINEAR) |
| 74 | { |
| 75 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32); |
| 76 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32); |
| 77 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32); |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 78 | |
| 79 | if(align_corners) |
| 80 | { |
| 81 | // For bilinear method with aligned corners, the resize ratio will |
| 82 | // be calculated by (input_size - 1)/(output_size - 1). Belows are |
| 83 | // checking possible overflows. |
| 84 | const auto input_width = input->dimension(width_index); |
| 85 | const auto input_height = input->dimension(height_index); |
| 86 | |
| 87 | ARM_COMPUTE_RETURN_ERROR_ON(input_width == 0 || input_height == 0); |
| 88 | ARM_COMPUTE_RETURN_ERROR_ON((output_width - 1 == 0) || (output_height - 1 == 0)); |
| 89 | } |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | if(policy == InterpolationPolicy::AREA) |
| 93 | { |
| 94 | ARM_COMPUTE_RETURN_ERROR_ON(data_layout != DataLayout::NCHW); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 95 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | return Status{}; |
| 99 | } |
| 100 | |
| 101 | std::pair<Status, Window> validate_and_configure_window_nchw(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output, |
| 102 | InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size) |
| 103 | { |
| 104 | bool window_changed{ false }; |
| 105 | Window win{}; |
| 106 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 107 | constexpr unsigned int num_elems_processed_per_iteration = 16; |
| 108 | |
| 109 | // Configure kernel window |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 110 | win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 111 | |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 112 | const ValidRegion &input_valid_region = input->valid_region(); |
| 113 | |
| 114 | if(offsets != nullptr) |
| 115 | { |
| 116 | AccessWindowHorizontal offsets_access(offsets, 0, num_elems_processed_per_iteration); |
| 117 | window_changed = window_changed || update_window_and_padding(win, offsets_access); |
| 118 | } |
| 119 | if(dx != nullptr && dy != nullptr) |
| 120 | { |
| 121 | AccessWindowHorizontal dx_access(dx, 0, num_elems_processed_per_iteration); |
| 122 | AccessWindowHorizontal dy_access(dy, 0, num_elems_processed_per_iteration); |
| 123 | window_changed = window_changed || update_window_and_padding(win, dx_access, dy_access); |
| 124 | } |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 125 | |
| 126 | // Reads can occur within the valid region of the input |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 127 | AccessWindowStatic input_access(input, input_valid_region.anchor[0] - border_size.left, |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 128 | input_valid_region.anchor[1] - border_size.top, |
| 129 | input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size.right, |
| 130 | input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size.bottom); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 131 | AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); |
| 132 | window_changed = window_changed || update_window_and_padding(win, input_access, output_access); |
| 133 | output_access.set_valid_region(win, calculate_valid_region_scale(*input, output->tensor_shape(), |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 134 | policy, sampling_policy, border_undefined)); |
| 135 | |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 136 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 137 | return std::make_pair(err, win); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 138 | } |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 139 | |
| 140 | std::pair<Status, Window> validate_and_configure_window_nhwc(ITensorInfo *input, ITensorInfo *output, |
| 141 | InterpolationPolicy policy, bool border_undefined, |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 142 | SamplingPolicy sampling_policy, BorderSize border_size, bool use_padding) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 143 | { |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 144 | bool window_changed{ false }; |
| 145 | Window win{}; |
| 146 | |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 147 | const unsigned int num_elems_processed_per_iteration = (use_padding && policy == InterpolationPolicy::NEAREST_NEIGHBOR) ? 16 / input->element_size() : 1; |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 148 | |
| 149 | // Configure kernel window |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 150 | win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 151 | |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 152 | if(use_padding) |
| 153 | { |
Georgios Pinitas | 3262042 | 2019-06-27 17:14:32 +0100 | [diff] [blame] | 154 | AccessWindowStatic input_access(input, 0, -border_size.top, ceil_to_multiple(input->tensor_shape()[0], num_elems_processed_per_iteration), input->tensor_shape()[1]); |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 155 | AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); |
| 156 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 157 | output->set_valid_region(calculate_valid_region_scale(*input, output->tensor_shape(), policy, sampling_policy, border_undefined)); |
| 158 | } |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 159 | |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 160 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 161 | return std::make_pair(err, win); |
| 162 | } |
| 163 | |
| 164 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output, |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 165 | InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size, bool use_padding) |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 166 | { |
| 167 | std::pair<Status, Window> win_config; |
| 168 | switch(input->data_layout()) |
| 169 | { |
| 170 | case DataLayout::NCHW: |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 171 | if(!use_padding) |
| 172 | { |
| 173 | return std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Padding required for NCHW"), Window{}); |
| 174 | } |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 175 | win_config = validate_and_configure_window_nchw(input, dx, dy, offsets, output, policy, border_undefined, sampling_policy, border_size); |
| 176 | break; |
| 177 | case DataLayout::NHWC: |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 178 | win_config = validate_and_configure_window_nhwc(input, output, policy, border_undefined, sampling_policy, border_size, use_padding); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 179 | break; |
| 180 | default: |
| 181 | win_config = std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported data layout!"), Window{}); |
| 182 | } |
| 183 | |
| 184 | return win_config; |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | template <typename T> |
| 188 | inline void scale_nearest_nhwc_core(const ITensor *input, const ITensor *offsets, ITensor *output, |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 189 | float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c, float sampling_offset) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 190 | { |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 191 | const int window_step_x = 16 / sizeof(T); |
| 192 | const auto window_start_x = static_cast<int32_t>(window.x().start()); |
| 193 | const auto window_end_x = static_cast<int32_t>(window.x().end()); |
| 194 | |
| 195 | window.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 196 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 197 | Iterator in(input, win_in); |
| 198 | Iterator out(output, window); |
| 199 | |
| 200 | const size_t offsets_stride = stride_w / sizeof(T); |
| 201 | |
| 202 | execute_window_loop(window, [&](const Coordinates & id) |
| 203 | { |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 204 | const int32_t offset = *reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z()))); |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 205 | const int in_yi = std::floor((id.z() + sampling_offset) * hr); |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 206 | const int offset_row = in_yi * stride_h; |
| 207 | int32_t x = window_start_x; |
| 208 | for(; x < window_end_x - window_step_x; x += window_step_x) |
| 209 | { |
| 210 | wrapper::vstore(reinterpret_cast<T *>(out.ptr()) + x, |
| 211 | wrapper::vloadq(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row + x * stride_c))); |
| 212 | } |
| 213 | for(; x < window_end_x; ++x) |
| 214 | { |
| 215 | *(reinterpret_cast<T *>(out.ptr()) + x) = |
| 216 | *(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row + x * stride_c)); |
| 217 | } |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 218 | }, |
| 219 | in, out); |
| 220 | } |
| 221 | |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 222 | template <typename T, typename ConstType> |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 223 | inline void scale_bilinear_nhwc_core(const ITensor *input, const ITensor *offsets, const ITensor *dx, const ITensor *dy, ITensor *output, |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 224 | float hr, float sampling_offset, Window window, const Window &win_in, size_t stride_w, size_t stride_h, |
| 225 | size_t stride_c, BorderMode border_mode, PixelValue constant_border_value, bool use_padding) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 226 | { |
| 227 | Iterator in(input, win_in); |
| 228 | Iterator out(output, window); |
| 229 | |
| 230 | const size_t stride_w_elems = stride_w / sizeof(T); |
| 231 | const size_t stride_h_elems = stride_h / sizeof(T); |
| 232 | |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 233 | const int input_width = input->info()->dimension(1); |
| 234 | const int input_height = input->info()->dimension(2); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 235 | |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 236 | T border_value; |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 237 | if(use_padding && border_mode != BorderMode::REPLICATE) |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 238 | { |
Pablo Tello | 1097147 | 2019-05-15 15:14:46 +0100 | [diff] [blame] | 239 | // configure() sets top border to 0 for BorderMode::REPLICATE and border_value is not needed in execute_window_loop() for REPLICATE |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 240 | border_value = *reinterpret_cast<T *>(input->buffer() + input->info()->offset_first_element_in_bytes() - stride_w); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | border_value = static_cast<T>(constant_border_value.get<ConstType>()); |
| 245 | } |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 246 | |
Michalis Spyrou | fae513c | 2019-10-16 17:41:33 +0100 | [diff] [blame] | 247 | auto is_valid = [](int64_t x, int64_t low_x, int64_t high_x, int64_t y, int64_t low_y, int64_t high_y) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 248 | { |
| 249 | return !(x < low_x || x > high_x || y < low_y || y > high_y); |
| 250 | }; |
| 251 | |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 252 | int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1; |
| 253 | |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 254 | const bool is_quantized = (input->info()->data_type() == DataType::QASYMM8); |
| 255 | const UniformQuantizationInfo iq_info = input->info()->quantization_info().uniform(); |
| 256 | const UniformQuantizationInfo oq_info = output->info()->quantization_info().uniform(); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 257 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 258 | execute_window_loop(window, [&](const Coordinates & id) |
| 259 | { |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 260 | const auto offset = (*reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z())))) / static_cast<int>(sizeof(T)); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 261 | const auto dx_scale = *reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id.y(), id.z()))); |
| 262 | const auto dy_scale = *reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id.y(), id.z()))); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 263 | const int in_yi = std::floor((id.z() + sampling_offset) * hr - sampling_offset); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 264 | const int offset_row = in_yi * stride_h + id.x() * stride_c; |
| 265 | const T *in_ptr = reinterpret_cast<T *>(in.ptr() + offset * stride_w + offset_row); |
| 266 | |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 267 | if(is_valid(offset, -border_size, input_width - 1 + border_size, in_yi, -border_size, input_height - 1 + border_size)) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 268 | { |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 269 | T a00 = 0; |
| 270 | T a01 = 0; |
| 271 | T a10 = 0; |
| 272 | T a11 = 0; |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 273 | |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 274 | if(border_mode == BorderMode::CONSTANT) |
| 275 | { |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 276 | a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : border_value; |
| 277 | a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : border_value; |
| 278 | a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : border_value; |
| 279 | a11 = is_valid(offset + 1, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems + stride_w_elems) : border_value; |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 280 | } |
| 281 | else if(border_mode == BorderMode::REPLICATE) |
| 282 | { |
| 283 | auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1); |
| 284 | auto clamped_x1 = utility::clamp<int>(offset + 1, 0, input_width - 1); |
| 285 | auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1); |
| 286 | auto clamped_y1 = utility::clamp<int>(in_yi + 1, 0, input_height - 1); |
| 287 | |
| 288 | a00 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c); |
| 289 | a01 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y * stride_h + id.x() * stride_c); |
| 290 | a10 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y1 * stride_h + id.x() * stride_c); |
| 291 | a11 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y1 * stride_h + id.x() * stride_c); |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : 0; |
| 296 | a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : 0; |
| 297 | a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : 0; |
| 298 | a11 = is_valid(offset + 1, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems + stride_w_elems) : 0; |
| 299 | } |
| 300 | |
| 301 | // Perform interpolation |
| 302 | const float dx1 = 1.0f - dx_scale; |
| 303 | const float dy1 = 1.0f - dy_scale; |
| 304 | |
| 305 | const float w1 = dx1 * dy1; |
| 306 | const float w2 = dx_scale * dy1; |
| 307 | const float w3 = dx1 * dy_scale; |
| 308 | const float w4 = dx_scale * dy_scale; |
| 309 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 310 | T res = 0; |
| 311 | //dequantize quantized input |
| 312 | if(is_quantized) |
| 313 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 314 | float inp00 = dequantize_qasymm8(a00, iq_info); |
| 315 | float inp01 = dequantize_qasymm8(a01, iq_info); |
| 316 | float inp10 = dequantize_qasymm8(a10, iq_info); |
| 317 | float inp11 = dequantize_qasymm8(a11, iq_info); |
| 318 | res = static_cast<T>(quantize_qasymm8((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), oq_info)); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 319 | } |
| 320 | else |
| 321 | { |
| 322 | res = static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4); |
| 323 | } |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 324 | // Store result |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 325 | *reinterpret_cast<T *>(out.ptr()) = res; |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 326 | } |
| 327 | else |
| 328 | { |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 329 | if(border_mode == BorderMode::CONSTANT) |
| 330 | { |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 331 | *reinterpret_cast<T *>(out.ptr()) = border_value; |
Georgios Pinitas | fa7ad56 | 2018-05-15 17:38:40 +0100 | [diff] [blame] | 332 | } |
| 333 | else if(border_mode == BorderMode::REPLICATE) |
| 334 | { |
| 335 | auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1); |
| 336 | auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1); |
| 337 | *reinterpret_cast<T *>(out.ptr()) = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c); |
| 338 | } |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 339 | } |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 340 | }, |
| 341 | in, out); |
| 342 | } |
| 343 | } // namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 344 | |
| 345 | NEScaleKernel::NEScaleKernel() |
Manuel Bottini | f00d332 | 2019-03-05 15:53:25 +0000 | [diff] [blame] | 346 | : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_size(1), _border_mode(), _constant_border_value(PixelValue()), |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 347 | _sampling_offset(0), _use_padding(true), _align_corners(false) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 348 | { |
| 349 | } |
| 350 | |
| 351 | BorderSize NEScaleKernel::border_size() const |
| 352 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 353 | return _border_size; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 356 | void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 357 | ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 358 | bool use_padding, bool align_corners) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 359 | { |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 360 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 361 | // Perform validation step |
| 362 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), |
| 363 | dx != nullptr ? dx->info() : nullptr, |
| 364 | dy != nullptr ? dy->info() : nullptr, |
| 365 | offsets != nullptr ? offsets->info() : nullptr, |
| 366 | output->info(), |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 367 | policy, border_mode, constant_border_value, sampling_policy, use_padding, align_corners)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 368 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 369 | // Get data layout and width/height indices |
| 370 | const DataLayout data_layout = input->info()->data_layout(); |
| 371 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 372 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 373 | |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 374 | _input = input; |
| 375 | _output = output; |
| 376 | _offsets = offsets; |
| 377 | _dx = dx; |
| 378 | _dy = dy; |
| 379 | _policy = policy; |
| 380 | _border_size = BorderSize(1); |
| 381 | _border_mode = border_mode; |
| 382 | _constant_border_value = constant_border_value; |
| 383 | _use_padding = use_padding; |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 384 | _align_corners = _policy == InterpolationPolicy::BILINEAR |
| 385 | && sampling_policy == SamplingPolicy::TOP_LEFT |
| 386 | && align_corners; |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 387 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 388 | if(sampling_policy == SamplingPolicy::CENTER) |
| 389 | { |
| 390 | _sampling_offset = 0.5f; |
| 391 | } |
| 392 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 393 | // Compute the ratio between source width/height and destination width/height |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 394 | const auto wr = arm_compute::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), _align_corners); |
| 395 | const auto hr = arm_compute::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), _align_corners); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 396 | |
| 397 | // Add constant border only on top in case of NHWC layout |
| 398 | if(data_layout == DataLayout::NHWC) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 399 | { |
Michalis Spyrou | c050e0c | 2019-07-25 17:58:30 +0100 | [diff] [blame] | 400 | _border_size = (border_mode != BorderMode::REPLICATE && policy == InterpolationPolicy::BILINEAR && use_padding) ? BorderSize(1, 0, 0, 0) : BorderSize(0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 403 | // Area interpolation behaves as Nearest Neighbour in case of up-sampling |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 404 | if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) |
| 405 | { |
| 406 | policy = InterpolationPolicy::NEAREST_NEIGHBOR; |
| 407 | } |
| 408 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 409 | // Select interpolation function |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 410 | switch(policy) |
| 411 | { |
| 412 | case InterpolationPolicy::NEAREST_NEIGHBOR: |
| 413 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 414 | _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 415 | break; |
| 416 | } |
| 417 | case InterpolationPolicy::BILINEAR: |
| 418 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 419 | _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 420 | break; |
| 421 | } |
| 422 | case InterpolationPolicy::AREA: |
| 423 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 424 | _func = &NEScaleKernel::scale_area_nchw; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 425 | break; |
| 426 | } |
| 427 | default: |
| 428 | ARM_COMPUTE_ERROR("Unsupported interpolation mode"); |
| 429 | } |
| 430 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 431 | // Configure window |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 432 | std::pair<Status, Window> win_config = validate_and_configure_window(input->info(), |
| 433 | dx != nullptr ? dx->info() : nullptr, |
| 434 | dy != nullptr ? dy->info() : nullptr, |
| 435 | offsets != nullptr ? offsets->info() : nullptr, |
| 436 | output->info(), |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 437 | policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size(), use_padding); |
| 438 | |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 439 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
| 440 | INEKernel::configure(win_config.second); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 441 | } |
| 442 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 443 | void NEScaleKernel::scale_nearest_nchw(const Window &window) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 444 | { |
| 445 | const size_t input_stride = _input->info()->strides_in_bytes()[1]; |
| 446 | |
| 447 | // Compute the ratio between source height and destination height |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 448 | const auto hr = arm_compute::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 449 | |
| 450 | // Don't increment in X and Y direction for the input tensor |
| 451 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 452 | Window win_in(window); |
| 453 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 454 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 455 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 456 | // Set offsets window |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 457 | Window win_off; |
| 458 | win_off.set(Window::DimX, window[Window::DimX]); |
| 459 | win_off.set(Window::DimY, window[Window::DimY]); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 460 | for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d) |
| 461 | { |
| 462 | win_off.set(d, Window::Dimension(0, 0, 0)); |
| 463 | } |
| 464 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 465 | // Create iterators |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 466 | Iterator in(_input, win_in); |
| 467 | Iterator out(_output, window); |
| 468 | Iterator offsets(_offsets, win_off); |
| 469 | |
| 470 | switch(_input->info()->data_type()) |
| 471 | { |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 472 | case DataType::QASYMM8: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 473 | case DataType::U8: |
| 474 | { |
| 475 | uint8x16_t tmp = vdupq_n_u8(0); |
| 476 | |
| 477 | execute_window_loop(window, [&](const Coordinates & id) |
| 478 | { |
| 479 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 480 | const uint8_t *const in_ptr = in.ptr(); |
| 481 | |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 482 | const int in_yi = std::floor((id.y() + _sampling_offset) * hr); |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 483 | const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1)); |
| 484 | ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1))); |
| 485 | const int offset_row = in_yi_clamped * input_stride; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 486 | |
| 487 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0); |
| 488 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1); |
| 489 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2); |
| 490 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3); |
| 491 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4); |
| 492 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5); |
| 493 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6); |
| 494 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7); |
| 495 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8); |
| 496 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9); |
| 497 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10); |
| 498 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11); |
| 499 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12); |
| 500 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13); |
| 501 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14); |
| 502 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15); |
| 503 | |
| 504 | vst1q_u8(out.ptr(), tmp); |
| 505 | }, |
| 506 | in, offsets, out); |
| 507 | break; |
| 508 | } |
| 509 | case DataType::S16: |
| 510 | { |
| 511 | int16x8x2_t tmp = |
| 512 | { |
| 513 | { |
| 514 | vdupq_n_s16(0), |
| 515 | vdupq_n_s16(0) |
| 516 | } |
| 517 | }; |
| 518 | |
| 519 | execute_window_loop(window, [&](const Coordinates & id) |
| 520 | { |
| 521 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 522 | |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 523 | const int in_yi = std::floor((id.y() + _sampling_offset) * hr); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 524 | const int offset_row = in_yi * input_stride; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 525 | |
| 526 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); |
| 527 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1); |
| 528 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2); |
| 529 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3); |
| 530 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4); |
| 531 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5); |
| 532 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6); |
| 533 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7); |
| 534 | |
| 535 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0); |
| 536 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1); |
| 537 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2); |
| 538 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3); |
| 539 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4); |
| 540 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5); |
| 541 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6); |
| 542 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7); |
| 543 | |
| 544 | vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp); |
| 545 | }, |
| 546 | in, offsets, out); |
| 547 | break; |
| 548 | } |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 549 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 550 | case DataType::F16: |
| 551 | { |
| 552 | float16x8x2_t tmp = |
| 553 | { |
| 554 | { |
| 555 | vdupq_n_f16(0), |
| 556 | vdupq_n_f16(0) |
| 557 | } |
| 558 | }; |
| 559 | |
| 560 | execute_window_loop(window, [&](const Coordinates & id) |
| 561 | { |
| 562 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 563 | |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 564 | const int in_yi = std::floor((id.y() + _sampling_offset) * hr); |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 565 | const int offset_row = in_yi * input_stride; |
| 566 | |
| 567 | tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); |
| 568 | tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1); |
| 569 | tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2); |
| 570 | tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3); |
| 571 | tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4); |
| 572 | tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5); |
| 573 | tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6); |
| 574 | tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7); |
| 575 | |
| 576 | tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0); |
| 577 | tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1); |
| 578 | tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2); |
| 579 | tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3); |
| 580 | tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4); |
| 581 | tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5); |
| 582 | tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6); |
| 583 | tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7); |
| 584 | |
| 585 | vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp); |
| 586 | }, |
| 587 | in, offsets, out); |
| 588 | break; |
| 589 | } |
| 590 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 591 | case DataType::F32: |
| 592 | { |
| 593 | float32x4x4_t tmp = |
| 594 | { |
| 595 | { |
| 596 | vdupq_n_f32(0), |
| 597 | vdupq_n_f32(0), |
| 598 | vdupq_n_f32(0), |
| 599 | vdupq_n_f32(0) |
| 600 | } |
| 601 | }; |
| 602 | |
| 603 | execute_window_loop(window, [&](const Coordinates & id) |
| 604 | { |
| 605 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 606 | |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 607 | const int in_yi = std::floor((id.y() + _sampling_offset) * hr); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 608 | const int offset_row = in_yi * input_stride; |
| 609 | |
| 610 | tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); |
| 611 | tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1); |
| 612 | tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2); |
| 613 | tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3); |
| 614 | |
| 615 | tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0); |
| 616 | tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1); |
| 617 | tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2); |
| 618 | tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3); |
| 619 | |
| 620 | tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0); |
| 621 | tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1); |
| 622 | tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2); |
| 623 | tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3); |
| 624 | |
| 625 | tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0); |
| 626 | tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1); |
| 627 | tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2); |
| 628 | tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3); |
| 629 | |
| 630 | vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp); |
| 631 | }, |
| 632 | in, offsets, out); |
| 633 | break; |
| 634 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 635 | default: |
| 636 | ARM_COMPUTE_ERROR("Not supported"); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 640 | void NEScaleKernel::scale_bilinear_nchw(const Window &window) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 641 | { |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 642 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::F32); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 643 | |
| 644 | // Compute the ratio between source height and destination height |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 645 | const auto hr = arm_compute::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 646 | |
| 647 | // Don't increment in X and Y direction for the input tensor |
| 648 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 649 | Window win_in(window); |
| 650 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 651 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 652 | |
| 653 | Window win_off; |
| 654 | win_off.set(Window::DimX, window.x()); |
| 655 | win_off.set(Window::DimY, window.y()); |
| 656 | |
| 657 | for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d) |
| 658 | { |
| 659 | win_off.set(d, Window::Dimension(0, 0, 0)); |
| 660 | } |
| 661 | |
| 662 | Iterator in(_input, win_in); |
| 663 | Iterator out(_output, window); |
| 664 | Iterator offsets(_offsets, win_off); |
| 665 | Iterator dx(_dx, win_off); |
| 666 | Iterator dy(_dy, win_off); |
| 667 | |
| 668 | /* Input image stride */ |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 669 | const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1]; |
| 670 | const size_t in_stride = in_stide_in_bytes / _input->info()->element_size(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 671 | |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 672 | const bool is_quantized = (_input->info()->data_type() == DataType::QASYMM8); |
| 673 | const UniformQuantizationInfo iq_info = _input->info()->quantization_info().uniform(); |
| 674 | const UniformQuantizationInfo oq_info = _output->info()->quantization_info().uniform(); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 675 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 676 | switch(_input->info()->data_type()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 677 | { |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 678 | case DataType::QASYMM8: |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 679 | case DataType::U8: |
| 680 | { |
| 681 | execute_window_loop(window, [&](const Coordinates & id) |
| 682 | { |
| 683 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 684 | const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr()); |
| 685 | const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr()); |
| 686 | const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 687 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 688 | const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 689 | const int offset_row = in_yi * in_stide_in_bytes; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 690 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 691 | uint8x8_t tmp0 = vdup_n_u8(0); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 692 | if(is_quantized) |
| 693 | { |
| 694 | tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0], iq_info, oq_info), tmp0, 0); |
| 695 | tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1], iq_info, oq_info), tmp0, 1); |
| 696 | tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2], iq_info, oq_info), tmp0, 2); |
| 697 | tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3], iq_info, oq_info), tmp0, 3); |
| 698 | tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4], iq_info, oq_info), tmp0, 4); |
| 699 | tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5], iq_info, oq_info), tmp0, 5); |
| 700 | tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6], iq_info, oq_info), tmp0, 6); |
| 701 | tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7], iq_info, oq_info), tmp0, 7); |
| 702 | } |
| 703 | else |
| 704 | { |
| 705 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0); |
| 706 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1); |
| 707 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2); |
| 708 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3); |
| 709 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4); |
| 710 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5); |
| 711 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6); |
| 712 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7); |
| 713 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 714 | uint8x8_t tmp1 = vdup_n_u8(0); |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 715 | if(is_quantized) |
| 716 | { |
| 717 | tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8], iq_info, oq_info), tmp1, 0); |
| 718 | tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9], iq_info, oq_info), tmp1, 1); |
| 719 | tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10], iq_info, oq_info), tmp1, 2); |
| 720 | tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11], iq_info, oq_info), tmp1, 3); |
| 721 | tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12], iq_info, oq_info), tmp1, 4); |
| 722 | tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13], iq_info, oq_info), tmp1, 5); |
| 723 | tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14], iq_info, oq_info), tmp1, 6); |
| 724 | tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15], iq_info, oq_info), tmp1, 7); |
| 725 | } |
| 726 | else |
| 727 | { |
| 728 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0); |
| 729 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1); |
| 730 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2); |
| 731 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3); |
| 732 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4); |
| 733 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5); |
| 734 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6); |
| 735 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7); |
| 736 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 737 | vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1)); |
| 738 | }, |
| 739 | in, offsets, dx, dy, out); |
| 740 | break; |
| 741 | } |
| 742 | case DataType::S16: |
| 743 | { |
| 744 | execute_window_loop(window, [&](const Coordinates & id) |
| 745 | { |
| 746 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 747 | const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr()); |
| 748 | const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr()); |
| 749 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 750 | const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 751 | const int offset_row = in_yi * in_stide_in_bytes; |
| 752 | |
| 753 | int16x8x2_t tmp = |
| 754 | { |
| 755 | { |
| 756 | vdupq_n_s16(0), |
| 757 | vdupq_n_s16(0) |
| 758 | } |
| 759 | }; |
| 760 | |
| 761 | tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), in_stride, dx_ptr[0], dy_ptr[0]), tmp.val[0], 0); |
| 762 | tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), in_stride, dx_ptr[2], dy_ptr[2]), tmp.val[0], 1); |
| 763 | tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), in_stride, dx_ptr[4], dy_ptr[4]), tmp.val[0], 2); |
| 764 | tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), in_stride, dx_ptr[6], dy_ptr[6]), tmp.val[0], 3); |
| 765 | tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), in_stride, dx_ptr[8], dy_ptr[8]), tmp.val[0], 4); |
| 766 | tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), in_stride, dx_ptr[10], dy_ptr[10]), tmp.val[0], 5); |
| 767 | tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), in_stride, dx_ptr[12], dy_ptr[12]), tmp.val[0], 6); |
| 768 | tmp.val[0] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), in_stride, dx_ptr[14], dy_ptr[14]), tmp.val[0], 7); |
| 769 | |
| 770 | tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), in_stride, dx_ptr[1], dy_ptr[1]), tmp.val[1], 0); |
| 771 | tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), in_stride, dx_ptr[3], dy_ptr[3]), tmp.val[1], 1); |
| 772 | tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), in_stride, dx_ptr[5], dy_ptr[5]), tmp.val[1], 2); |
| 773 | tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), in_stride, dx_ptr[7], dy_ptr[7]), tmp.val[1], 3); |
| 774 | tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), in_stride, dx_ptr[9], dy_ptr[9]), tmp.val[1], 4); |
| 775 | tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), in_stride, dx_ptr[11], dy_ptr[11]), tmp.val[1], 5); |
| 776 | tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), in_stride, dx_ptr[13], dy_ptr[13]), tmp.val[1], 6); |
| 777 | tmp.val[1] = vsetq_lane_s16(delta_bilinear_c1(reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), in_stride, dx_ptr[15], dy_ptr[15]), tmp.val[1], 7); |
| 778 | |
| 779 | vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp); |
| 780 | }, |
| 781 | in, offsets, dx, dy, out); |
| 782 | break; |
| 783 | } |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 784 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 785 | case DataType::F16: |
| 786 | { |
| 787 | execute_window_loop(window, [&](const Coordinates & id) |
| 788 | { |
| 789 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 790 | const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr()); |
| 791 | const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr()); |
| 792 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 793 | const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset); |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 794 | const int offset_row = in_yi * in_stide_in_bytes; |
| 795 | |
| 796 | float16x8x2_t tmp = |
| 797 | { |
| 798 | { |
| 799 | vdupq_n_f16(0), |
| 800 | vdupq_n_f16(0) |
| 801 | } |
| 802 | }; |
| 803 | |
| 804 | tmp.val[0] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[0] + offset_row), in_stride, dx_ptr[0], dy_ptr[0]), tmp.val[0], 0); |
| 805 | tmp.val[0] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[2] + offset_row), in_stride, dx_ptr[2], dy_ptr[2]), tmp.val[0], 1); |
| 806 | tmp.val[0] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[4] + offset_row), in_stride, dx_ptr[4], dy_ptr[4]), tmp.val[0], 2); |
| 807 | tmp.val[0] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[6] + offset_row), in_stride, dx_ptr[6], dy_ptr[6]), tmp.val[0], 3); |
| 808 | tmp.val[0] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[8] + offset_row), in_stride, dx_ptr[8], dy_ptr[8]), tmp.val[0], 4); |
| 809 | tmp.val[0] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[10] + offset_row), in_stride, dx_ptr[10], dy_ptr[10]), tmp.val[0], 5); |
| 810 | tmp.val[0] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[12] + offset_row), in_stride, dx_ptr[12], dy_ptr[12]), tmp.val[0], 6); |
| 811 | tmp.val[0] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[14] + offset_row), in_stride, dx_ptr[14], dy_ptr[14]), tmp.val[0], 7); |
| 812 | |
| 813 | tmp.val[1] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[1] + offset_row), in_stride, dx_ptr[1], dy_ptr[1]), tmp.val[1], 0); |
| 814 | tmp.val[1] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[3] + offset_row), in_stride, dx_ptr[3], dy_ptr[3]), tmp.val[1], 1); |
| 815 | tmp.val[1] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[5] + offset_row), in_stride, dx_ptr[5], dy_ptr[5]), tmp.val[1], 2); |
| 816 | tmp.val[1] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[7] + offset_row), in_stride, dx_ptr[7], dy_ptr[7]), tmp.val[1], 3); |
| 817 | tmp.val[1] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[9] + offset_row), in_stride, dx_ptr[9], dy_ptr[9]), tmp.val[1], 4); |
| 818 | tmp.val[1] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[11] + offset_row), in_stride, dx_ptr[11], dy_ptr[11]), tmp.val[1], 5); |
| 819 | tmp.val[1] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[13] + offset_row), in_stride, dx_ptr[13], dy_ptr[13]), tmp.val[1], 6); |
| 820 | tmp.val[1] = vsetq_lane_f16(delta_bilinear_c1(reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[15] + offset_row), in_stride, dx_ptr[15], dy_ptr[15]), tmp.val[1], 7); |
| 821 | |
| 822 | vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp); |
| 823 | }, |
| 824 | in, offsets, dx, dy, out); |
| 825 | break; |
| 826 | } |
| 827 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 828 | case DataType::F32: |
| 829 | { |
| 830 | execute_window_loop(window, [&](const Coordinates & id) |
| 831 | { |
| 832 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 833 | const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr()); |
| 834 | const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr()); |
| 835 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 836 | const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 837 | const int offset_row = in_yi * in_stide_in_bytes; |
| 838 | |
| 839 | float32x4x4_t tmp = |
| 840 | { |
| 841 | { |
| 842 | vdupq_n_f32(0), |
| 843 | vdupq_n_f32(0), |
| 844 | vdupq_n_f32(0), |
| 845 | vdupq_n_f32(0) |
| 846 | } |
| 847 | }; |
| 848 | |
| 849 | tmp.val[0] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), in_stride, dx_ptr[0], dy_ptr[0]), tmp.val[0], 0); |
| 850 | tmp.val[0] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), in_stride, dx_ptr[4], dy_ptr[4]), tmp.val[0], 1); |
| 851 | tmp.val[0] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), in_stride, dx_ptr[8], dy_ptr[8]), tmp.val[0], 2); |
| 852 | tmp.val[0] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), in_stride, dx_ptr[12], dy_ptr[12]), tmp.val[0], 3); |
| 853 | |
| 854 | tmp.val[1] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), in_stride, dx_ptr[1], dy_ptr[1]), tmp.val[1], 0); |
| 855 | tmp.val[1] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), in_stride, dx_ptr[5], dy_ptr[5]), tmp.val[1], 1); |
| 856 | tmp.val[1] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), in_stride, dx_ptr[9], dy_ptr[9]), tmp.val[1], 2); |
| 857 | tmp.val[1] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), in_stride, dx_ptr[13], dy_ptr[13]), tmp.val[1], 3); |
| 858 | |
| 859 | tmp.val[2] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), in_stride, dx_ptr[2], dy_ptr[2]), tmp.val[2], 0); |
| 860 | tmp.val[2] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), in_stride, dx_ptr[6], dy_ptr[6]), tmp.val[2], 1); |
| 861 | tmp.val[2] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), in_stride, dx_ptr[10], dy_ptr[10]), tmp.val[2], 2); |
| 862 | tmp.val[2] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), in_stride, dx_ptr[14], dy_ptr[14]), tmp.val[2], 3); |
| 863 | |
| 864 | tmp.val[3] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), in_stride, dx_ptr[3], dy_ptr[3]), tmp.val[3], 0); |
| 865 | tmp.val[3] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), in_stride, dx_ptr[7], dy_ptr[7]), tmp.val[3], 1); |
| 866 | tmp.val[3] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), in_stride, dx_ptr[11], dy_ptr[11]), tmp.val[3], 2); |
| 867 | tmp.val[3] = vsetq_lane_f32(delta_bilinear_c1(reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), in_stride, dx_ptr[15], dy_ptr[15]), tmp.val[3], 3); |
| 868 | |
| 869 | vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp); |
| 870 | }, |
| 871 | in, offsets, dx, dy, out); |
| 872 | break; |
| 873 | } |
| 874 | default: |
| 875 | ARM_COMPUTE_ERROR("Not supported"); |
| 876 | break; |
| 877 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 878 | } |
| 879 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 880 | void NEScaleKernel::scale_area_nchw(const Window &window) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 881 | { |
| 882 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8); |
| 883 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 884 | // Don't increment in width/height/channels for the input tensor |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 885 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 886 | Window win_in(window); |
| 887 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 888 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 889 | win_in.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 890 | |
| 891 | Iterator in(_input, win_in); |
| 892 | Iterator out(_output, window); |
| 893 | |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 894 | const auto wr = arm_compute::calculate_resize_ratio(_input->info()->dimension(0), _output->info()->dimension(0), _align_corners); |
| 895 | const auto hr = arm_compute::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 896 | const auto w = _input->info()->dimension(0); |
| 897 | const auto h = _input->info()->dimension(1); |
| 898 | const size_t in_stride = _input->info()->strides_in_bytes()[1]; |
| 899 | |
| 900 | execute_window_loop(window, [&](const Coordinates & id) |
| 901 | { |
| 902 | const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr()); |
| 903 | |
| 904 | uint8x8_t tmp0 = vdup_n_u8(0); |
| 905 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0); |
| 906 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1); |
| 907 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2); |
| 908 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3); |
| 909 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4); |
| 910 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5); |
| 911 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6); |
| 912 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7); |
| 913 | |
| 914 | uint8x8_t tmp1 = vdup_n_u8(0); |
| 915 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0); |
| 916 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1); |
| 917 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2); |
| 918 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3); |
| 919 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4); |
| 920 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5); |
| 921 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6); |
| 922 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7); |
| 923 | |
| 924 | vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1)); |
| 925 | }, |
| 926 | in, out); |
| 927 | } |
| 928 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 929 | void NEScaleKernel::scale_nhwc(const Window &window) |
| 930 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 931 | // Get data layout and width/height indices |
Georgios Pinitas | a5eb591 | 2020-01-07 17:37:14 +0000 | [diff] [blame] | 932 | const DataLayout data_layout = DataLayout::NHWC; |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 933 | const int idx_channels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 934 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 935 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 936 | |
| 937 | const size_t input_stride_w = _input->info()->strides_in_bytes()[idx_width]; |
| 938 | const size_t input_stride_h = _input->info()->strides_in_bytes()[idx_height]; |
| 939 | const size_t input_stride_c = _input->info()->strides_in_bytes()[idx_channels]; |
| 940 | |
| 941 | // Compute the ratio between source height and destination height |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 942 | const auto hr = arm_compute::calculate_resize_ratio(_input->info()->dimension(idx_height), _output->info()->dimension(idx_height), _align_corners); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 943 | |
| 944 | // Don't increment in width/height/channels for the input tensor |
| 945 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 946 | Window win_in(window); |
| 947 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 948 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 949 | win_in.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
| 950 | |
| 951 | switch(_input->info()->data_type()) |
| 952 | { |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 953 | case DataType::QASYMM8: |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 954 | case DataType::U8: |
| 955 | { |
| 956 | if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 957 | { |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 958 | scale_nearest_nhwc_core<uint8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 959 | } |
| 960 | else |
| 961 | { |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 962 | scale_bilinear_nhwc_core<uint8_t, uint8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset, |
| 963 | window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 964 | } |
| 965 | break; |
| 966 | } |
| 967 | case DataType::S16: |
| 968 | { |
| 969 | if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 970 | { |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 971 | scale_nearest_nhwc_core<int16_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 972 | } |
| 973 | else |
| 974 | { |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 975 | scale_bilinear_nhwc_core<int16_t, int16_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset, |
| 976 | window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 977 | } |
| 978 | break; |
| 979 | } |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 980 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 981 | case DataType::F16: |
| 982 | { |
| 983 | if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 984 | { |
| 985 | scale_nearest_nhwc_core<float16_t>(_input, _offsets, _output, hr, |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 986 | window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset); |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 987 | } |
| 988 | else |
| 989 | { |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 990 | scale_bilinear_nhwc_core<float16_t, half>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset, |
| 991 | window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding); |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 992 | } |
| 993 | break; |
| 994 | } |
| 995 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 996 | case DataType::F32: |
| 997 | { |
| 998 | if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 999 | { |
Michalis Spyrou | d473386 | 2019-07-09 14:21:06 +0100 | [diff] [blame] | 1000 | scale_nearest_nhwc_core<float>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 1001 | } |
| 1002 | else |
| 1003 | { |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 1004 | scale_bilinear_nhwc_core<float, float>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset, |
| 1005 | window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 1006 | } |
| 1007 | break; |
| 1008 | } |
| 1009 | default: |
| 1010 | ARM_COMPUTE_ERROR("Not supported"); |
| 1011 | break; |
| 1012 | } |
| 1013 | } |
| 1014 | |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 1015 | Status NEScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, |
| 1016 | const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy, |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 1017 | BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding, bool align_corners) |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 1018 | { |
| 1019 | BorderSize border_size(1); |
| 1020 | if(input->data_layout() == DataLayout::NHWC) |
| 1021 | { |
| 1022 | border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0); |
| 1023 | } |
| 1024 | |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 1025 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, policy, border_mode, constant_border_value, sampling_policy, use_padding, align_corners)); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 1026 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), |
| 1027 | dx != nullptr ? dx->clone().get() : nullptr, |
| 1028 | dy != nullptr ? dy->clone().get() : nullptr, |
| 1029 | offsets != nullptr ? offsets->clone().get() : nullptr, |
| 1030 | output->clone().get(), |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 1031 | policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size, use_padding) |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 1032 | .first); |
| 1033 | |
| 1034 | return Status{}; |
| 1035 | } |
| 1036 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 1037 | void NEScaleKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1038 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 1039 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1040 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 1041 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 1042 | ARM_COMPUTE_ERROR_ON(_func == nullptr); |
| 1043 | |
| 1044 | (this->*_func)(window); |
| 1045 | } |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 1046 | } // namespace arm_compute |