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