blob: 33540393e40410d77c3f93fc9eadaffc121f6391 [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;
221 if(use_padding)
222 {
223 border_value = *reinterpret_cast<T *>(input->buffer() + input->info()->offset_first_element_in_bytes() - stride_w);
224 }
225 else
226 {
227 border_value = static_cast<T>(constant_border_value.get<ConstType>());
228 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100229
230 auto is_valid = [](int x, int low_x, int high_x, int y, int low_y, int high_y)
231 {
232 return !(x < low_x || x > high_x || y < low_y || y > high_y);
233 };
234
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100235 int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1;
236
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000237 const bool is_quantized = (input->info()->data_type() == DataType::QASYMM8);
238 const QuantizationInfo iq_info = input->info()->quantization_info();
239 const QuantizationInfo oq_info = output->info()->quantization_info();
240
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100241 execute_window_loop(window, [&](const Coordinates & id)
242 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100243 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 +0100244 const auto dx_scale = *reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id.y(), id.z())));
245 const auto dy_scale = *reinterpret_cast<const float *>(dy->ptr_to_element(Coordinates(id.y(), id.z())));
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000246 const int in_yi = std::floor((id.z() + sampling_offset) * hr - sampling_offset);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100247 const int offset_row = in_yi * stride_h + id.x() * stride_c;
248 const T *in_ptr = reinterpret_cast<T *>(in.ptr() + offset * stride_w + offset_row);
249
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100250 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 +0100251 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100252 T a00 = 0;
253 T a01 = 0;
254 T a10 = 0;
255 T a11 = 0;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100256
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100257 if(border_mode == BorderMode::CONSTANT)
258 {
George Wort05398a92019-01-25 15:38:33 +0000259 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : border_value;
260 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : border_value;
261 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : border_value;
262 a11 = is_valid(offset + 1, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems + stride_w_elems) : border_value;
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100263 }
264 else if(border_mode == BorderMode::REPLICATE)
265 {
266 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
267 auto clamped_x1 = utility::clamp<int>(offset + 1, 0, input_width - 1);
268 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
269 auto clamped_y1 = utility::clamp<int>(in_yi + 1, 0, input_height - 1);
270
271 a00 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
272 a01 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y * stride_h + id.x() * stride_c);
273 a10 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
274 a11 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
275 }
276 else
277 {
278 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : 0;
279 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : 0;
280 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : 0;
281 a11 = is_valid(offset + 1, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems + stride_w_elems) : 0;
282 }
283
284 // Perform interpolation
285 const float dx1 = 1.0f - dx_scale;
286 const float dy1 = 1.0f - dy_scale;
287
288 const float w1 = dx1 * dy1;
289 const float w2 = dx_scale * dy1;
290 const float w3 = dx1 * dy_scale;
291 const float w4 = dx_scale * dy_scale;
292
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000293 T res = 0;
294 //dequantize quantized input
295 if(is_quantized)
296 {
297 float inp00 = iq_info.dequantize(a00);
298 float inp01 = iq_info.dequantize(a01);
299 float inp10 = iq_info.dequantize(a10);
300 float inp11 = iq_info.dequantize(a11);
301 res = static_cast<T>(oq_info.quantize((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), RoundingPolicy::TO_NEAREST_UP));
302 }
303 else
304 {
305 res = static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4);
306 }
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100307 // Store result
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000308 *reinterpret_cast<T *>(out.ptr()) = res;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100309 }
310 else
311 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100312 if(border_mode == BorderMode::CONSTANT)
313 {
George Wort05398a92019-01-25 15:38:33 +0000314 *reinterpret_cast<T *>(out.ptr()) = border_value;
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100315 }
316 else if(border_mode == BorderMode::REPLICATE)
317 {
318 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
319 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
320 *reinterpret_cast<T *>(out.ptr()) = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
321 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100322 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100323 },
324 in, out);
325}
326} // namespace
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100327
328NEScaleKernel::NEScaleKernel()
Manuel Bottinif00d3322019-03-05 15:53:25 +0000329 : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_size(1), _border_mode(), _constant_border_value(PixelValue()),
330 _sampling_offset(0), _use_padding(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100331{
332}
333
334BorderSize NEScaleKernel::border_size() const
335{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100336 return _border_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100337}
338
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100339void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets,
George Wort05398a92019-01-25 15:38:33 +0000340 ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy,
341 bool use_padding)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100342{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100343 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100344 // Perform validation step
345 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
346 dx != nullptr ? dx->info() : nullptr,
347 dy != nullptr ? dy->info() : nullptr,
348 offsets != nullptr ? offsets->info() : nullptr,
349 output->info(),
George Wort05398a92019-01-25 15:38:33 +0000350 policy, border_mode, constant_border_value, sampling_policy, use_padding));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100351
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100352 // Get data layout and width/height indices
353 const DataLayout data_layout = input->info()->data_layout();
354 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
355 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100356
George Wort05398a92019-01-25 15:38:33 +0000357 _input = input;
358 _output = output;
359 _offsets = offsets;
360 _dx = dx;
361 _dy = dy;
362 _policy = policy;
363 _border_size = BorderSize(1);
364 _border_mode = border_mode;
365 _constant_border_value = constant_border_value;
366 _use_padding = use_padding;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100367
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000368 if(sampling_policy == SamplingPolicy::CENTER)
369 {
370 _sampling_offset = 0.5f;
371 }
372
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100373 // Compute the ratio between source width/height and destination width/height
374 const auto wr = static_cast<float>(input->info()->dimension(idx_width)) / static_cast<float>(output->info()->dimension(idx_width));
375 const auto hr = static_cast<float>(input->info()->dimension(idx_height)) / static_cast<float>(output->info()->dimension(idx_height));
376
377 // Add constant border only on top in case of NHWC layout
378 if(data_layout == DataLayout::NHWC)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100379 {
George Wort05398a92019-01-25 15:38:33 +0000380 _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 +0100381 }
382
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100383 // Area interpolation behaves as Nearest Neighbour in case of up-sampling
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100384 if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
385 {
386 policy = InterpolationPolicy::NEAREST_NEIGHBOR;
387 }
388
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100389 // Select interpolation function
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100390 switch(policy)
391 {
392 case InterpolationPolicy::NEAREST_NEIGHBOR:
393 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100394 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100395 break;
396 }
397 case InterpolationPolicy::BILINEAR:
398 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100399 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100400 break;
401 }
402 case InterpolationPolicy::AREA:
403 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100404 _func = &NEScaleKernel::scale_area_nchw;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100405 break;
406 }
407 default:
408 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
409 }
410
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100411 // Configure window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100412 std::pair<Status, Window> win_config = validate_and_configure_window(input->info(),
413 dx != nullptr ? dx->info() : nullptr,
414 dy != nullptr ? dy->info() : nullptr,
415 offsets != nullptr ? offsets->info() : nullptr,
416 output->info(),
George Wort05398a92019-01-25 15:38:33 +0000417 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size(), use_padding);
418
Georgios Pinitas20b43132018-05-14 16:05:23 +0100419 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
420 INEKernel::configure(win_config.second);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100421}
422
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100423void NEScaleKernel::scale_nearest_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100424{
425 const size_t input_stride = _input->info()->strides_in_bytes()[1];
426
427 // Compute the ratio between source height and destination height
428 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
429
430 // Don't increment in X and Y direction for the input tensor
431 // A pointer to the start of this plane is needed as base for the precomputed offsets
432 Window win_in(window);
433 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
434 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
435
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100436 // Set offsets window
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100437 Window win_off;
438 win_off.set(Window::DimX, window[Window::DimX]);
439 win_off.set(Window::DimY, window[Window::DimY]);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100440 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
441 {
442 win_off.set(d, Window::Dimension(0, 0, 0));
443 }
444
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100445 // Create iterators
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100446 Iterator in(_input, win_in);
447 Iterator out(_output, window);
448 Iterator offsets(_offsets, win_off);
449
450 switch(_input->info()->data_type())
451 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000452 case DataType::QASYMM8:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100453 case DataType::U8:
454 {
455 uint8x16_t tmp = vdupq_n_u8(0);
456
457 execute_window_loop(window, [&](const Coordinates & id)
458 {
459 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
460 const uint8_t *const in_ptr = in.ptr();
461
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100462 const int in_yi = std::floor((id.y() + 0.5f) * hr);
463 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
464 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
465 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100466
467 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
468 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
469 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
470 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
471 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
472 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
473 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
474 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
475 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
476 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
477 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
478 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
479 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
480 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
481 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
482 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
483
484 vst1q_u8(out.ptr(), tmp);
485 },
486 in, offsets, out);
487 break;
488 }
489 case DataType::S16:
490 {
491 int16x8x2_t tmp =
492 {
493 {
494 vdupq_n_s16(0),
495 vdupq_n_s16(0)
496 }
497 };
498
499 execute_window_loop(window, [&](const Coordinates & id)
500 {
501 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
502
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100503 const int in_yi = (id.y() + 0.5f) * hr;
504 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100505
506 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
507 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
508 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
509 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
510 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
511 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
512 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
513 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
514
515 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
516 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
517 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
518 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
519 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
520 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
521 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
522 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
523
524 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
525 },
526 in, offsets, out);
527 break;
528 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000529#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
530 case DataType::F16:
531 {
532 float16x8x2_t tmp =
533 {
534 {
535 vdupq_n_f16(0),
536 vdupq_n_f16(0)
537 }
538 };
539
540 execute_window_loop(window, [&](const Coordinates & id)
541 {
542 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
543
544 const int in_yi = (id.y() + 0.5f) * hr;
545 const int offset_row = in_yi * input_stride;
546
547 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
548 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
549 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
550 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
551 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
552 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
553 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
554 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
555
556 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
557 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
558 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
559 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
560 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
561 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
562 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
563 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
564
565 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
566 },
567 in, offsets, out);
568 break;
569 }
570#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100571 case DataType::F32:
572 {
573 float32x4x4_t tmp =
574 {
575 {
576 vdupq_n_f32(0),
577 vdupq_n_f32(0),
578 vdupq_n_f32(0),
579 vdupq_n_f32(0)
580 }
581 };
582
583 execute_window_loop(window, [&](const Coordinates & id)
584 {
585 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
586
587 const int in_yi = (id.y() + 0.5f) * hr;
588 const int offset_row = in_yi * input_stride;
589
590 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
591 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
592 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
593 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
594
595 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
596 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
597 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
598 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
599
600 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
601 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
602 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
603 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
604
605 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
606 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
607 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
608 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
609
610 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
611 },
612 in, offsets, out);
613 break;
614 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100615 default:
616 ARM_COMPUTE_ERROR("Not supported");
617 break;
618 }
619}
620
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100621void NEScaleKernel::scale_bilinear_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100622{
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000623 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 +0100624
625 // Compute the ratio between source height and destination height
626 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
627
628 // Don't increment in X and Y direction for the input tensor
629 // A pointer to the start of this plane is needed as base for the precomputed offsets
630 Window win_in(window);
631 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
632 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
633
634 Window win_off;
635 win_off.set(Window::DimX, window.x());
636 win_off.set(Window::DimY, window.y());
637
638 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
639 {
640 win_off.set(d, Window::Dimension(0, 0, 0));
641 }
642
643 Iterator in(_input, win_in);
644 Iterator out(_output, window);
645 Iterator offsets(_offsets, win_off);
646 Iterator dx(_dx, win_off);
647 Iterator dy(_dy, win_off);
648
649 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100650 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
651 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100652
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000653 const bool is_quantized = (_input->info()->data_type() == DataType::QASYMM8);
654 const QuantizationInfo iq_info = _input->info()->quantization_info();
655 const QuantizationInfo oq_info = _output->info()->quantization_info();
656
Georgios Pinitas583137c2017-08-31 18:12:42 +0100657 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100658 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000659 case DataType::QASYMM8:
Georgios Pinitas583137c2017-08-31 18:12:42 +0100660 case DataType::U8:
661 {
662 execute_window_loop(window, [&](const Coordinates & id)
663 {
664 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
665 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
666 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
667 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100668
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000669 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100670 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100671
Georgios Pinitas583137c2017-08-31 18:12:42 +0100672 uint8x8_t tmp0 = vdup_n_u8(0);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000673 if(is_quantized)
674 {
675 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);
676 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);
677 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);
678 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);
679 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);
680 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);
681 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);
682 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);
683 }
684 else
685 {
686 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
687 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
688 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
689 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
690 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
691 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
692 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
693 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7);
694 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100695 uint8x8_t tmp1 = vdup_n_u8(0);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000696 if(is_quantized)
697 {
698 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);
699 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);
700 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);
701 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);
702 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);
703 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);
704 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);
705 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);
706 }
707 else
708 {
709 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
710 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
711 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
712 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
713 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
714 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
715 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
716 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7);
717 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100718 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
719 },
720 in, offsets, dx, dy, out);
721 break;
722 }
723 case DataType::S16:
724 {
725 execute_window_loop(window, [&](const Coordinates & id)
726 {
727 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
728 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
729 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
730
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000731 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100732 const int offset_row = in_yi * in_stide_in_bytes;
733
734 int16x8x2_t tmp =
735 {
736 {
737 vdupq_n_s16(0),
738 vdupq_n_s16(0)
739 }
740 };
741
742 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);
743 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);
744 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);
745 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);
746 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);
747 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);
748 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);
749 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);
750
751 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);
752 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);
753 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);
754 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);
755 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);
756 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);
757 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);
758 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);
759
760 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
761 },
762 in, offsets, dx, dy, out);
763 break;
764 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000765#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
766 case DataType::F16:
767 {
768 execute_window_loop(window, [&](const Coordinates & id)
769 {
770 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
771 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
772 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
773
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000774 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000775 const int offset_row = in_yi * in_stide_in_bytes;
776
777 float16x8x2_t tmp =
778 {
779 {
780 vdupq_n_f16(0),
781 vdupq_n_f16(0)
782 }
783 };
784
785 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);
786 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);
787 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);
788 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);
789 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);
790 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);
791 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);
792 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);
793
794 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);
795 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);
796 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);
797 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);
798 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);
799 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);
800 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);
801 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);
802
803 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
804 },
805 in, offsets, dx, dy, out);
806 break;
807 }
808#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100809 case DataType::F32:
810 {
811 execute_window_loop(window, [&](const Coordinates & id)
812 {
813 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
814 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
815 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
816
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000817 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100818 const int offset_row = in_yi * in_stide_in_bytes;
819
820 float32x4x4_t tmp =
821 {
822 {
823 vdupq_n_f32(0),
824 vdupq_n_f32(0),
825 vdupq_n_f32(0),
826 vdupq_n_f32(0)
827 }
828 };
829
830 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);
831 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);
832 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);
833 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);
834
835 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);
836 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);
837 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);
838 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);
839
840 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);
841 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);
842 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);
843 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);
844
845 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);
846 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);
847 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);
848 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);
849
850 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
851 },
852 in, offsets, dx, dy, out);
853 break;
854 }
855 default:
856 ARM_COMPUTE_ERROR("Not supported");
857 break;
858 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100859}
860
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100861void NEScaleKernel::scale_area_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100862{
863 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
864
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100865 // Don't increment in width/height/channels for the input tensor
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100866 // A pointer to the start of this plane is needed as base for the precomputed offsets
867 Window win_in(window);
868 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
869 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100870 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100871
872 Iterator in(_input, win_in);
873 Iterator out(_output, window);
874
875 const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0));
876 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
877 const auto w = _input->info()->dimension(0);
878 const auto h = _input->info()->dimension(1);
879 const size_t in_stride = _input->info()->strides_in_bytes()[1];
880
881 execute_window_loop(window, [&](const Coordinates & id)
882 {
883 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
884
885 uint8x8_t tmp0 = vdup_n_u8(0);
886 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
887 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
888 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
889 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
890 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
891 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
892 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
893 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
894
895 uint8x8_t tmp1 = vdup_n_u8(0);
896 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
897 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
898 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
899 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
900 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
901 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
902 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
903 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
904
905 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
906 },
907 in, out);
908}
909
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100910void NEScaleKernel::scale_nhwc(const Window &window)
911{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100912 // Get data layout and width/height indices
913 const DataLayout data_layout = _input->info()->data_layout();
914 const int idx_channels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
915 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
916 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
917
918 const size_t input_stride_w = _input->info()->strides_in_bytes()[idx_width];
919 const size_t input_stride_h = _input->info()->strides_in_bytes()[idx_height];
920 const size_t input_stride_c = _input->info()->strides_in_bytes()[idx_channels];
921
922 // Compute the ratio between source height and destination height
923 const auto hr = static_cast<float>(_input->info()->dimension(idx_height)) / static_cast<float>(_output->info()->dimension(idx_height));
924
925 // Don't increment in width/height/channels for the input tensor
926 // A pointer to the start of this plane is needed as base for the precomputed offsets
927 Window win_in(window);
928 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
929 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
930 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
931
932 switch(_input->info()->data_type())
933 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000934 case DataType::QASYMM8:
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100935 case DataType::U8:
936 {
937 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
938 {
939 scale_nearest_nhwc_core<uint8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
940 }
941 else
942 {
George Wort05398a92019-01-25 15:38:33 +0000943 scale_bilinear_nhwc_core<uint8_t, uint8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
944 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 +0100945 }
946 break;
947 }
948 case DataType::S16:
949 {
950 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
951 {
952 scale_nearest_nhwc_core<int16_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
953 }
954 else
955 {
George Wort05398a92019-01-25 15:38:33 +0000956 scale_bilinear_nhwc_core<int16_t, int16_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
957 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 +0100958 }
959 break;
960 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000961#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
962 case DataType::F16:
963 {
964 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
965 {
966 scale_nearest_nhwc_core<float16_t>(_input, _offsets, _output, hr,
967 window, win_in, input_stride_w, input_stride_h, input_stride_c);
968 }
969 else
970 {
George Wort05398a92019-01-25 15:38:33 +0000971 scale_bilinear_nhwc_core<float16_t, half>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
972 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 +0000973 }
974 break;
975 }
976#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100977 case DataType::F32:
978 {
979 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
980 {
981 scale_nearest_nhwc_core<float>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
982 }
983 else
984 {
George Wort05398a92019-01-25 15:38:33 +0000985 scale_bilinear_nhwc_core<float, float>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
986 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 +0100987 }
988 break;
989 }
990 default:
991 ARM_COMPUTE_ERROR("Not supported");
992 break;
993 }
994}
995
Georgios Pinitas20b43132018-05-14 16:05:23 +0100996Status NEScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
997 const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy,
George Wort05398a92019-01-25 15:38:33 +0000998 BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +0100999{
1000 BorderSize border_size(1);
1001 if(input->data_layout() == DataLayout::NHWC)
1002 {
1003 border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
1004 }
1005
George Wort05398a92019-01-25 15:38:33 +00001006 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 +01001007 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
1008 dx != nullptr ? dx->clone().get() : nullptr,
1009 dy != nullptr ? dy->clone().get() : nullptr,
1010 offsets != nullptr ? offsets->clone().get() : nullptr,
1011 output->clone().get(),
George Wort05398a92019-01-25 15:38:33 +00001012 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size, use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +01001013 .first);
1014
1015 return Status{};
1016}
1017
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001018void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001019{
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001020 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001021 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
1022 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
1023 ARM_COMPUTE_ERROR_ON(_func == nullptr);
1024
1025 (this->*_func)(window);
1026}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001027} // namespace arm_compute