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