blob: 3d300ef26bd8ec55c4186f3a5e5cd2db3507f543 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +00002 * Copyright (c) 2016-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Pinitasc47ef202018-11-16 18:19:43 +000027#include "arm_compute/core/CPP/Validate.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028#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 Pinitas393fa4c2018-05-08 15:54:53 +010032#include "arm_compute/core/NEON/wrapper/wrapper.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033#include "arm_compute/core/TensorInfo.h"
34#include "arm_compute/core/Validate.h"
35#include "arm_compute/core/Window.h"
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010036#include "arm_compute/core/utils/misc/Utility.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037
38#include <arm_neon.h>
39#include <cstddef>
40#include <cstdint>
41
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010042namespace arm_compute
43{
44namespace
45{
Georgios Pinitas20b43132018-05-14 16:05:23 +010046Status 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 Pinitas393fa4c2018-05-08 15:54:53 +010049{
Georgios Pinitasc47ef202018-11-16 18:19:43 +000050 ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +000051 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16, DataType::F16, DataType::F32, DataType::QASYMM8);
Georgios Pinitas20b43132018-05-14 16:05:23 +010052 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
53 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
54 ARM_COMPUTE_RETURN_ERROR_ON(output == input);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +000055 ARM_COMPUTE_RETURN_ERROR_ON(sampling_policy != SamplingPolicy::CENTER && sampling_policy != SamplingPolicy::TOP_LEFT);
Georgios Pinitas20b43132018-05-14 16:05:23 +010056 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);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +000077 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
Georgios Pinitas20b43132018-05-14 16:05:23 +010078 }
79
80 return Status{};
81}
82
83std::pair<Status, Window> validate_and_configure_window_nchw(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output,
84 InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size)
85{
86 bool window_changed{ false };
87 Window win{};
88
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010089 constexpr unsigned int num_elems_processed_per_iteration = 16;
90
91 // Configure kernel window
Georgios Pinitas20b43132018-05-14 16:05:23 +010092 win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010093
Georgios Pinitas20b43132018-05-14 16:05:23 +010094 const ValidRegion &input_valid_region = input->valid_region();
95
96 if(offsets != nullptr)
97 {
98 AccessWindowHorizontal offsets_access(offsets, 0, num_elems_processed_per_iteration);
99 window_changed = window_changed || update_window_and_padding(win, offsets_access);
100 }
101 if(dx != nullptr && dy != nullptr)
102 {
103 AccessWindowHorizontal dx_access(dx, 0, num_elems_processed_per_iteration);
104 AccessWindowHorizontal dy_access(dy, 0, num_elems_processed_per_iteration);
105 window_changed = window_changed || update_window_and_padding(win, dx_access, dy_access);
106 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100107
108 // Reads can occur within the valid region of the input
Georgios Pinitas20b43132018-05-14 16:05:23 +0100109 AccessWindowStatic input_access(input, input_valid_region.anchor[0] - border_size.left,
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100110 input_valid_region.anchor[1] - border_size.top,
111 input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size.right,
112 input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size.bottom);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100113 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
114 window_changed = window_changed || update_window_and_padding(win, input_access, output_access);
115 output_access.set_valid_region(win, calculate_valid_region_scale(*input, output->tensor_shape(),
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100116 policy, sampling_policy, border_undefined));
117
Georgios Pinitas20b43132018-05-14 16:05:23 +0100118 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
119 return std::make_pair(err, win);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100120}
Georgios Pinitas20b43132018-05-14 16:05:23 +0100121
122std::pair<Status, Window> validate_and_configure_window_nhwc(ITensorInfo *input, ITensorInfo *output,
123 InterpolationPolicy policy, bool border_undefined,
124 SamplingPolicy sampling_policy, BorderSize border_size)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100125{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100126 bool window_changed{ false };
127 Window win{};
128
129 const unsigned int num_elems_processed_per_iteration = (policy == InterpolationPolicy::NEAREST_NEIGHBOR) ? 16 / input->element_size() : 1;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100130
131 // Configure kernel window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100132 win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100133
Georgios Pinitas20b43132018-05-14 16:05:23 +0100134 AccessWindowStatic input_access(input, 0, -border_size.top,
135 ceil_to_multiple(input->tensor_shape()[0], num_elems_processed_per_iteration),
136 input->tensor_shape()[1]);
137 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100138
Georgios Pinitas20b43132018-05-14 16:05:23 +0100139 window_changed = update_window_and_padding(win, input_access, output_access);
140 output->set_valid_region(calculate_valid_region_scale(*input, output->tensor_shape(),
141 policy, sampling_policy, border_undefined));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100142
Georgios Pinitas20b43132018-05-14 16:05:23 +0100143 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
144 return std::make_pair(err, win);
145}
146
147std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output,
148 InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size)
149{
150 std::pair<Status, Window> win_config;
151 switch(input->data_layout())
152 {
153 case DataLayout::NCHW:
154 win_config = validate_and_configure_window_nchw(input, dx, dy, offsets, output, policy, border_undefined, sampling_policy, border_size);
155 break;
156 case DataLayout::NHWC:
157 win_config = validate_and_configure_window_nhwc(input, output, policy, border_undefined, sampling_policy, border_size);
158 break;
159 default:
160 win_config = std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported data layout!"), Window{});
161 }
162
163 return win_config;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100164}
165
166template <typename T>
167inline void scale_nearest_nhwc_core(const ITensor *input, const ITensor *offsets, ITensor *output,
168 float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c)
169{
170 Iterator in(input, win_in);
171 Iterator out(output, window);
172
173 const size_t offsets_stride = stride_w / sizeof(T);
174
175 execute_window_loop(window, [&](const Coordinates & id)
176 {
177 const auto offset = *reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z())));
178 const int in_yi = (id.z() + 0.5f) * hr;
179 const int offset_row = in_yi * stride_h + id.x() * stride_c;
180 wrapper::vstore(reinterpret_cast<T *>(out.ptr()),
181 wrapper::vloadq(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row)));
182 },
183 in, out);
184}
185
186template <typename T>
187inline void scale_bilinear_nhwc_core(const ITensor *input, const ITensor *offsets, const ITensor *dx, const ITensor *dy, ITensor *output,
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000188 float hr, float sampling_offset, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c, BorderMode border_mode)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100189{
190 Iterator in(input, win_in);
191 Iterator out(output, window);
192
193 const size_t stride_w_elems = stride_w / sizeof(T);
194 const size_t stride_h_elems = stride_h / sizeof(T);
195
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100196 const int input_width = input->info()->dimension(1);
197 const int input_height = input->info()->dimension(2);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100198
199 const T *border_area = reinterpret_cast<T *>(input->buffer() + input->info()->offset_first_element_in_bytes() - stride_w);
200
201 auto is_valid = [](int x, int low_x, int high_x, int y, int low_y, int high_y)
202 {
203 return !(x < low_x || x > high_x || y < low_y || y > high_y);
204 };
205
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100206 int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1;
207
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000208 const bool is_quantized = (input->info()->data_type() == DataType::QASYMM8);
209 const QuantizationInfo iq_info = input->info()->quantization_info();
210 const QuantizationInfo oq_info = output->info()->quantization_info();
211
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100212 execute_window_loop(window, [&](const Coordinates & id)
213 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100214 const auto offset = (*reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z())))) / static_cast<int>(sizeof(T));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100215 const auto dx_scale = *reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id.y(), id.z())));
216 const auto dy_scale = *reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id.y(), id.z())));
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000217 const int in_yi = std::floor((id.z() + sampling_offset) * hr - sampling_offset);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100218 const int offset_row = in_yi * stride_h + id.x() * stride_c;
219 const T *in_ptr = reinterpret_cast<T *>(in.ptr() + offset * stride_w + offset_row);
220
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100221 if(is_valid(offset, -border_size, input_width - 1 + border_size, in_yi, -border_size, input_height - 1 + border_size))
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100222 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100223 T a00 = 0, a01 = 0, a10 = 0, a11 = 0;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100224
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100225 if(border_mode == BorderMode::CONSTANT)
226 {
227 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : *border_area;
228 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : *border_area;
229 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : *border_area;
230 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;
231 }
232 else if(border_mode == BorderMode::REPLICATE)
233 {
234 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
235 auto clamped_x1 = utility::clamp<int>(offset + 1, 0, input_width - 1);
236 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
237 auto clamped_y1 = utility::clamp<int>(in_yi + 1, 0, input_height - 1);
238
239 a00 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
240 a01 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y * stride_h + id.x() * stride_c);
241 a10 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
242 a11 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
243 }
244 else
245 {
246 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : 0;
247 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : 0;
248 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : 0;
249 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;
250 }
251
252 // Perform interpolation
253 const float dx1 = 1.0f - dx_scale;
254 const float dy1 = 1.0f - dy_scale;
255
256 const float w1 = dx1 * dy1;
257 const float w2 = dx_scale * dy1;
258 const float w3 = dx1 * dy_scale;
259 const float w4 = dx_scale * dy_scale;
260
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000261 T res = 0;
262 //dequantize quantized input
263 if(is_quantized)
264 {
265 float inp00 = iq_info.dequantize(a00);
266 float inp01 = iq_info.dequantize(a01);
267 float inp10 = iq_info.dequantize(a10);
268 float inp11 = iq_info.dequantize(a11);
269 res = static_cast<T>(oq_info.quantize((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), RoundingPolicy::TO_NEAREST_UP));
270 }
271 else
272 {
273 res = static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4);
274 }
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100275 // Store result
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000276 *reinterpret_cast<T *>(out.ptr()) = res;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100277 }
278 else
279 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100280 if(border_mode == BorderMode::CONSTANT)
281 {
282 *reinterpret_cast<T *>(out.ptr()) = *border_area;
283 }
284 else if(border_mode == BorderMode::REPLICATE)
285 {
286 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
287 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
288 *reinterpret_cast<T *>(out.ptr()) = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
289 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100290 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100291 },
292 in, out);
293}
294} // namespace
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100295
296NEScaleKernel::NEScaleKernel()
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000297 : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_size(1), _border_mode(), _sampling_offset(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100298{
299}
300
301BorderSize NEScaleKernel::border_size() const
302{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100303 return _border_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100304}
305
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100306void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets,
307 ITensor *output, InterpolationPolicy policy, BorderMode border_mode, SamplingPolicy sampling_policy)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100308{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100309 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100310
Georgios Pinitas20b43132018-05-14 16:05:23 +0100311 // Perform validation step
312 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
313 dx != nullptr ? dx->info() : nullptr,
314 dy != nullptr ? dy->info() : nullptr,
315 offsets != nullptr ? offsets->info() : nullptr,
316 output->info(),
317 policy, border_mode, sampling_policy));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100318
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100319 // Get data layout and width/height indices
320 const DataLayout data_layout = input->info()->data_layout();
321 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
322 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100323
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100324 _input = input;
325 _output = output;
326 _offsets = offsets;
327 _dx = dx;
328 _dy = dy;
329 _policy = policy;
330 _border_size = BorderSize(1);
331 _border_mode = border_mode;
332
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000333 if(sampling_policy == SamplingPolicy::CENTER)
334 {
335 _sampling_offset = 0.5f;
336 }
337
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100338 // Compute the ratio between source width/height and destination width/height
339 const auto wr = static_cast<float>(input->info()->dimension(idx_width)) / static_cast<float>(output->info()->dimension(idx_width));
340 const auto hr = static_cast<float>(input->info()->dimension(idx_height)) / static_cast<float>(output->info()->dimension(idx_height));
341
342 // Add constant border only on top in case of NHWC layout
343 if(data_layout == DataLayout::NHWC)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100344 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100345 _border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100346 }
347
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100348 // Area interpolation behaves as Nearest Neighbour in case of up-sampling
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100349 if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
350 {
351 policy = InterpolationPolicy::NEAREST_NEIGHBOR;
352 }
353
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100354 // Select interpolation function
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100355 switch(policy)
356 {
357 case InterpolationPolicy::NEAREST_NEIGHBOR:
358 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100359 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100360 break;
361 }
362 case InterpolationPolicy::BILINEAR:
363 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100364 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100365 break;
366 }
367 case InterpolationPolicy::AREA:
368 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100369 _func = &NEScaleKernel::scale_area_nchw;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100370 break;
371 }
372 default:
373 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
374 }
375
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100376 // Configure window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100377 std::pair<Status, Window> win_config = validate_and_configure_window(input->info(),
378 dx != nullptr ? dx->info() : nullptr,
379 dy != nullptr ? dy->info() : nullptr,
380 offsets != nullptr ? offsets->info() : nullptr,
381 output->info(),
382 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size());
383 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
384 INEKernel::configure(win_config.second);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100385}
386
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100387void NEScaleKernel::scale_nearest_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100388{
389 const size_t input_stride = _input->info()->strides_in_bytes()[1];
390
391 // Compute the ratio between source height and destination height
392 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
393
394 // Don't increment in X and Y direction for the input tensor
395 // A pointer to the start of this plane is needed as base for the precomputed offsets
396 Window win_in(window);
397 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
398 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
399
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100400 // Set offsets window
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100401 Window win_off;
402 win_off.set(Window::DimX, window[Window::DimX]);
403 win_off.set(Window::DimY, window[Window::DimY]);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100404 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
405 {
406 win_off.set(d, Window::Dimension(0, 0, 0));
407 }
408
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100409 // Create iterators
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100410 Iterator in(_input, win_in);
411 Iterator out(_output, window);
412 Iterator offsets(_offsets, win_off);
413
414 switch(_input->info()->data_type())
415 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000416 case DataType::QASYMM8:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100417 case DataType::U8:
418 {
419 uint8x16_t tmp = vdupq_n_u8(0);
420
421 execute_window_loop(window, [&](const Coordinates & id)
422 {
423 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
424 const uint8_t *const in_ptr = in.ptr();
425
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100426 const int in_yi = std::floor((id.y() + 0.5f) * hr);
427 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
428 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
429 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100430
431 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
432 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
433 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
434 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
435 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
436 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
437 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
438 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
439 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
440 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
441 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
442 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
443 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
444 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
445 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
446 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
447
448 vst1q_u8(out.ptr(), tmp);
449 },
450 in, offsets, out);
451 break;
452 }
453 case DataType::S16:
454 {
455 int16x8x2_t tmp =
456 {
457 {
458 vdupq_n_s16(0),
459 vdupq_n_s16(0)
460 }
461 };
462
463 execute_window_loop(window, [&](const Coordinates & id)
464 {
465 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
466
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100467 const int in_yi = (id.y() + 0.5f) * hr;
468 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100469
470 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
471 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
472 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
473 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
474 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
475 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
476 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
477 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
478
479 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
480 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
481 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
482 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
483 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
484 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
485 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
486 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
487
488 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
489 },
490 in, offsets, out);
491 break;
492 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000493#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
494 case DataType::F16:
495 {
496 float16x8x2_t tmp =
497 {
498 {
499 vdupq_n_f16(0),
500 vdupq_n_f16(0)
501 }
502 };
503
504 execute_window_loop(window, [&](const Coordinates & id)
505 {
506 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
507
508 const int in_yi = (id.y() + 0.5f) * hr;
509 const int offset_row = in_yi * input_stride;
510
511 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
512 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
513 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
514 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
515 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
516 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
517 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
518 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
519
520 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
521 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
522 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
523 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
524 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
525 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
526 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
527 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
528
529 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
530 },
531 in, offsets, out);
532 break;
533 }
534#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100535 case DataType::F32:
536 {
537 float32x4x4_t tmp =
538 {
539 {
540 vdupq_n_f32(0),
541 vdupq_n_f32(0),
542 vdupq_n_f32(0),
543 vdupq_n_f32(0)
544 }
545 };
546
547 execute_window_loop(window, [&](const Coordinates & id)
548 {
549 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
550
551 const int in_yi = (id.y() + 0.5f) * hr;
552 const int offset_row = in_yi * input_stride;
553
554 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
555 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
556 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
557 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
558
559 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
560 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
561 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
562 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
563
564 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
565 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
566 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
567 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
568
569 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
570 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
571 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
572 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
573
574 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
575 },
576 in, offsets, out);
577 break;
578 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100579 default:
580 ARM_COMPUTE_ERROR("Not supported");
581 break;
582 }
583}
584
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100585void NEScaleKernel::scale_bilinear_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100586{
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000587 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::QASYMM8, DataType::S16, DataType::F16, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100588
589 // Compute the ratio between source height and destination height
590 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
591
592 // Don't increment in X and Y direction for the input tensor
593 // A pointer to the start of this plane is needed as base for the precomputed offsets
594 Window win_in(window);
595 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
596 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
597
598 Window win_off;
599 win_off.set(Window::DimX, window.x());
600 win_off.set(Window::DimY, window.y());
601
602 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
603 {
604 win_off.set(d, Window::Dimension(0, 0, 0));
605 }
606
607 Iterator in(_input, win_in);
608 Iterator out(_output, window);
609 Iterator offsets(_offsets, win_off);
610 Iterator dx(_dx, win_off);
611 Iterator dy(_dy, win_off);
612
613 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100614 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
615 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100616
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000617 const bool is_quantized = (_input->info()->data_type() == DataType::QASYMM8);
618 const QuantizationInfo iq_info = _input->info()->quantization_info();
619 const QuantizationInfo oq_info = _output->info()->quantization_info();
620
Georgios Pinitas583137c2017-08-31 18:12:42 +0100621 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100622 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000623 case DataType::QASYMM8:
Georgios Pinitas583137c2017-08-31 18:12:42 +0100624 case DataType::U8:
625 {
626 execute_window_loop(window, [&](const Coordinates & id)
627 {
628 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
629 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
630 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
631 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100632
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000633 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100634 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100635
Georgios Pinitas583137c2017-08-31 18:12:42 +0100636 uint8x8_t tmp0 = vdup_n_u8(0);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000637 if(is_quantized)
638 {
639 tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0], iq_info, oq_info), tmp0, 0);
640 tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1], iq_info, oq_info), tmp0, 1);
641 tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2], iq_info, oq_info), tmp0, 2);
642 tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3], iq_info, oq_info), tmp0, 3);
643 tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4], iq_info, oq_info), tmp0, 4);
644 tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5], iq_info, oq_info), tmp0, 5);
645 tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6], iq_info, oq_info), tmp0, 6);
646 tmp0 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7], iq_info, oq_info), tmp0, 7);
647 }
648 else
649 {
650 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
651 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
652 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
653 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
654 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
655 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
656 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
657 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7);
658 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100659 uint8x8_t tmp1 = vdup_n_u8(0);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000660 if(is_quantized)
661 {
662 tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8], iq_info, oq_info), tmp1, 0);
663 tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9], iq_info, oq_info), tmp1, 1);
664 tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10], iq_info, oq_info), tmp1, 2);
665 tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11], iq_info, oq_info), tmp1, 3);
666 tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12], iq_info, oq_info), tmp1, 4);
667 tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13], iq_info, oq_info), tmp1, 5);
668 tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14], iq_info, oq_info), tmp1, 6);
669 tmp1 = vset_lane_u8(delta_bilinear_c1_quantized(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15], iq_info, oq_info), tmp1, 7);
670 }
671 else
672 {
673 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
674 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
675 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
676 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
677 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
678 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
679 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
680 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7);
681 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100682 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
683 },
684 in, offsets, dx, dy, out);
685 break;
686 }
687 case DataType::S16:
688 {
689 execute_window_loop(window, [&](const Coordinates & id)
690 {
691 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
692 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
693 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
694
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000695 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100696 const int offset_row = in_yi * in_stide_in_bytes;
697
698 int16x8x2_t tmp =
699 {
700 {
701 vdupq_n_s16(0),
702 vdupq_n_s16(0)
703 }
704 };
705
706 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);
707 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);
708 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);
709 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);
710 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);
711 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);
712 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);
713 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);
714
715 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);
716 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);
717 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);
718 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);
719 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);
720 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);
721 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);
722 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);
723
724 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
725 },
726 in, offsets, dx, dy, out);
727 break;
728 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000729#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
730 case DataType::F16:
731 {
732 execute_window_loop(window, [&](const Coordinates & id)
733 {
734 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
735 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
736 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
737
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000738 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000739 const int offset_row = in_yi * in_stide_in_bytes;
740
741 float16x8x2_t tmp =
742 {
743 {
744 vdupq_n_f16(0),
745 vdupq_n_f16(0)
746 }
747 };
748
749 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);
750 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);
751 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);
752 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);
753 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);
754 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);
755 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);
756 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);
757
758 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);
759 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);
760 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);
761 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);
762 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);
763 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);
764 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);
765 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);
766
767 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
768 },
769 in, offsets, dx, dy, out);
770 break;
771 }
772#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100773 case DataType::F32:
774 {
775 execute_window_loop(window, [&](const Coordinates & id)
776 {
777 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
778 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
779 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
780
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000781 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100782 const int offset_row = in_yi * in_stide_in_bytes;
783
784 float32x4x4_t tmp =
785 {
786 {
787 vdupq_n_f32(0),
788 vdupq_n_f32(0),
789 vdupq_n_f32(0),
790 vdupq_n_f32(0)
791 }
792 };
793
794 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);
795 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);
796 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);
797 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);
798
799 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);
800 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);
801 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);
802 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);
803
804 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);
805 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);
806 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);
807 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);
808
809 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);
810 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);
811 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);
812 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);
813
814 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
815 },
816 in, offsets, dx, dy, out);
817 break;
818 }
819 default:
820 ARM_COMPUTE_ERROR("Not supported");
821 break;
822 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100823}
824
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100825void NEScaleKernel::scale_area_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100826{
827 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
828
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100829 // Don't increment in width/height/channels for the input tensor
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100830 // A pointer to the start of this plane is needed as base for the precomputed offsets
831 Window win_in(window);
832 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
833 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100834 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100835
836 Iterator in(_input, win_in);
837 Iterator out(_output, window);
838
839 const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0));
840 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
841 const auto w = _input->info()->dimension(0);
842 const auto h = _input->info()->dimension(1);
843 const size_t in_stride = _input->info()->strides_in_bytes()[1];
844
845 execute_window_loop(window, [&](const Coordinates & id)
846 {
847 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
848
849 uint8x8_t tmp0 = vdup_n_u8(0);
850 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
851 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
852 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
853 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
854 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
855 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
856 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
857 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
858
859 uint8x8_t tmp1 = vdup_n_u8(0);
860 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
861 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
862 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
863 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
864 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
865 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
866 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
867 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
868
869 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
870 },
871 in, out);
872}
873
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100874void NEScaleKernel::scale_nhwc(const Window &window)
875{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100876 // Get data layout and width/height indices
877 const DataLayout data_layout = _input->info()->data_layout();
878 const int idx_channels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
879 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
880 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
881
882 const size_t input_stride_w = _input->info()->strides_in_bytes()[idx_width];
883 const size_t input_stride_h = _input->info()->strides_in_bytes()[idx_height];
884 const size_t input_stride_c = _input->info()->strides_in_bytes()[idx_channels];
885
886 // Compute the ratio between source height and destination height
887 const auto hr = static_cast<float>(_input->info()->dimension(idx_height)) / static_cast<float>(_output->info()->dimension(idx_height));
888
889 // Don't increment in width/height/channels for the input tensor
890 // A pointer to the start of this plane is needed as base for the precomputed offsets
891 Window win_in(window);
892 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
893 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
894 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
895
896 switch(_input->info()->data_type())
897 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000898 case DataType::QASYMM8:
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100899 case DataType::U8:
900 {
901 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
902 {
903 scale_nearest_nhwc_core<uint8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
904 }
905 else
906 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000907 scale_bilinear_nhwc_core<uint8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100908 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode);
909 }
910 break;
911 }
912 case DataType::S16:
913 {
914 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
915 {
916 scale_nearest_nhwc_core<int16_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
917 }
918 else
919 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000920 scale_bilinear_nhwc_core<int16_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100921 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode);
922 }
923 break;
924 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000925#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
926 case DataType::F16:
927 {
928 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
929 {
930 scale_nearest_nhwc_core<float16_t>(_input, _offsets, _output, hr,
931 window, win_in, input_stride_w, input_stride_h, input_stride_c);
932 }
933 else
934 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000935 scale_bilinear_nhwc_core<float16_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000936 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode);
937 }
938 break;
939 }
940#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100941 case DataType::F32:
942 {
943 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
944 {
945 scale_nearest_nhwc_core<float>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
946 }
947 else
948 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000949 scale_bilinear_nhwc_core<float>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100950 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode);
951 }
952 break;
953 }
954 default:
955 ARM_COMPUTE_ERROR("Not supported");
956 break;
957 }
958}
959
Georgios Pinitas20b43132018-05-14 16:05:23 +0100960Status NEScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
961 const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy,
962 BorderMode border_mode, SamplingPolicy sampling_policy)
963{
964 BorderSize border_size(1);
965 if(input->data_layout() == DataLayout::NHWC)
966 {
967 border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
968 }
969
970 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, policy, border_mode, sampling_policy));
971 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
972 dx != nullptr ? dx->clone().get() : nullptr,
973 dy != nullptr ? dy->clone().get() : nullptr,
974 offsets != nullptr ? offsets->clone().get() : nullptr,
975 output->clone().get(),
976 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size)
977 .first);
978
979 return Status{};
980}
981
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100982void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100983{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100984 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100985 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
986 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
987 ARM_COMPUTE_ERROR_ON(_func == nullptr);
988
989 (this->*_func)(window);
990}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100991} // namespace arm_compute