blob: 003f4724868072f88387a4b0f46cd657667618c6 [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,
George Wort05398a92019-01-25 15:38:33 +000048 BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding)
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);
George Wort05398a92019-01-25 15:38:33 +000056 ARM_COMPUTE_RETURN_ERROR_ON(!use_padding && border_mode != BorderMode::CONSTANT);
57 ARM_COMPUTE_UNUSED(constant_border_value);
Georgios Pinitas20b43132018-05-14 16:05:23 +010058
59 const DataLayout data_layout = input->data_layout();
60 ARM_COMPUTE_RETURN_ERROR_ON(output->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH)) == 0);
61 ARM_COMPUTE_RETURN_ERROR_ON(output->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT)) == 0);
62
63 if(policy == InterpolationPolicy::NEAREST_NEIGHBOR)
64 {
65 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
66 }
67
68 if(policy == InterpolationPolicy::BILINEAR)
69 {
70 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
71 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32);
72 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32);
73 }
74
75 if(policy == InterpolationPolicy::AREA)
76 {
77 ARM_COMPUTE_RETURN_ERROR_ON(data_layout != DataLayout::NCHW);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +000078 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
Georgios Pinitas20b43132018-05-14 16:05:23 +010079 }
80
81 return Status{};
82}
83
84std::pair<Status, Window> validate_and_configure_window_nchw(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output,
85 InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size)
86{
87 bool window_changed{ false };
88 Window win{};
89
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010090 constexpr unsigned int num_elems_processed_per_iteration = 16;
91
92 // Configure kernel window
Georgios Pinitas20b43132018-05-14 16:05:23 +010093 win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010094
Georgios Pinitas20b43132018-05-14 16:05:23 +010095 const ValidRegion &input_valid_region = input->valid_region();
96
97 if(offsets != nullptr)
98 {
99 AccessWindowHorizontal offsets_access(offsets, 0, num_elems_processed_per_iteration);
100 window_changed = window_changed || update_window_and_padding(win, offsets_access);
101 }
102 if(dx != nullptr && dy != nullptr)
103 {
104 AccessWindowHorizontal dx_access(dx, 0, num_elems_processed_per_iteration);
105 AccessWindowHorizontal dy_access(dy, 0, num_elems_processed_per_iteration);
106 window_changed = window_changed || update_window_and_padding(win, dx_access, dy_access);
107 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100108
109 // Reads can occur within the valid region of the input
Georgios Pinitas20b43132018-05-14 16:05:23 +0100110 AccessWindowStatic input_access(input, input_valid_region.anchor[0] - border_size.left,
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100111 input_valid_region.anchor[1] - border_size.top,
112 input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size.right,
113 input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size.bottom);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100114 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
115 window_changed = window_changed || update_window_and_padding(win, input_access, output_access);
116 output_access.set_valid_region(win, calculate_valid_region_scale(*input, output->tensor_shape(),
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100117 policy, sampling_policy, border_undefined));
118
Georgios Pinitas20b43132018-05-14 16:05:23 +0100119 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
120 return std::make_pair(err, win);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100121}
Georgios Pinitas20b43132018-05-14 16:05:23 +0100122
123std::pair<Status, Window> validate_and_configure_window_nhwc(ITensorInfo *input, ITensorInfo *output,
124 InterpolationPolicy policy, bool border_undefined,
George Wort05398a92019-01-25 15:38:33 +0000125 SamplingPolicy sampling_policy, BorderSize border_size, bool use_padding)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100126{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100127 bool window_changed{ false };
128 Window win{};
129
George Wort05398a92019-01-25 15:38:33 +0000130 const unsigned int num_elems_processed_per_iteration = (use_padding && policy == InterpolationPolicy::NEAREST_NEIGHBOR) ? 16 / input->element_size() : 1;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100131
132 // Configure kernel window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100133 win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100134
George Wort05398a92019-01-25 15:38:33 +0000135 if(use_padding)
136 {
137 AccessWindowStatic input_access(input, 0, -border_size.top, use_padding ? ceil_to_multiple(input->tensor_shape()[0], num_elems_processed_per_iteration) : num_elems_processed_per_iteration,
138 input->tensor_shape()[1]);
139 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
140 window_changed = update_window_and_padding(win, input_access, output_access);
141 output->set_valid_region(calculate_valid_region_scale(*input, output->tensor_shape(), policy, sampling_policy, border_undefined));
142 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100143
Georgios Pinitas20b43132018-05-14 16:05:23 +0100144 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
145 return std::make_pair(err, win);
146}
147
148std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output,
George Wort05398a92019-01-25 15:38:33 +0000149 InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size, bool use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +0100150{
151 std::pair<Status, Window> win_config;
152 switch(input->data_layout())
153 {
154 case DataLayout::NCHW:
George Wort05398a92019-01-25 15:38:33 +0000155 if(!use_padding)
156 {
157 return std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Padding required for NCHW"), Window{});
158 }
Georgios Pinitas20b43132018-05-14 16:05:23 +0100159 win_config = validate_and_configure_window_nchw(input, dx, dy, offsets, output, policy, border_undefined, sampling_policy, border_size);
160 break;
161 case DataLayout::NHWC:
George Wort05398a92019-01-25 15:38:33 +0000162 win_config = validate_and_configure_window_nhwc(input, output, policy, border_undefined, sampling_policy, border_size, use_padding);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100163 break;
164 default:
165 win_config = std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported data layout!"), Window{});
166 }
167
168 return win_config;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100169}
170
171template <typename T>
172inline void scale_nearest_nhwc_core(const ITensor *input, const ITensor *offsets, ITensor *output,
173 float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c)
174{
George Wort05398a92019-01-25 15:38:33 +0000175 const int window_step_x = 16 / sizeof(T);
176 const auto window_start_x = static_cast<int32_t>(window.x().start());
177 const auto window_end_x = static_cast<int32_t>(window.x().end());
178
179 window.set(Window::DimX, Window::Dimension(0, 1, 1));
180
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100181 Iterator in(input, win_in);
182 Iterator out(output, window);
183
184 const size_t offsets_stride = stride_w / sizeof(T);
185
186 execute_window_loop(window, [&](const Coordinates & id)
187 {
George Wort05398a92019-01-25 15:38:33 +0000188 const int32_t offset = *reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z())));
189 const int in_yi = (id.z() + 0.5f) * hr;
190 const int offset_row = in_yi * stride_h;
191 int32_t x = window_start_x;
192 for(; x < window_end_x - window_step_x; x += window_step_x)
193 {
194 wrapper::vstore(reinterpret_cast<T *>(out.ptr()) + x,
195 wrapper::vloadq(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row + x * stride_c)));
196 }
197 for(; x < window_end_x; ++x)
198 {
199 *(reinterpret_cast<T *>(out.ptr()) + x) =
200 *(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row + x * stride_c));
201 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100202 },
203 in, out);
204}
205
George Wort05398a92019-01-25 15:38:33 +0000206template <typename T, typename ConstType>
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100207inline void scale_bilinear_nhwc_core(const ITensor *input, const ITensor *offsets, const ITensor *dx, const ITensor *dy, ITensor *output,
George Wort05398a92019-01-25 15:38:33 +0000208 float hr, float sampling_offset, Window window, const Window &win_in, size_t stride_w, size_t stride_h,
209 size_t stride_c, BorderMode border_mode, PixelValue constant_border_value, bool use_padding)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100210{
211 Iterator in(input, win_in);
212 Iterator out(output, window);
213
214 const size_t stride_w_elems = stride_w / sizeof(T);
215 const size_t stride_h_elems = stride_h / sizeof(T);
216
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100217 const int input_width = input->info()->dimension(1);
218 const int input_height = input->info()->dimension(2);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100219
George Wort05398a92019-01-25 15:38:33 +0000220 T border_value;
Pablo Tello10971472019-05-15 15:14:46 +0100221 if(use_padding && border_mode != BorderMode::REPLICATE )
George Wort05398a92019-01-25 15:38:33 +0000222 {
Pablo Tello10971472019-05-15 15:14:46 +0100223 // configure() sets top border to 0 for BorderMode::REPLICATE and border_value is not needed in execute_window_loop() for REPLICATE
George Wort05398a92019-01-25 15:38:33 +0000224 border_value = *reinterpret_cast<T *>(input->buffer() + input->info()->offset_first_element_in_bytes() - stride_w);
225 }
226 else
227 {
228 border_value = static_cast<T>(constant_border_value.get<ConstType>());
229 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100230
231 auto is_valid = [](int x, int low_x, int high_x, int y, int low_y, int high_y)
232 {
233 return !(x < low_x || x > high_x || y < low_y || y > high_y);
234 };
235
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100236 int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1;
237
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000238 const bool is_quantized = (input->info()->data_type() == DataType::QASYMM8);
239 const QuantizationInfo iq_info = input->info()->quantization_info();
240 const QuantizationInfo oq_info = output->info()->quantization_info();
241
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100242 execute_window_loop(window, [&](const Coordinates & id)
243 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100244 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 +0100245 const auto dx_scale = *reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id.y(), id.z())));
246 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 +0000247 const int in_yi = std::floor((id.z() + sampling_offset) * hr - sampling_offset);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100248 const int offset_row = in_yi * stride_h + id.x() * stride_c;
249 const T *in_ptr = reinterpret_cast<T *>(in.ptr() + offset * stride_w + offset_row);
250
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100251 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 +0100252 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100253 T a00 = 0;
254 T a01 = 0;
255 T a10 = 0;
256 T a11 = 0;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100257
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100258 if(border_mode == BorderMode::CONSTANT)
259 {
George Wort05398a92019-01-25 15:38:33 +0000260 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : border_value;
261 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : border_value;
262 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : border_value;
263 a11 = is_valid(offset + 1, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems + stride_w_elems) : border_value;
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100264 }
265 else if(border_mode == BorderMode::REPLICATE)
266 {
267 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
268 auto clamped_x1 = utility::clamp<int>(offset + 1, 0, input_width - 1);
269 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
270 auto clamped_y1 = utility::clamp<int>(in_yi + 1, 0, input_height - 1);
271
272 a00 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
273 a01 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y * stride_h + id.x() * stride_c);
274 a10 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
275 a11 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
276 }
277 else
278 {
279 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : 0;
280 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : 0;
281 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : 0;
282 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;
283 }
284
285 // Perform interpolation
286 const float dx1 = 1.0f - dx_scale;
287 const float dy1 = 1.0f - dy_scale;
288
289 const float w1 = dx1 * dy1;
290 const float w2 = dx_scale * dy1;
291 const float w3 = dx1 * dy_scale;
292 const float w4 = dx_scale * dy_scale;
293
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000294 T res = 0;
295 //dequantize quantized input
296 if(is_quantized)
297 {
298 float inp00 = iq_info.dequantize(a00);
299 float inp01 = iq_info.dequantize(a01);
300 float inp10 = iq_info.dequantize(a10);
301 float inp11 = iq_info.dequantize(a11);
302 res = static_cast<T>(oq_info.quantize((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), RoundingPolicy::TO_NEAREST_UP));
303 }
304 else
305 {
306 res = static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4);
307 }
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100308 // Store result
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000309 *reinterpret_cast<T *>(out.ptr()) = res;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100310 }
311 else
312 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100313 if(border_mode == BorderMode::CONSTANT)
314 {
George Wort05398a92019-01-25 15:38:33 +0000315 *reinterpret_cast<T *>(out.ptr()) = border_value;
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100316 }
317 else if(border_mode == BorderMode::REPLICATE)
318 {
319 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
320 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
321 *reinterpret_cast<T *>(out.ptr()) = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
322 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100323 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100324 },
325 in, out);
326}
327} // namespace
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100328
329NEScaleKernel::NEScaleKernel()
Manuel Bottinif00d3322019-03-05 15:53:25 +0000330 : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_size(1), _border_mode(), _constant_border_value(PixelValue()),
331 _sampling_offset(0), _use_padding(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100332{
333}
334
335BorderSize NEScaleKernel::border_size() const
336{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100337 return _border_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100338}
339
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100340void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets,
George Wort05398a92019-01-25 15:38:33 +0000341 ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy,
342 bool use_padding)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100344 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100345 // Perform validation step
346 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
347 dx != nullptr ? dx->info() : nullptr,
348 dy != nullptr ? dy->info() : nullptr,
349 offsets != nullptr ? offsets->info() : nullptr,
350 output->info(),
George Wort05398a92019-01-25 15:38:33 +0000351 policy, border_mode, constant_border_value, sampling_policy, use_padding));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100352
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100353 // Get data layout and width/height indices
354 const DataLayout data_layout = input->info()->data_layout();
355 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
356 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100357
George Wort05398a92019-01-25 15:38:33 +0000358 _input = input;
359 _output = output;
360 _offsets = offsets;
361 _dx = dx;
362 _dy = dy;
363 _policy = policy;
364 _border_size = BorderSize(1);
365 _border_mode = border_mode;
366 _constant_border_value = constant_border_value;
367 _use_padding = use_padding;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100368
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000369 if(sampling_policy == SamplingPolicy::CENTER)
370 {
371 _sampling_offset = 0.5f;
372 }
373
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100374 // Compute the ratio between source width/height and destination width/height
375 const auto wr = static_cast<float>(input->info()->dimension(idx_width)) / static_cast<float>(output->info()->dimension(idx_width));
376 const auto hr = static_cast<float>(input->info()->dimension(idx_height)) / static_cast<float>(output->info()->dimension(idx_height));
377
378 // Add constant border only on top in case of NHWC layout
379 if(data_layout == DataLayout::NHWC)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100380 {
George Wort05398a92019-01-25 15:38:33 +0000381 _border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR && use_padding) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100382 }
383
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100384 // Area interpolation behaves as Nearest Neighbour in case of up-sampling
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100385 if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
386 {
387 policy = InterpolationPolicy::NEAREST_NEIGHBOR;
388 }
389
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100390 // Select interpolation function
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100391 switch(policy)
392 {
393 case InterpolationPolicy::NEAREST_NEIGHBOR:
394 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100395 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100396 break;
397 }
398 case InterpolationPolicy::BILINEAR:
399 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100400 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100401 break;
402 }
403 case InterpolationPolicy::AREA:
404 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100405 _func = &NEScaleKernel::scale_area_nchw;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100406 break;
407 }
408 default:
409 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
410 }
411
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100412 // Configure window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100413 std::pair<Status, Window> win_config = validate_and_configure_window(input->info(),
414 dx != nullptr ? dx->info() : nullptr,
415 dy != nullptr ? dy->info() : nullptr,
416 offsets != nullptr ? offsets->info() : nullptr,
417 output->info(),
George Wort05398a92019-01-25 15:38:33 +0000418 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size(), use_padding);
419
Georgios Pinitas20b43132018-05-14 16:05:23 +0100420 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
421 INEKernel::configure(win_config.second);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100422}
423
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100424void NEScaleKernel::scale_nearest_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100425{
426 const size_t input_stride = _input->info()->strides_in_bytes()[1];
427
428 // Compute the ratio between source height and destination height
429 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
430
431 // Don't increment in X and Y direction for the input tensor
432 // A pointer to the start of this plane is needed as base for the precomputed offsets
433 Window win_in(window);
434 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
435 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
436
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100437 // Set offsets window
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100438 Window win_off;
439 win_off.set(Window::DimX, window[Window::DimX]);
440 win_off.set(Window::DimY, window[Window::DimY]);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100441 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
442 {
443 win_off.set(d, Window::Dimension(0, 0, 0));
444 }
445
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100446 // Create iterators
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100447 Iterator in(_input, win_in);
448 Iterator out(_output, window);
449 Iterator offsets(_offsets, win_off);
450
451 switch(_input->info()->data_type())
452 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000453 case DataType::QASYMM8:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100454 case DataType::U8:
455 {
456 uint8x16_t tmp = vdupq_n_u8(0);
457
458 execute_window_loop(window, [&](const Coordinates & id)
459 {
460 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
461 const uint8_t *const in_ptr = in.ptr();
462
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100463 const int in_yi = std::floor((id.y() + 0.5f) * hr);
464 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
465 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
466 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100467
468 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
469 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
470 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
471 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
472 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
473 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
474 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
475 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
476 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
477 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
478 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
479 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
480 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
481 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
482 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
483 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
484
485 vst1q_u8(out.ptr(), tmp);
486 },
487 in, offsets, out);
488 break;
489 }
490 case DataType::S16:
491 {
492 int16x8x2_t tmp =
493 {
494 {
495 vdupq_n_s16(0),
496 vdupq_n_s16(0)
497 }
498 };
499
500 execute_window_loop(window, [&](const Coordinates & id)
501 {
502 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
503
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100504 const int in_yi = (id.y() + 0.5f) * hr;
505 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100506
507 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
508 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
509 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
510 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
511 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
512 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
513 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
514 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
515
516 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
517 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
518 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
519 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
520 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
521 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
522 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
523 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
524
525 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
526 },
527 in, offsets, out);
528 break;
529 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000530#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
531 case DataType::F16:
532 {
533 float16x8x2_t tmp =
534 {
535 {
536 vdupq_n_f16(0),
537 vdupq_n_f16(0)
538 }
539 };
540
541 execute_window_loop(window, [&](const Coordinates & id)
542 {
543 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
544
545 const int in_yi = (id.y() + 0.5f) * hr;
546 const int offset_row = in_yi * input_stride;
547
548 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
549 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
550 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
551 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
552 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
553 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
554 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
555 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
556
557 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
558 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
559 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
560 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
561 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
562 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
563 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
564 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
565
566 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
567 },
568 in, offsets, out);
569 break;
570 }
571#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100572 case DataType::F32:
573 {
574 float32x4x4_t tmp =
575 {
576 {
577 vdupq_n_f32(0),
578 vdupq_n_f32(0),
579 vdupq_n_f32(0),
580 vdupq_n_f32(0)
581 }
582 };
583
584 execute_window_loop(window, [&](const Coordinates & id)
585 {
586 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
587
588 const int in_yi = (id.y() + 0.5f) * hr;
589 const int offset_row = in_yi * input_stride;
590
591 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
592 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
593 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
594 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
595
596 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
597 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
598 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
599 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
600
601 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
602 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
603 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
604 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
605
606 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
607 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
608 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
609 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
610
611 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
612 },
613 in, offsets, out);
614 break;
615 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100616 default:
617 ARM_COMPUTE_ERROR("Not supported");
618 break;
619 }
620}
621
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100622void NEScaleKernel::scale_bilinear_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100623{
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000624 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 +0100625
626 // Compute the ratio between source height and destination height
627 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
628
629 // Don't increment in X and Y direction for the input tensor
630 // A pointer to the start of this plane is needed as base for the precomputed offsets
631 Window win_in(window);
632 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
633 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
634
635 Window win_off;
636 win_off.set(Window::DimX, window.x());
637 win_off.set(Window::DimY, window.y());
638
639 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
640 {
641 win_off.set(d, Window::Dimension(0, 0, 0));
642 }
643
644 Iterator in(_input, win_in);
645 Iterator out(_output, window);
646 Iterator offsets(_offsets, win_off);
647 Iterator dx(_dx, win_off);
648 Iterator dy(_dy, win_off);
649
650 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100651 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
652 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100653
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000654 const bool is_quantized = (_input->info()->data_type() == DataType::QASYMM8);
655 const QuantizationInfo iq_info = _input->info()->quantization_info();
656 const QuantizationInfo oq_info = _output->info()->quantization_info();
657
Georgios Pinitas583137c2017-08-31 18:12:42 +0100658 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100659 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000660 case DataType::QASYMM8:
Georgios Pinitas583137c2017-08-31 18:12:42 +0100661 case DataType::U8:
662 {
663 execute_window_loop(window, [&](const Coordinates & id)
664 {
665 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
666 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
667 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
668 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100669
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000670 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100671 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100672
Georgios Pinitas583137c2017-08-31 18:12:42 +0100673 uint8x8_t tmp0 = vdup_n_u8(0);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000674 if(is_quantized)
675 {
676 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);
677 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);
678 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);
679 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);
680 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);
681 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);
682 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);
683 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);
684 }
685 else
686 {
687 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
688 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
689 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
690 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
691 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
692 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
693 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
694 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7);
695 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100696 uint8x8_t tmp1 = vdup_n_u8(0);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000697 if(is_quantized)
698 {
699 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);
700 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);
701 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);
702 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);
703 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);
704 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);
705 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);
706 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);
707 }
708 else
709 {
710 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
711 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
712 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
713 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
714 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
715 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
716 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
717 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7);
718 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100719 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
720 },
721 in, offsets, dx, dy, out);
722 break;
723 }
724 case DataType::S16:
725 {
726 execute_window_loop(window, [&](const Coordinates & id)
727 {
728 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
729 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
730 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
731
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000732 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100733 const int offset_row = in_yi * in_stide_in_bytes;
734
735 int16x8x2_t tmp =
736 {
737 {
738 vdupq_n_s16(0),
739 vdupq_n_s16(0)
740 }
741 };
742
743 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);
744 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);
745 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);
746 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);
747 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);
748 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);
749 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);
750 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);
751
752 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);
753 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);
754 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);
755 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);
756 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);
757 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);
758 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);
759 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);
760
761 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
762 },
763 in, offsets, dx, dy, out);
764 break;
765 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000766#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
767 case DataType::F16:
768 {
769 execute_window_loop(window, [&](const Coordinates & id)
770 {
771 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
772 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
773 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
774
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000775 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000776 const int offset_row = in_yi * in_stide_in_bytes;
777
778 float16x8x2_t tmp =
779 {
780 {
781 vdupq_n_f16(0),
782 vdupq_n_f16(0)
783 }
784 };
785
786 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);
787 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);
788 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);
789 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);
790 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);
791 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);
792 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);
793 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);
794
795 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);
796 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);
797 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);
798 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);
799 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);
800 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);
801 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);
802 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);
803
804 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
805 },
806 in, offsets, dx, dy, out);
807 break;
808 }
809#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100810 case DataType::F32:
811 {
812 execute_window_loop(window, [&](const Coordinates & id)
813 {
814 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
815 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
816 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
817
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000818 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100819 const int offset_row = in_yi * in_stide_in_bytes;
820
821 float32x4x4_t tmp =
822 {
823 {
824 vdupq_n_f32(0),
825 vdupq_n_f32(0),
826 vdupq_n_f32(0),
827 vdupq_n_f32(0)
828 }
829 };
830
831 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);
832 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);
833 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);
834 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);
835
836 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);
837 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);
838 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);
839 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);
840
841 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);
842 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);
843 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);
844 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);
845
846 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);
847 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);
848 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);
849 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);
850
851 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
852 },
853 in, offsets, dx, dy, out);
854 break;
855 }
856 default:
857 ARM_COMPUTE_ERROR("Not supported");
858 break;
859 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100860}
861
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100862void NEScaleKernel::scale_area_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100863{
864 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
865
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100866 // Don't increment in width/height/channels for the input tensor
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100867 // A pointer to the start of this plane is needed as base for the precomputed offsets
868 Window win_in(window);
869 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
870 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100871 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100872
873 Iterator in(_input, win_in);
874 Iterator out(_output, window);
875
876 const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0));
877 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
878 const auto w = _input->info()->dimension(0);
879 const auto h = _input->info()->dimension(1);
880 const size_t in_stride = _input->info()->strides_in_bytes()[1];
881
882 execute_window_loop(window, [&](const Coordinates & id)
883 {
884 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
885
886 uint8x8_t tmp0 = vdup_n_u8(0);
887 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
888 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
889 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
890 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
891 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
892 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
893 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
894 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
895
896 uint8x8_t tmp1 = vdup_n_u8(0);
897 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
898 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
899 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
900 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
901 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
902 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
903 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
904 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
905
906 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
907 },
908 in, out);
909}
910
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100911void NEScaleKernel::scale_nhwc(const Window &window)
912{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100913 // Get data layout and width/height indices
914 const DataLayout data_layout = _input->info()->data_layout();
915 const int idx_channels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
916 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
917 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
918
919 const size_t input_stride_w = _input->info()->strides_in_bytes()[idx_width];
920 const size_t input_stride_h = _input->info()->strides_in_bytes()[idx_height];
921 const size_t input_stride_c = _input->info()->strides_in_bytes()[idx_channels];
922
923 // Compute the ratio between source height and destination height
924 const auto hr = static_cast<float>(_input->info()->dimension(idx_height)) / static_cast<float>(_output->info()->dimension(idx_height));
925
926 // Don't increment in width/height/channels for the input tensor
927 // A pointer to the start of this plane is needed as base for the precomputed offsets
928 Window win_in(window);
929 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
930 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
931 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
932
933 switch(_input->info()->data_type())
934 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000935 case DataType::QASYMM8:
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100936 case DataType::U8:
937 {
938 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
939 {
940 scale_nearest_nhwc_core<uint8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
941 }
942 else
943 {
George Wort05398a92019-01-25 15:38:33 +0000944 scale_bilinear_nhwc_core<uint8_t, uint8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
945 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100946 }
947 break;
948 }
949 case DataType::S16:
950 {
951 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
952 {
953 scale_nearest_nhwc_core<int16_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
954 }
955 else
956 {
George Wort05398a92019-01-25 15:38:33 +0000957 scale_bilinear_nhwc_core<int16_t, int16_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
958 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100959 }
960 break;
961 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000962#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
963 case DataType::F16:
964 {
965 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
966 {
967 scale_nearest_nhwc_core<float16_t>(_input, _offsets, _output, hr,
968 window, win_in, input_stride_w, input_stride_h, input_stride_c);
969 }
970 else
971 {
George Wort05398a92019-01-25 15:38:33 +0000972 scale_bilinear_nhwc_core<float16_t, half>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
973 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000974 }
975 break;
976 }
977#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100978 case DataType::F32:
979 {
980 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
981 {
982 scale_nearest_nhwc_core<float>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
983 }
984 else
985 {
George Wort05398a92019-01-25 15:38:33 +0000986 scale_bilinear_nhwc_core<float, float>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
987 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100988 }
989 break;
990 }
991 default:
992 ARM_COMPUTE_ERROR("Not supported");
993 break;
994 }
995}
996
Georgios Pinitas20b43132018-05-14 16:05:23 +0100997Status NEScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
998 const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy,
George Wort05398a92019-01-25 15:38:33 +0000999 BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +01001000{
1001 BorderSize border_size(1);
1002 if(input->data_layout() == DataLayout::NHWC)
1003 {
1004 border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
1005 }
1006
George Wort05398a92019-01-25 15:38:33 +00001007 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, policy, border_mode, constant_border_value, sampling_policy, use_padding));
Georgios Pinitas20b43132018-05-14 16:05:23 +01001008 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
1009 dx != nullptr ? dx->clone().get() : nullptr,
1010 dy != nullptr ? dy->clone().get() : nullptr,
1011 offsets != nullptr ? offsets->clone().get() : nullptr,
1012 output->clone().get(),
George Wort05398a92019-01-25 15:38:33 +00001013 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size, use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +01001014 .first);
1015
1016 return Status{};
1017}
1018
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001019void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001020{
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001021 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001022 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
1023 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
1024 ARM_COMPUTE_ERROR_ON(_func == nullptr);
1025
1026 (this->*_func)(window);
1027}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001028} // namespace arm_compute