blob: 8c4a70cdadfa67e123526d9d63d569e2aa92a96a [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 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100252 T a00 = 0, a01 = 0, a10 = 0, a11 = 0;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100253
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100254 if(border_mode == BorderMode::CONSTANT)
255 {
George Wort05398a92019-01-25 15:38:33 +0000256 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : border_value;
257 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : border_value;
258 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : border_value;
259 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 +0100260 }
261 else if(border_mode == BorderMode::REPLICATE)
262 {
263 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
264 auto clamped_x1 = utility::clamp<int>(offset + 1, 0, input_width - 1);
265 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
266 auto clamped_y1 = utility::clamp<int>(in_yi + 1, 0, input_height - 1);
267
268 a00 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
269 a01 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y * stride_h + id.x() * stride_c);
270 a10 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
271 a11 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
272 }
273 else
274 {
275 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : 0;
276 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : 0;
277 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : 0;
278 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;
279 }
280
281 // Perform interpolation
282 const float dx1 = 1.0f - dx_scale;
283 const float dy1 = 1.0f - dy_scale;
284
285 const float w1 = dx1 * dy1;
286 const float w2 = dx_scale * dy1;
287 const float w3 = dx1 * dy_scale;
288 const float w4 = dx_scale * dy_scale;
289
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000290 T res = 0;
291 //dequantize quantized input
292 if(is_quantized)
293 {
294 float inp00 = iq_info.dequantize(a00);
295 float inp01 = iq_info.dequantize(a01);
296 float inp10 = iq_info.dequantize(a10);
297 float inp11 = iq_info.dequantize(a11);
298 res = static_cast<T>(oq_info.quantize((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), RoundingPolicy::TO_NEAREST_UP));
299 }
300 else
301 {
302 res = static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4);
303 }
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100304 // Store result
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000305 *reinterpret_cast<T *>(out.ptr()) = res;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100306 }
307 else
308 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100309 if(border_mode == BorderMode::CONSTANT)
310 {
George Wort05398a92019-01-25 15:38:33 +0000311 *reinterpret_cast<T *>(out.ptr()) = border_value;
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100312 }
313 else if(border_mode == BorderMode::REPLICATE)
314 {
315 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
316 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
317 *reinterpret_cast<T *>(out.ptr()) = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
318 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100319 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100320 },
321 in, out);
322}
323} // namespace
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100324
325NEScaleKernel::NEScaleKernel()
Manuel Bottinif00d3322019-03-05 15:53:25 +0000326 : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_size(1), _border_mode(), _constant_border_value(PixelValue()),
327 _sampling_offset(0), _use_padding(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100328{
329}
330
331BorderSize NEScaleKernel::border_size() const
332{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100333 return _border_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100334}
335
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100336void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets,
George Wort05398a92019-01-25 15:38:33 +0000337 ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy,
338 bool use_padding)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100339{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100340 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100341 // Perform validation step
342 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
343 dx != nullptr ? dx->info() : nullptr,
344 dy != nullptr ? dy->info() : nullptr,
345 offsets != nullptr ? offsets->info() : nullptr,
346 output->info(),
George Wort05398a92019-01-25 15:38:33 +0000347 policy, border_mode, constant_border_value, sampling_policy, use_padding));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100348
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100349 // Get data layout and width/height indices
350 const DataLayout data_layout = input->info()->data_layout();
351 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
352 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353
George Wort05398a92019-01-25 15:38:33 +0000354 _input = input;
355 _output = output;
356 _offsets = offsets;
357 _dx = dx;
358 _dy = dy;
359 _policy = policy;
360 _border_size = BorderSize(1);
361 _border_mode = border_mode;
362 _constant_border_value = constant_border_value;
363 _use_padding = use_padding;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100364
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000365 if(sampling_policy == SamplingPolicy::CENTER)
366 {
367 _sampling_offset = 0.5f;
368 }
369
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100370 // Compute the ratio between source width/height and destination width/height
371 const auto wr = static_cast<float>(input->info()->dimension(idx_width)) / static_cast<float>(output->info()->dimension(idx_width));
372 const auto hr = static_cast<float>(input->info()->dimension(idx_height)) / static_cast<float>(output->info()->dimension(idx_height));
373
374 // Add constant border only on top in case of NHWC layout
375 if(data_layout == DataLayout::NHWC)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100376 {
George Wort05398a92019-01-25 15:38:33 +0000377 _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 +0100378 }
379
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100380 // Area interpolation behaves as Nearest Neighbour in case of up-sampling
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100381 if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
382 {
383 policy = InterpolationPolicy::NEAREST_NEIGHBOR;
384 }
385
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100386 // Select interpolation function
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100387 switch(policy)
388 {
389 case InterpolationPolicy::NEAREST_NEIGHBOR:
390 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100391 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100392 break;
393 }
394 case InterpolationPolicy::BILINEAR:
395 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100396 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100397 break;
398 }
399 case InterpolationPolicy::AREA:
400 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100401 _func = &NEScaleKernel::scale_area_nchw;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100402 break;
403 }
404 default:
405 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
406 }
407
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100408 // Configure window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100409 std::pair<Status, Window> win_config = validate_and_configure_window(input->info(),
410 dx != nullptr ? dx->info() : nullptr,
411 dy != nullptr ? dy->info() : nullptr,
412 offsets != nullptr ? offsets->info() : nullptr,
413 output->info(),
George Wort05398a92019-01-25 15:38:33 +0000414 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size(), use_padding);
415
Georgios Pinitas20b43132018-05-14 16:05:23 +0100416 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
417 INEKernel::configure(win_config.second);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100418}
419
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100420void NEScaleKernel::scale_nearest_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100421{
422 const size_t input_stride = _input->info()->strides_in_bytes()[1];
423
424 // Compute the ratio between source height and destination height
425 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
426
427 // Don't increment in X and Y direction for the input tensor
428 // A pointer to the start of this plane is needed as base for the precomputed offsets
429 Window win_in(window);
430 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
431 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
432
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100433 // Set offsets window
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100434 Window win_off;
435 win_off.set(Window::DimX, window[Window::DimX]);
436 win_off.set(Window::DimY, window[Window::DimY]);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100437 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
438 {
439 win_off.set(d, Window::Dimension(0, 0, 0));
440 }
441
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100442 // Create iterators
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100443 Iterator in(_input, win_in);
444 Iterator out(_output, window);
445 Iterator offsets(_offsets, win_off);
446
447 switch(_input->info()->data_type())
448 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000449 case DataType::QASYMM8:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100450 case DataType::U8:
451 {
452 uint8x16_t tmp = vdupq_n_u8(0);
453
454 execute_window_loop(window, [&](const Coordinates & id)
455 {
456 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
457 const uint8_t *const in_ptr = in.ptr();
458
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100459 const int in_yi = std::floor((id.y() + 0.5f) * hr);
460 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
461 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
462 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100463
464 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
465 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
466 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
467 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
468 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
469 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
470 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
471 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
472 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
473 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
474 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
475 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
476 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
477 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
478 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
479 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
480
481 vst1q_u8(out.ptr(), tmp);
482 },
483 in, offsets, out);
484 break;
485 }
486 case DataType::S16:
487 {
488 int16x8x2_t tmp =
489 {
490 {
491 vdupq_n_s16(0),
492 vdupq_n_s16(0)
493 }
494 };
495
496 execute_window_loop(window, [&](const Coordinates & id)
497 {
498 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
499
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100500 const int in_yi = (id.y() + 0.5f) * hr;
501 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100502
503 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
504 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
505 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
506 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
507 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
508 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
509 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
510 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
511
512 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
513 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
514 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
515 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
516 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
517 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
518 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
519 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
520
521 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
522 },
523 in, offsets, out);
524 break;
525 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000526#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
527 case DataType::F16:
528 {
529 float16x8x2_t tmp =
530 {
531 {
532 vdupq_n_f16(0),
533 vdupq_n_f16(0)
534 }
535 };
536
537 execute_window_loop(window, [&](const Coordinates & id)
538 {
539 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
540
541 const int in_yi = (id.y() + 0.5f) * hr;
542 const int offset_row = in_yi * input_stride;
543
544 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
545 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
546 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
547 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
548 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
549 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
550 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
551 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
552
553 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
554 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
555 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
556 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
557 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
558 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
559 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
560 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
561
562 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
563 },
564 in, offsets, out);
565 break;
566 }
567#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100568 case DataType::F32:
569 {
570 float32x4x4_t tmp =
571 {
572 {
573 vdupq_n_f32(0),
574 vdupq_n_f32(0),
575 vdupq_n_f32(0),
576 vdupq_n_f32(0)
577 }
578 };
579
580 execute_window_loop(window, [&](const Coordinates & id)
581 {
582 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
583
584 const int in_yi = (id.y() + 0.5f) * hr;
585 const int offset_row = in_yi * input_stride;
586
587 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
588 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
589 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
590 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
591
592 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
593 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
594 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
595 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
596
597 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
598 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
599 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
600 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
601
602 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
603 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
604 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
605 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
606
607 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
608 },
609 in, offsets, out);
610 break;
611 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100612 default:
613 ARM_COMPUTE_ERROR("Not supported");
614 break;
615 }
616}
617
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100618void NEScaleKernel::scale_bilinear_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100619{
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000620 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 +0100621
622 // Compute the ratio between source height and destination height
623 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
624
625 // Don't increment in X and Y direction for the input tensor
626 // A pointer to the start of this plane is needed as base for the precomputed offsets
627 Window win_in(window);
628 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
629 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
630
631 Window win_off;
632 win_off.set(Window::DimX, window.x());
633 win_off.set(Window::DimY, window.y());
634
635 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
636 {
637 win_off.set(d, Window::Dimension(0, 0, 0));
638 }
639
640 Iterator in(_input, win_in);
641 Iterator out(_output, window);
642 Iterator offsets(_offsets, win_off);
643 Iterator dx(_dx, win_off);
644 Iterator dy(_dy, win_off);
645
646 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100647 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
648 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100649
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000650 const bool is_quantized = (_input->info()->data_type() == DataType::QASYMM8);
651 const QuantizationInfo iq_info = _input->info()->quantization_info();
652 const QuantizationInfo oq_info = _output->info()->quantization_info();
653
Georgios Pinitas583137c2017-08-31 18:12:42 +0100654 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100655 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000656 case DataType::QASYMM8:
Georgios Pinitas583137c2017-08-31 18:12:42 +0100657 case DataType::U8:
658 {
659 execute_window_loop(window, [&](const Coordinates & id)
660 {
661 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
662 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
663 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
664 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100665
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000666 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100667 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100668
Georgios Pinitas583137c2017-08-31 18:12:42 +0100669 uint8x8_t tmp0 = vdup_n_u8(0);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000670 if(is_quantized)
671 {
672 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);
673 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);
674 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);
675 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);
676 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);
677 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);
678 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);
679 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);
680 }
681 else
682 {
683 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
684 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
685 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
686 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
687 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
688 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
689 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
690 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7);
691 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100692 uint8x8_t tmp1 = vdup_n_u8(0);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000693 if(is_quantized)
694 {
695 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);
696 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);
697 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);
698 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);
699 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);
700 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);
701 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);
702 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);
703 }
704 else
705 {
706 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
707 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
708 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
709 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
710 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
711 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
712 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
713 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7);
714 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100715 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
716 },
717 in, offsets, dx, dy, out);
718 break;
719 }
720 case DataType::S16:
721 {
722 execute_window_loop(window, [&](const Coordinates & id)
723 {
724 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
725 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
726 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
727
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000728 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100729 const int offset_row = in_yi * in_stide_in_bytes;
730
731 int16x8x2_t tmp =
732 {
733 {
734 vdupq_n_s16(0),
735 vdupq_n_s16(0)
736 }
737 };
738
739 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);
740 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);
741 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);
742 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);
743 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);
744 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);
745 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);
746 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);
747
748 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);
749 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);
750 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);
751 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);
752 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);
753 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);
754 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);
755 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);
756
757 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
758 },
759 in, offsets, dx, dy, out);
760 break;
761 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000762#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
763 case DataType::F16:
764 {
765 execute_window_loop(window, [&](const Coordinates & id)
766 {
767 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
768 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
769 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
770
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000771 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000772 const int offset_row = in_yi * in_stide_in_bytes;
773
774 float16x8x2_t tmp =
775 {
776 {
777 vdupq_n_f16(0),
778 vdupq_n_f16(0)
779 }
780 };
781
782 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);
783 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);
784 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);
785 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);
786 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);
787 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);
788 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);
789 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);
790
791 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);
792 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);
793 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);
794 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);
795 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);
796 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);
797 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);
798 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);
799
800 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
801 },
802 in, offsets, dx, dy, out);
803 break;
804 }
805#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100806 case DataType::F32:
807 {
808 execute_window_loop(window, [&](const Coordinates & id)
809 {
810 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
811 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
812 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
813
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000814 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100815 const int offset_row = in_yi * in_stide_in_bytes;
816
817 float32x4x4_t tmp =
818 {
819 {
820 vdupq_n_f32(0),
821 vdupq_n_f32(0),
822 vdupq_n_f32(0),
823 vdupq_n_f32(0)
824 }
825 };
826
827 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);
828 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);
829 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);
830 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);
831
832 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);
833 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);
834 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);
835 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);
836
837 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);
838 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);
839 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);
840 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);
841
842 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);
843 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);
844 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);
845 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);
846
847 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
848 },
849 in, offsets, dx, dy, out);
850 break;
851 }
852 default:
853 ARM_COMPUTE_ERROR("Not supported");
854 break;
855 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100856}
857
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100858void NEScaleKernel::scale_area_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100859{
860 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
861
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100862 // Don't increment in width/height/channels for the input tensor
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100863 // A pointer to the start of this plane is needed as base for the precomputed offsets
864 Window win_in(window);
865 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
866 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100867 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100868
869 Iterator in(_input, win_in);
870 Iterator out(_output, window);
871
872 const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0));
873 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
874 const auto w = _input->info()->dimension(0);
875 const auto h = _input->info()->dimension(1);
876 const size_t in_stride = _input->info()->strides_in_bytes()[1];
877
878 execute_window_loop(window, [&](const Coordinates & id)
879 {
880 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
881
882 uint8x8_t tmp0 = vdup_n_u8(0);
883 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
884 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
885 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
886 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
887 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
888 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
889 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
890 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
891
892 uint8x8_t tmp1 = vdup_n_u8(0);
893 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
894 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
895 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
896 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
897 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
898 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
899 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
900 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
901
902 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
903 },
904 in, out);
905}
906
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100907void NEScaleKernel::scale_nhwc(const Window &window)
908{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100909 // Get data layout and width/height indices
910 const DataLayout data_layout = _input->info()->data_layout();
911 const int idx_channels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
912 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
913 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
914
915 const size_t input_stride_w = _input->info()->strides_in_bytes()[idx_width];
916 const size_t input_stride_h = _input->info()->strides_in_bytes()[idx_height];
917 const size_t input_stride_c = _input->info()->strides_in_bytes()[idx_channels];
918
919 // Compute the ratio between source height and destination height
920 const auto hr = static_cast<float>(_input->info()->dimension(idx_height)) / static_cast<float>(_output->info()->dimension(idx_height));
921
922 // Don't increment in width/height/channels for the input tensor
923 // A pointer to the start of this plane is needed as base for the precomputed offsets
924 Window win_in(window);
925 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
926 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
927 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
928
929 switch(_input->info()->data_type())
930 {
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000931 case DataType::QASYMM8:
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100932 case DataType::U8:
933 {
934 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
935 {
936 scale_nearest_nhwc_core<uint8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
937 }
938 else
939 {
George Wort05398a92019-01-25 15:38:33 +0000940 scale_bilinear_nhwc_core<uint8_t, uint8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
941 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 +0100942 }
943 break;
944 }
945 case DataType::S16:
946 {
947 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
948 {
949 scale_nearest_nhwc_core<int16_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
950 }
951 else
952 {
George Wort05398a92019-01-25 15:38:33 +0000953 scale_bilinear_nhwc_core<int16_t, int16_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
954 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 +0100955 }
956 break;
957 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000958#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
959 case DataType::F16:
960 {
961 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
962 {
963 scale_nearest_nhwc_core<float16_t>(_input, _offsets, _output, hr,
964 window, win_in, input_stride_w, input_stride_h, input_stride_c);
965 }
966 else
967 {
George Wort05398a92019-01-25 15:38:33 +0000968 scale_bilinear_nhwc_core<float16_t, half>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
969 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 +0000970 }
971 break;
972 }
973#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100974 case DataType::F32:
975 {
976 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
977 {
978 scale_nearest_nhwc_core<float>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c);
979 }
980 else
981 {
George Wort05398a92019-01-25 15:38:33 +0000982 scale_bilinear_nhwc_core<float, float>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
983 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 +0100984 }
985 break;
986 }
987 default:
988 ARM_COMPUTE_ERROR("Not supported");
989 break;
990 }
991}
992
Georgios Pinitas20b43132018-05-14 16:05:23 +0100993Status NEScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
994 const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy,
George Wort05398a92019-01-25 15:38:33 +0000995 BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +0100996{
997 BorderSize border_size(1);
998 if(input->data_layout() == DataLayout::NHWC)
999 {
1000 border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
1001 }
1002
George Wort05398a92019-01-25 15:38:33 +00001003 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 +01001004 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
1005 dx != nullptr ? dx->clone().get() : nullptr,
1006 dy != nullptr ? dy->clone().get() : nullptr,
1007 offsets != nullptr ? offsets->clone().get() : nullptr,
1008 output->clone().get(),
George Wort05398a92019-01-25 15:38:33 +00001009 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size, use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +01001010 .first);
1011
1012 return Status{};
1013}
1014
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001015void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001016{
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001017 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001018 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
1019 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
1020 ARM_COMPUTE_ERROR_ON(_func == nullptr);
1021
1022 (this->*_func)(window);
1023}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001024} // namespace arm_compute