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