Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Diego Lopez Recas | ff860cf | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 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" |
| 27 | #include "arm_compute/core/Coordinates.h" |
| 28 | #include "arm_compute/core/Error.h" |
| 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/ITensor.h" |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 31 | #include "arm_compute/core/NEON/wrapper/wrapper.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | #include "arm_compute/core/TensorInfo.h" |
| 33 | #include "arm_compute/core/Validate.h" |
| 34 | #include "arm_compute/core/Window.h" |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 35 | #include "arm_compute/core/utils/misc/Utility.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | |
| 37 | #include <arm_neon.h> |
| 38 | #include <cstddef> |
| 39 | #include <cstdint> |
| 40 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | Window configure_nchw(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output, |
| 46 | InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size) |
| 47 | { |
| 48 | constexpr unsigned int num_elems_processed_per_iteration = 16; |
| 49 | |
| 50 | // Configure kernel window |
| 51 | Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration)); |
| 52 | |
| 53 | const ValidRegion &input_valid_region = input->info()->valid_region(); |
| 54 | |
| 55 | // Reads can occur within the valid region of the input |
| 56 | AccessWindowStatic input_access(input->info(), input_valid_region.anchor[0] - border_size.left, |
| 57 | input_valid_region.anchor[1] - border_size.top, |
| 58 | input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size.right, |
| 59 | input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size.bottom); |
| 60 | AccessWindowHorizontal offsets_access(offsets == nullptr ? nullptr : offsets->info(), 0, |
| 61 | num_elems_processed_per_iteration); |
| 62 | AccessWindowHorizontal dx_access(dx == nullptr ? nullptr : dx->info(), 0, num_elems_processed_per_iteration); |
| 63 | AccessWindowHorizontal dy_access(dy == nullptr ? nullptr : dy->info(), 0, num_elems_processed_per_iteration); |
| 64 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration); |
| 65 | |
| 66 | update_window_and_padding(win, input_access, offsets_access, dx_access, dy_access, output_access); |
| 67 | |
| 68 | output_access.set_valid_region(win, calculate_valid_region_scale(*(input->info()), output->info()->tensor_shape(), |
| 69 | policy, sampling_policy, border_undefined)); |
| 70 | |
| 71 | return win; |
| 72 | } |
| 73 | Window configure_nhwc(const ITensor *input, ITensor *output, |
| 74 | InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size) |
| 75 | { |
| 76 | unsigned int num_elems_processed_per_iteration = (policy == InterpolationPolicy::NEAREST_NEIGHBOR) ? 16 / input->info()->element_size() : 1; |
| 77 | |
| 78 | // Configure kernel window |
| 79 | Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration)); |
| 80 | |
| 81 | AccessWindowStatic input_access(input->info(), 0, -border_size.top, |
| 82 | ceil_to_multiple(input->info()->tensor_shape()[0], num_elems_processed_per_iteration), |
| 83 | input->info()->tensor_shape()[1]); |
| 84 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration); |
| 85 | |
| 86 | update_window_and_padding(win, input_access, output_access); |
| 87 | output->info()->set_valid_region(calculate_valid_region_scale(*(input->info()), output->info()->tensor_shape(), |
| 88 | policy, sampling_policy, border_undefined)); |
| 89 | |
| 90 | return win; |
| 91 | } |
| 92 | |
| 93 | template <typename T> |
| 94 | inline void scale_nearest_nhwc_core(const ITensor *input, const ITensor *offsets, ITensor *output, |
| 95 | float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c) |
| 96 | { |
| 97 | Iterator in(input, win_in); |
| 98 | Iterator out(output, window); |
| 99 | |
| 100 | const size_t offsets_stride = stride_w / sizeof(T); |
| 101 | |
| 102 | execute_window_loop(window, [&](const Coordinates & id) |
| 103 | { |
| 104 | const auto offset = *reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z()))); |
| 105 | const int in_yi = (id.z() + 0.5f) * hr; |
| 106 | const int offset_row = in_yi * stride_h + id.x() * stride_c; |
| 107 | wrapper::vstore(reinterpret_cast<T *>(out.ptr()), |
| 108 | wrapper::vloadq(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row))); |
| 109 | }, |
| 110 | in, out); |
| 111 | } |
| 112 | |
| 113 | template <typename T> |
| 114 | inline void scale_bilinear_nhwc_core(const ITensor *input, const ITensor *offsets, const ITensor *dx, const ITensor *dy, ITensor *output, |
| 115 | float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c, BorderMode border_mode) |
| 116 | { |
| 117 | Iterator in(input, win_in); |
| 118 | Iterator out(output, window); |
| 119 | |
| 120 | const size_t stride_w_elems = stride_w / sizeof(T); |
| 121 | const size_t stride_h_elems = stride_h / sizeof(T); |
| 122 | |
| 123 | const size_t input_width = input->info()->dimension(1); |
| 124 | const size_t input_height = input->info()->dimension(2); |
| 125 | |
| 126 | const T *border_area = reinterpret_cast<T *>(input->buffer() + input->info()->offset_first_element_in_bytes() - stride_w); |
| 127 | |
| 128 | auto is_valid = [](int x, int low_x, int high_x, int y, int low_y, int high_y) |
| 129 | { |
| 130 | return !(x < low_x || x > high_x || y < low_y || y > high_y); |
| 131 | }; |
| 132 | |
| 133 | execute_window_loop(window, [&](const Coordinates & id) |
| 134 | { |
| 135 | const auto offset = (*reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z())))) / sizeof(T); |
| 136 | const auto dx_scale = *reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id.y(), id.z()))); |
| 137 | const auto dy_scale = *reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id.y(), id.z()))); |
| 138 | const int in_yi = std::floor((id.z() + 0.5f) * hr - 0.5f); |
| 139 | const int offset_row = in_yi * stride_h + id.x() * stride_c; |
| 140 | const T *in_ptr = reinterpret_cast<T *>(in.ptr() + offset * stride_w + offset_row); |
| 141 | |
| 142 | T a00 = 0, a01 = 0, a10 = 0, a11 = 0; |
| 143 | |
| 144 | if(border_mode == BorderMode::CONSTANT) |
| 145 | { |
| 146 | a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : *border_area; |
| 147 | a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : *border_area; |
| 148 | a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : *border_area; |
| 149 | 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_area; |
| 150 | } |
| 151 | else if(border_mode == BorderMode::REPLICATE) |
| 152 | { |
| 153 | auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1); |
| 154 | auto clamped_x1 = utility::clamp<int>(offset + 1, 0, input_width - 1); |
| 155 | auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1); |
| 156 | auto clamped_y1 = utility::clamp<int>(in_yi + 1, 0, input_height - 1); |
| 157 | |
| 158 | a00 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c); |
| 159 | a01 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y * stride_h + id.x() * stride_c); |
| 160 | a10 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y1 * stride_h + id.x() * stride_c); |
| 161 | a11 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y1 * stride_h + id.x() * stride_c); |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | a00 = *in_ptr; |
| 166 | a01 = *(in_ptr + stride_w_elems); |
| 167 | a10 = *(in_ptr + stride_h_elems); |
| 168 | a11 = *(in_ptr + stride_h_elems + stride_w_elems); |
| 169 | } |
| 170 | |
| 171 | // Perform interpolation |
| 172 | const float dx1 = 1.0f - dx_scale; |
| 173 | const float dy1 = 1.0f - dy_scale; |
| 174 | |
| 175 | const float w1 = dx1 * dy1; |
| 176 | const float w2 = dx_scale * dy1; |
| 177 | const float w3 = dx1 * dy_scale; |
| 178 | const float w4 = dx_scale * dy_scale; |
| 179 | |
| 180 | // Store result |
| 181 | *reinterpret_cast<T *>(out.ptr()) = static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4); |
| 182 | }, |
| 183 | in, out); |
| 184 | } |
| 185 | } // namespace |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 186 | |
| 187 | NEScaleKernel::NEScaleKernel() |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 188 | : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_size(1), _border_mode() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 189 | { |
| 190 | } |
| 191 | |
| 192 | BorderSize NEScaleKernel::border_size() const |
| 193 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 194 | return _border_size; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 197 | void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, |
| 198 | ITensor *output, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 199 | { |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 200 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16, DataType::F32); |
| 201 | ARM_COMPUTE_ERROR_ON_NULLPTR(output); |
| 202 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 203 | ARM_COMPUTE_ERROR_ON(output == input); |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 204 | ARM_COMPUTE_ERROR_ON(sampling_policy != SamplingPolicy::CENTER); |
| 205 | ARM_COMPUTE_UNUSED(sampling_policy); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 206 | |
| 207 | if(policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 208 | { |
| 209 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32); |
| 210 | } |
| 211 | |
| 212 | if(policy == InterpolationPolicy::BILINEAR) |
| 213 | { |
| 214 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32); |
| 215 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32); |
| 216 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32); |
| 217 | } |
| 218 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 219 | // Get data layout and width/height indices |
| 220 | const DataLayout data_layout = input->info()->data_layout(); |
| 221 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 222 | 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] | 223 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 224 | ARM_COMPUTE_ERROR_ON(output->info()->dimension(idx_width) == 0); |
| 225 | ARM_COMPUTE_ERROR_ON(output->info()->dimension(idx_height) == 0); |
| 226 | |
| 227 | _input = input; |
| 228 | _output = output; |
| 229 | _offsets = offsets; |
| 230 | _dx = dx; |
| 231 | _dy = dy; |
| 232 | _policy = policy; |
| 233 | _border_size = BorderSize(1); |
| 234 | _border_mode = border_mode; |
| 235 | |
| 236 | // Compute the ratio between source width/height and destination width/height |
| 237 | const auto wr = static_cast<float>(input->info()->dimension(idx_width)) / static_cast<float>(output->info()->dimension(idx_width)); |
| 238 | const auto hr = static_cast<float>(input->info()->dimension(idx_height)) / static_cast<float>(output->info()->dimension(idx_height)); |
| 239 | |
| 240 | // Add constant border only on top in case of NHWC layout |
| 241 | if(data_layout == DataLayout::NHWC) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 242 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 243 | _border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 246 | // Area interpolation behaves as Nearest Neighbour in case of up-sampling |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 247 | if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) |
| 248 | { |
| 249 | policy = InterpolationPolicy::NEAREST_NEIGHBOR; |
| 250 | } |
| 251 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 252 | // Select interpolation function |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 253 | switch(policy) |
| 254 | { |
| 255 | case InterpolationPolicy::NEAREST_NEIGHBOR: |
| 256 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 257 | _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 258 | break; |
| 259 | } |
| 260 | case InterpolationPolicy::BILINEAR: |
| 261 | { |
| 262 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_dx, 1, DataType::F32); |
| 263 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_dy, 1, DataType::F32); |
| 264 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 265 | _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 266 | break; |
| 267 | } |
| 268 | case InterpolationPolicy::AREA: |
| 269 | { |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 270 | ARM_COMPUTE_ERROR_ON(data_layout != DataLayout::NCHW); |
| 271 | |
| 272 | _func = &NEScaleKernel::scale_area_nchw; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 273 | break; |
| 274 | } |
| 275 | default: |
| 276 | ARM_COMPUTE_ERROR("Unsupported interpolation mode"); |
| 277 | } |
| 278 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 279 | // Configure window |
| 280 | Window win{}; |
| 281 | switch(data_layout) |
| 282 | { |
| 283 | case DataLayout::NCHW: |
| 284 | win = configure_nchw(input, dx, dy, offsets, output, policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size()); |
| 285 | break; |
| 286 | case DataLayout::NHWC: |
| 287 | win = configure_nhwc(input, output, policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size()); |
| 288 | break; |
| 289 | default: |
| 290 | ARM_COMPUTE_ERROR("Unsupported data layout"); |
| 291 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 292 | INEKernel::configure(win); |
| 293 | } |
| 294 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 295 | void NEScaleKernel::scale_nearest_nchw(const Window &window) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 296 | { |
| 297 | const size_t input_stride = _input->info()->strides_in_bytes()[1]; |
| 298 | |
| 299 | // Compute the ratio between source height and destination height |
| 300 | const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1)); |
| 301 | |
| 302 | // Don't increment in X and Y direction for the input tensor |
| 303 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 304 | Window win_in(window); |
| 305 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 306 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 307 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 308 | // Set offsets window |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 309 | Window win_off; |
| 310 | win_off.set(Window::DimX, window[Window::DimX]); |
| 311 | win_off.set(Window::DimY, window[Window::DimY]); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 312 | for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d) |
| 313 | { |
| 314 | win_off.set(d, Window::Dimension(0, 0, 0)); |
| 315 | } |
| 316 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 317 | // Create iterators |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 318 | Iterator in(_input, win_in); |
| 319 | Iterator out(_output, window); |
| 320 | Iterator offsets(_offsets, win_off); |
| 321 | |
| 322 | switch(_input->info()->data_type()) |
| 323 | { |
| 324 | case DataType::U8: |
| 325 | { |
| 326 | uint8x16_t tmp = vdupq_n_u8(0); |
| 327 | |
| 328 | execute_window_loop(window, [&](const Coordinates & id) |
| 329 | { |
| 330 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 331 | const uint8_t *const in_ptr = in.ptr(); |
| 332 | |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 333 | const int in_yi = std::floor((id.y() + 0.5f) * hr); |
| 334 | const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1)); |
| 335 | ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1))); |
| 336 | const int offset_row = in_yi_clamped * input_stride; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 337 | |
| 338 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0); |
| 339 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1); |
| 340 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2); |
| 341 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3); |
| 342 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4); |
| 343 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5); |
| 344 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6); |
| 345 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7); |
| 346 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8); |
| 347 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9); |
| 348 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10); |
| 349 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11); |
| 350 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12); |
| 351 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13); |
| 352 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14); |
| 353 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15); |
| 354 | |
| 355 | vst1q_u8(out.ptr(), tmp); |
| 356 | }, |
| 357 | in, offsets, out); |
| 358 | break; |
| 359 | } |
| 360 | case DataType::S16: |
| 361 | { |
| 362 | int16x8x2_t tmp = |
| 363 | { |
| 364 | { |
| 365 | vdupq_n_s16(0), |
| 366 | vdupq_n_s16(0) |
| 367 | } |
| 368 | }; |
| 369 | |
| 370 | execute_window_loop(window, [&](const Coordinates & id) |
| 371 | { |
| 372 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 373 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 374 | const int in_yi = (id.y() + 0.5f) * hr; |
| 375 | const int offset_row = in_yi * input_stride; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 376 | |
| 377 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); |
| 378 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1); |
| 379 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2); |
| 380 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3); |
| 381 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4); |
| 382 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5); |
| 383 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6); |
| 384 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7); |
| 385 | |
| 386 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0); |
| 387 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1); |
| 388 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2); |
| 389 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3); |
| 390 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4); |
| 391 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5); |
| 392 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6); |
| 393 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7); |
| 394 | |
| 395 | vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp); |
| 396 | }, |
| 397 | in, offsets, out); |
| 398 | break; |
| 399 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 400 | case DataType::F32: |
| 401 | { |
| 402 | float32x4x4_t tmp = |
| 403 | { |
| 404 | { |
| 405 | vdupq_n_f32(0), |
| 406 | vdupq_n_f32(0), |
| 407 | vdupq_n_f32(0), |
| 408 | vdupq_n_f32(0) |
| 409 | } |
| 410 | }; |
| 411 | |
| 412 | execute_window_loop(window, [&](const Coordinates & id) |
| 413 | { |
| 414 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 415 | |
| 416 | const int in_yi = (id.y() + 0.5f) * hr; |
| 417 | const int offset_row = in_yi * input_stride; |
| 418 | |
| 419 | tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); |
| 420 | tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1); |
| 421 | tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2); |
| 422 | tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3); |
| 423 | |
| 424 | tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0); |
| 425 | tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1); |
| 426 | tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2); |
| 427 | tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3); |
| 428 | |
| 429 | tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0); |
| 430 | tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1); |
| 431 | tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2); |
| 432 | tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3); |
| 433 | |
| 434 | tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0); |
| 435 | tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1); |
| 436 | tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2); |
| 437 | tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3); |
| 438 | |
| 439 | vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp); |
| 440 | }, |
| 441 | in, offsets, out); |
| 442 | break; |
| 443 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 444 | default: |
| 445 | ARM_COMPUTE_ERROR("Not supported"); |
| 446 | break; |
| 447 | } |
| 448 | } |
| 449 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 450 | void NEScaleKernel::scale_bilinear_nchw(const Window &window) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 451 | { |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 452 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::S16, DataType::F32); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 453 | |
| 454 | // Compute the ratio between source height and destination height |
| 455 | const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1)); |
| 456 | |
| 457 | // Don't increment in X and Y direction for the input tensor |
| 458 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 459 | Window win_in(window); |
| 460 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 461 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 462 | |
| 463 | Window win_off; |
| 464 | win_off.set(Window::DimX, window.x()); |
| 465 | win_off.set(Window::DimY, window.y()); |
| 466 | |
| 467 | for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d) |
| 468 | { |
| 469 | win_off.set(d, Window::Dimension(0, 0, 0)); |
| 470 | } |
| 471 | |
| 472 | Iterator in(_input, win_in); |
| 473 | Iterator out(_output, window); |
| 474 | Iterator offsets(_offsets, win_off); |
| 475 | Iterator dx(_dx, win_off); |
| 476 | Iterator dy(_dy, win_off); |
| 477 | |
| 478 | /* Input image stride */ |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 479 | const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1]; |
| 480 | 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] | 481 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 482 | switch(_input->info()->data_type()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 483 | { |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 484 | case DataType::U8: |
| 485 | { |
| 486 | execute_window_loop(window, [&](const Coordinates & id) |
| 487 | { |
| 488 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 489 | const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr()); |
| 490 | const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr()); |
| 491 | const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 492 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 493 | const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f); |
| 494 | const int offset_row = in_yi * in_stide_in_bytes; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 495 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 496 | uint8x8_t tmp0 = vdup_n_u8(0); |
| 497 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0); |
| 498 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1); |
| 499 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2); |
| 500 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3); |
| 501 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4); |
| 502 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5); |
| 503 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6); |
| 504 | tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 505 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 506 | uint8x8_t tmp1 = vdup_n_u8(0); |
| 507 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0); |
| 508 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1); |
| 509 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2); |
| 510 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3); |
| 511 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4); |
| 512 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5); |
| 513 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6); |
| 514 | tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 515 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 516 | vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1)); |
| 517 | }, |
| 518 | in, offsets, dx, dy, out); |
| 519 | break; |
| 520 | } |
| 521 | case DataType::S16: |
| 522 | { |
| 523 | execute_window_loop(window, [&](const Coordinates & id) |
| 524 | { |
| 525 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 526 | const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr()); |
| 527 | const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr()); |
| 528 | |
| 529 | const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f); |
| 530 | const int offset_row = in_yi * in_stide_in_bytes; |
| 531 | |
| 532 | int16x8x2_t tmp = |
| 533 | { |
| 534 | { |
| 535 | vdupq_n_s16(0), |
| 536 | vdupq_n_s16(0) |
| 537 | } |
| 538 | }; |
| 539 | |
| 540 | 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); |
| 541 | 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); |
| 542 | 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); |
| 543 | 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); |
| 544 | 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); |
| 545 | 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); |
| 546 | 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); |
| 547 | 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); |
| 548 | |
| 549 | 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); |
| 550 | 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); |
| 551 | 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); |
| 552 | 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); |
| 553 | 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); |
| 554 | 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); |
| 555 | 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); |
| 556 | 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); |
| 557 | |
| 558 | vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp); |
| 559 | }, |
| 560 | in, offsets, dx, dy, out); |
| 561 | break; |
| 562 | } |
| 563 | case DataType::F32: |
| 564 | { |
| 565 | execute_window_loop(window, [&](const Coordinates & id) |
| 566 | { |
| 567 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 568 | const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr()); |
| 569 | const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr()); |
| 570 | |
| 571 | const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f); |
| 572 | const int offset_row = in_yi * in_stide_in_bytes; |
| 573 | |
| 574 | float32x4x4_t tmp = |
| 575 | { |
| 576 | { |
| 577 | vdupq_n_f32(0), |
| 578 | vdupq_n_f32(0), |
| 579 | vdupq_n_f32(0), |
| 580 | vdupq_n_f32(0) |
| 581 | } |
| 582 | }; |
| 583 | |
| 584 | 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); |
| 585 | 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); |
| 586 | 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); |
| 587 | 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); |
| 588 | |
| 589 | 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); |
| 590 | 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); |
| 591 | 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); |
| 592 | 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); |
| 593 | |
| 594 | 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); |
| 595 | 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); |
| 596 | 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); |
| 597 | 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); |
| 598 | |
| 599 | 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); |
| 600 | 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); |
| 601 | 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); |
| 602 | 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); |
| 603 | |
| 604 | vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp); |
| 605 | }, |
| 606 | in, offsets, dx, dy, out); |
| 607 | break; |
| 608 | } |
| 609 | default: |
| 610 | ARM_COMPUTE_ERROR("Not supported"); |
| 611 | break; |
| 612 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 613 | } |
| 614 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 615 | void NEScaleKernel::scale_area_nchw(const Window &window) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 616 | { |
| 617 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8); |
| 618 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 619 | // Don't increment in width/height/channels for the input tensor |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 620 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 621 | Window win_in(window); |
| 622 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 623 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 624 | win_in.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 625 | |
| 626 | Iterator in(_input, win_in); |
| 627 | Iterator out(_output, window); |
| 628 | |
| 629 | const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0)); |
| 630 | const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1)); |
| 631 | const auto w = _input->info()->dimension(0); |
| 632 | const auto h = _input->info()->dimension(1); |
| 633 | const size_t in_stride = _input->info()->strides_in_bytes()[1]; |
| 634 | |
| 635 | execute_window_loop(window, [&](const Coordinates & id) |
| 636 | { |
| 637 | const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr()); |
| 638 | |
| 639 | uint8x8_t tmp0 = vdup_n_u8(0); |
| 640 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0); |
| 641 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1); |
| 642 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2); |
| 643 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3); |
| 644 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4); |
| 645 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5); |
| 646 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6); |
| 647 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7); |
| 648 | |
| 649 | uint8x8_t tmp1 = vdup_n_u8(0); |
| 650 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0); |
| 651 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1); |
| 652 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2); |
| 653 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3); |
| 654 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4); |
| 655 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5); |
| 656 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6); |
| 657 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7); |
| 658 | |
| 659 | vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1)); |
| 660 | }, |
| 661 | in, out); |
| 662 | } |
| 663 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 664 | void NEScaleKernel::scale_nhwc(const Window &window) |
| 665 | { |
| 666 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::S16, DataType::F32); |
| 667 | |
| 668 | // Get data layout and width/height indices |
| 669 | const DataLayout data_layout = _input->info()->data_layout(); |
| 670 | const int idx_channels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 671 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 672 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 673 | |
| 674 | const size_t input_stride_w = _input->info()->strides_in_bytes()[idx_width]; |
| 675 | const size_t input_stride_h = _input->info()->strides_in_bytes()[idx_height]; |
| 676 | const size_t input_stride_c = _input->info()->strides_in_bytes()[idx_channels]; |
| 677 | |
| 678 | // Compute the ratio between source height and destination height |
| 679 | const auto hr = static_cast<float>(_input->info()->dimension(idx_height)) / static_cast<float>(_output->info()->dimension(idx_height)); |
| 680 | |
| 681 | // Don't increment in width/height/channels for the input tensor |
| 682 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 683 | Window win_in(window); |
| 684 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 685 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 686 | win_in.set(Window::DimZ, Window::Dimension(0, 0, 0)); |
| 687 | |
| 688 | switch(_input->info()->data_type()) |
| 689 | { |
| 690 | case DataType::U8: |
| 691 | { |
| 692 | if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 693 | { |
| 694 | scale_nearest_nhwc_core<uint8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c); |
| 695 | } |
| 696 | else |
| 697 | { |
| 698 | scale_bilinear_nhwc_core<uint8_t>(_input, _offsets, _dx, _dy, _output, hr, |
| 699 | window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode); |
| 700 | } |
| 701 | break; |
| 702 | } |
| 703 | case DataType::S16: |
| 704 | { |
| 705 | if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 706 | { |
| 707 | scale_nearest_nhwc_core<int16_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c); |
| 708 | } |
| 709 | else |
| 710 | { |
| 711 | scale_bilinear_nhwc_core<int16_t>(_input, _offsets, _dx, _dy, _output, hr, |
| 712 | window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode); |
| 713 | } |
| 714 | break; |
| 715 | } |
| 716 | case DataType::F32: |
| 717 | { |
| 718 | if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 719 | { |
| 720 | scale_nearest_nhwc_core<float>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c); |
| 721 | } |
| 722 | else |
| 723 | { |
| 724 | scale_bilinear_nhwc_core<float>(_input, _offsets, _dx, _dy, _output, hr, |
| 725 | window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode); |
| 726 | } |
| 727 | break; |
| 728 | } |
| 729 | default: |
| 730 | ARM_COMPUTE_ERROR("Not supported"); |
| 731 | break; |
| 732 | } |
| 733 | } |
| 734 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 735 | void NEScaleKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 736 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 737 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 738 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 739 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 740 | ARM_COMPUTE_ERROR_ON(_func == nullptr); |
| 741 | |
| 742 | (this->*_func)(window); |
| 743 | } |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 744 | } // namespace arm_compute |