blob: 4f2f925c3c69c8538687c3510da8e4cec502285a [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitasa5eb5912020-01-07 17:37:14 +00002 * Copyright (c) 2016-2020 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/Helpers.h"
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010029#include "arm_compute/core/NEON/wrapper/wrapper.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030#include "arm_compute/core/Window.h"
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010031#include "arm_compute/core/utils/misc/Utility.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
33#include <arm_neon.h>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010035namespace arm_compute
36{
37namespace
38{
Georgios Pinitas20b43132018-05-14 16:05:23 +010039Status validate_arguments(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
40 const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy,
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +000041 BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding, bool align_corners)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010042{
Georgios Pinitasc47ef202018-11-16 18:19:43 +000043 ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input);
Sheri Zhang359c48e2020-04-30 22:53:39 +010044 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16, DataType::F16, DataType::F32, DataType::QASYMM8, DataType::QASYMM8_SIGNED);
Georgios Pinitas20b43132018-05-14 16:05:23 +010045 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
46 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
47 ARM_COMPUTE_RETURN_ERROR_ON(output == input);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +000048 ARM_COMPUTE_RETURN_ERROR_ON(sampling_policy != SamplingPolicy::CENTER && sampling_policy != SamplingPolicy::TOP_LEFT);
George Wort05398a92019-01-25 15:38:33 +000049 ARM_COMPUTE_RETURN_ERROR_ON(!use_padding && border_mode != BorderMode::CONSTANT);
50 ARM_COMPUTE_UNUSED(constant_border_value);
Georgios Pinitas20b43132018-05-14 16:05:23 +010051
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +000052 const DataLayout data_layout = input->data_layout();
53 const auto width_index = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
54 const auto height_index = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
55 const auto output_width = output->dimension(width_index);
56 const auto output_height = output->dimension(height_index);
57 ARM_COMPUTE_RETURN_ERROR_ON(output_width == 0);
58 ARM_COMPUTE_RETURN_ERROR_ON(output_height == 0);
Georgios Pinitas20b43132018-05-14 16:05:23 +010059
60 if(policy == InterpolationPolicy::NEAREST_NEIGHBOR)
61 {
62 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
63 }
64
65 if(policy == InterpolationPolicy::BILINEAR)
66 {
67 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
68 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32);
69 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32);
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +000070
71 if(align_corners)
72 {
73 // For bilinear method with aligned corners, the resize ratio will
74 // be calculated by (input_size - 1)/(output_size - 1). Belows are
75 // checking possible overflows.
76 const auto input_width = input->dimension(width_index);
77 const auto input_height = input->dimension(height_index);
78
79 ARM_COMPUTE_RETURN_ERROR_ON(input_width == 0 || input_height == 0);
80 ARM_COMPUTE_RETURN_ERROR_ON((output_width - 1 == 0) || (output_height - 1 == 0));
81 }
Georgios Pinitas20b43132018-05-14 16:05:23 +010082 }
83
84 if(policy == InterpolationPolicy::AREA)
85 {
86 ARM_COMPUTE_RETURN_ERROR_ON(data_layout != DataLayout::NCHW);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +000087 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
Georgios Pinitas20b43132018-05-14 16:05:23 +010088 }
89
90 return Status{};
91}
92
93std::pair<Status, Window> validate_and_configure_window_nchw(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output,
94 InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size)
95{
96 bool window_changed{ false };
97 Window win{};
98
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010099 constexpr unsigned int num_elems_processed_per_iteration = 16;
100
101 // Configure kernel window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100102 win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100103
Georgios Pinitas20b43132018-05-14 16:05:23 +0100104 const ValidRegion &input_valid_region = input->valid_region();
105
106 if(offsets != nullptr)
107 {
108 AccessWindowHorizontal offsets_access(offsets, 0, num_elems_processed_per_iteration);
109 window_changed = window_changed || update_window_and_padding(win, offsets_access);
110 }
111 if(dx != nullptr && dy != nullptr)
112 {
113 AccessWindowHorizontal dx_access(dx, 0, num_elems_processed_per_iteration);
114 AccessWindowHorizontal dy_access(dy, 0, num_elems_processed_per_iteration);
115 window_changed = window_changed || update_window_and_padding(win, dx_access, dy_access);
116 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100117
118 // Reads can occur within the valid region of the input
Georgios Pinitas20b43132018-05-14 16:05:23 +0100119 AccessWindowStatic input_access(input, input_valid_region.anchor[0] - border_size.left,
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100120 input_valid_region.anchor[1] - border_size.top,
121 input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size.right,
122 input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size.bottom);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100123 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
124 window_changed = window_changed || update_window_and_padding(win, input_access, output_access);
125 output_access.set_valid_region(win, calculate_valid_region_scale(*input, output->tensor_shape(),
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100126 policy, sampling_policy, border_undefined));
127
Georgios Pinitas20b43132018-05-14 16:05:23 +0100128 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
129 return std::make_pair(err, win);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100130}
Georgios Pinitas20b43132018-05-14 16:05:23 +0100131
132std::pair<Status, Window> validate_and_configure_window_nhwc(ITensorInfo *input, ITensorInfo *output,
133 InterpolationPolicy policy, bool border_undefined,
George Wort05398a92019-01-25 15:38:33 +0000134 SamplingPolicy sampling_policy, BorderSize border_size, bool use_padding)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100135{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100136 bool window_changed{ false };
137 Window win{};
138
George Wort05398a92019-01-25 15:38:33 +0000139 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 +0100140
141 // Configure kernel window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100142 win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100143
George Wort05398a92019-01-25 15:38:33 +0000144 if(use_padding)
145 {
Georgios Pinitas32620422019-06-27 17:14:32 +0100146 AccessWindowStatic input_access(input, 0, -border_size.top, ceil_to_multiple(input->tensor_shape()[0], num_elems_processed_per_iteration), input->tensor_shape()[1]);
George Wort05398a92019-01-25 15:38:33 +0000147 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
148 window_changed = update_window_and_padding(win, input_access, output_access);
149 output->set_valid_region(calculate_valid_region_scale(*input, output->tensor_shape(), policy, sampling_policy, border_undefined));
150 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100151
Georgios Pinitas20b43132018-05-14 16:05:23 +0100152 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
153 return std::make_pair(err, win);
154}
155
156std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output,
George Wort05398a92019-01-25 15:38:33 +0000157 InterpolationPolicy policy, bool border_undefined, SamplingPolicy sampling_policy, BorderSize border_size, bool use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +0100158{
159 std::pair<Status, Window> win_config;
160 switch(input->data_layout())
161 {
162 case DataLayout::NCHW:
George Wort05398a92019-01-25 15:38:33 +0000163 if(!use_padding)
164 {
165 return std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Padding required for NCHW"), Window{});
166 }
Georgios Pinitas20b43132018-05-14 16:05:23 +0100167 win_config = validate_and_configure_window_nchw(input, dx, dy, offsets, output, policy, border_undefined, sampling_policy, border_size);
168 break;
169 case DataLayout::NHWC:
George Wort05398a92019-01-25 15:38:33 +0000170 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 +0100171 break;
172 default:
173 win_config = std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported data layout!"), Window{});
174 }
175
176 return win_config;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100177}
178
179template <typename T>
180inline void scale_nearest_nhwc_core(const ITensor *input, const ITensor *offsets, ITensor *output,
Michalis Spyroud4733862019-07-09 14:21:06 +0100181 float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c, float sampling_offset)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100182{
George Wort05398a92019-01-25 15:38:33 +0000183 const int window_step_x = 16 / sizeof(T);
184 const auto window_start_x = static_cast<int32_t>(window.x().start());
185 const auto window_end_x = static_cast<int32_t>(window.x().end());
186
187 window.set(Window::DimX, Window::Dimension(0, 1, 1));
188
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100189 Iterator in(input, win_in);
190 Iterator out(output, window);
191
192 const size_t offsets_stride = stride_w / sizeof(T);
193
194 execute_window_loop(window, [&](const Coordinates & id)
195 {
George Wort05398a92019-01-25 15:38:33 +0000196 const int32_t offset = *reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z())));
Michalis Spyroud4733862019-07-09 14:21:06 +0100197 const int in_yi = std::floor((id.z() + sampling_offset) * hr);
George Wort05398a92019-01-25 15:38:33 +0000198 const int offset_row = in_yi * stride_h;
199 int32_t x = window_start_x;
200 for(; x < window_end_x - window_step_x; x += window_step_x)
201 {
202 wrapper::vstore(reinterpret_cast<T *>(out.ptr()) + x,
203 wrapper::vloadq(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row + x * stride_c)));
204 }
205 for(; x < window_end_x; ++x)
206 {
207 *(reinterpret_cast<T *>(out.ptr()) + x) =
208 *(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row + x * stride_c));
209 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100210 },
211 in, out);
212}
213
George Wort05398a92019-01-25 15:38:33 +0000214template <typename T, typename ConstType>
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100215inline 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 +0000216 float hr, float sampling_offset, Window window, const Window &win_in, size_t stride_w, size_t stride_h,
217 size_t stride_c, BorderMode border_mode, PixelValue constant_border_value, bool use_padding)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100218{
219 Iterator in(input, win_in);
220 Iterator out(output, window);
221
222 const size_t stride_w_elems = stride_w / sizeof(T);
223 const size_t stride_h_elems = stride_h / sizeof(T);
224
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100225 const int input_width = input->info()->dimension(1);
226 const int input_height = input->info()->dimension(2);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100227
George Wort05398a92019-01-25 15:38:33 +0000228 T border_value;
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100229 if(use_padding && border_mode != BorderMode::REPLICATE)
George Wort05398a92019-01-25 15:38:33 +0000230 {
Pablo Tello10971472019-05-15 15:14:46 +0100231 // configure() sets top border to 0 for BorderMode::REPLICATE and border_value is not needed in execute_window_loop() for REPLICATE
George Wort05398a92019-01-25 15:38:33 +0000232 border_value = *reinterpret_cast<T *>(input->buffer() + input->info()->offset_first_element_in_bytes() - stride_w);
233 }
234 else
235 {
236 border_value = static_cast<T>(constant_border_value.get<ConstType>());
237 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100238
Michalis Spyroufae513c2019-10-16 17:41:33 +0100239 auto is_valid = [](int64_t x, int64_t low_x, int64_t high_x, int64_t y, int64_t low_y, int64_t high_y)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100240 {
241 return !(x < low_x || x > high_x || y < low_y || y > high_y);
242 };
243
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100244 int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1;
245
Sheri Zhang359c48e2020-04-30 22:53:39 +0100246 const UniformQuantizationInfo iq_info = input->info()->quantization_info().uniform();
247 const UniformQuantizationInfo oq_info = output->info()->quantization_info().uniform();
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000248
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100249 execute_window_loop(window, [&](const Coordinates & id)
250 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100251 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 +0100252 const auto dx_scale = *reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id.y(), id.z())));
253 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 +0000254 const int in_yi = std::floor((id.z() + sampling_offset) * hr - sampling_offset);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100255 const int offset_row = in_yi * stride_h + id.x() * stride_c;
256 const T *in_ptr = reinterpret_cast<T *>(in.ptr() + offset * stride_w + offset_row);
257
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100258 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 +0100259 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100260 T a00 = 0;
261 T a01 = 0;
262 T a10 = 0;
263 T a11 = 0;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100264
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100265 if(border_mode == BorderMode::CONSTANT)
266 {
George Wort05398a92019-01-25 15:38:33 +0000267 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : border_value;
268 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : border_value;
269 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : border_value;
270 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 +0100271 }
272 else if(border_mode == BorderMode::REPLICATE)
273 {
274 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
275 auto clamped_x1 = utility::clamp<int>(offset + 1, 0, input_width - 1);
276 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
277 auto clamped_y1 = utility::clamp<int>(in_yi + 1, 0, input_height - 1);
278
279 a00 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
280 a01 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y * stride_h + id.x() * stride_c);
281 a10 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
282 a11 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
283 }
284 else
285 {
286 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : 0;
287 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : 0;
288 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : 0;
289 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;
290 }
291
292 // Perform interpolation
293 const float dx1 = 1.0f - dx_scale;
294 const float dy1 = 1.0f - dy_scale;
295
296 const float w1 = dx1 * dy1;
297 const float w2 = dx_scale * dy1;
298 const float w3 = dx1 * dy_scale;
299 const float w4 = dx_scale * dy_scale;
300
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000301 T res = 0;
302 //dequantize quantized input
Sheri Zhang359c48e2020-04-30 22:53:39 +0100303 if(input->info()->data_type() == DataType::QASYMM8)
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000304 {
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100305 float inp00 = dequantize_qasymm8(a00, iq_info);
306 float inp01 = dequantize_qasymm8(a01, iq_info);
307 float inp10 = dequantize_qasymm8(a10, iq_info);
308 float inp11 = dequantize_qasymm8(a11, iq_info);
309 res = static_cast<T>(quantize_qasymm8((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), oq_info));
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000310 }
Sheri Zhang359c48e2020-04-30 22:53:39 +0100311 else if(input->info()->data_type() == DataType::QASYMM8_SIGNED)
312 {
313 float inp00 = dequantize_qasymm8_signed(a00, iq_info);
314 float inp01 = dequantize_qasymm8_signed(a01, iq_info);
315 float inp10 = dequantize_qasymm8_signed(a10, iq_info);
316 float inp11 = dequantize_qasymm8_signed(a11, iq_info);
317 res = static_cast<T>(quantize_qasymm8_signed((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), oq_info));
318 }
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000319 else
320 {
321 res = static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4);
322 }
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100323 // Store result
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000324 *reinterpret_cast<T *>(out.ptr()) = res;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100325 }
326 else
327 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100328 if(border_mode == BorderMode::CONSTANT)
329 {
George Wort05398a92019-01-25 15:38:33 +0000330 *reinterpret_cast<T *>(out.ptr()) = border_value;
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100331 }
332 else if(border_mode == BorderMode::REPLICATE)
333 {
334 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
335 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
336 *reinterpret_cast<T *>(out.ptr()) = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
337 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100338 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100339 },
340 in, out);
341}
342} // namespace
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343
344NEScaleKernel::NEScaleKernel()
Manuel Bottinif00d3322019-03-05 15:53:25 +0000345 : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_size(1), _border_mode(), _constant_border_value(PixelValue()),
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000346 _sampling_offset(0), _use_padding(true), _align_corners(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100347{
348}
349
350BorderSize NEScaleKernel::border_size() const
351{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100352 return _border_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353}
354
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100355void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets,
George Wort05398a92019-01-25 15:38:33 +0000356 ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy,
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000357 bool use_padding, bool align_corners)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100358{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100359 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100360 // Perform validation step
361 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
362 dx != nullptr ? dx->info() : nullptr,
363 dy != nullptr ? dy->info() : nullptr,
364 offsets != nullptr ? offsets->info() : nullptr,
365 output->info(),
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000366 policy, border_mode, constant_border_value, sampling_policy, use_padding, align_corners));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100367
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100368 // Get data layout and width/height indices
369 const DataLayout data_layout = input->info()->data_layout();
370 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
371 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100372
George Wort05398a92019-01-25 15:38:33 +0000373 _input = input;
374 _output = output;
375 _offsets = offsets;
376 _dx = dx;
377 _dy = dy;
378 _policy = policy;
379 _border_size = BorderSize(1);
380 _border_mode = border_mode;
381 _constant_border_value = constant_border_value;
382 _use_padding = use_padding;
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000383 _align_corners = _policy == InterpolationPolicy::BILINEAR
384 && sampling_policy == SamplingPolicy::TOP_LEFT
385 && align_corners;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100386
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000387 if(sampling_policy == SamplingPolicy::CENTER)
388 {
389 _sampling_offset = 0.5f;
390 }
391
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100392 // Compute the ratio between source width/height and destination width/height
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000393 const auto wr = arm_compute::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), _align_corners);
394 const auto hr = arm_compute::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), _align_corners);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100395
396 // Add constant border only on top in case of NHWC layout
397 if(data_layout == DataLayout::NHWC)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100398 {
Michalis Spyrouc050e0c2019-07-25 17:58:30 +0100399 _border_size = (border_mode != BorderMode::REPLICATE && policy == InterpolationPolicy::BILINEAR && use_padding) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100400 }
401
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100402 // Area interpolation behaves as Nearest Neighbour in case of up-sampling
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100403 if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
404 {
405 policy = InterpolationPolicy::NEAREST_NEIGHBOR;
406 }
407
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100408 // Select interpolation function
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100409 switch(policy)
410 {
411 case InterpolationPolicy::NEAREST_NEIGHBOR:
412 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100413 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100414 break;
415 }
416 case InterpolationPolicy::BILINEAR:
417 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100418 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100419 break;
420 }
421 case InterpolationPolicy::AREA:
422 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100423 _func = &NEScaleKernel::scale_area_nchw;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100424 break;
425 }
426 default:
427 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
428 }
429
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100430 // Configure window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100431 std::pair<Status, Window> win_config = validate_and_configure_window(input->info(),
432 dx != nullptr ? dx->info() : nullptr,
433 dy != nullptr ? dy->info() : nullptr,
434 offsets != nullptr ? offsets->info() : nullptr,
435 output->info(),
George Wort05398a92019-01-25 15:38:33 +0000436 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size(), use_padding);
437
Georgios Pinitas20b43132018-05-14 16:05:23 +0100438 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
439 INEKernel::configure(win_config.second);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100440}
441
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100442void NEScaleKernel::scale_nearest_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100443{
444 const size_t input_stride = _input->info()->strides_in_bytes()[1];
445
446 // Compute the ratio between source height and destination height
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000447 const auto hr = arm_compute::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100448
449 // Don't increment in X and Y direction for the input tensor
450 // A pointer to the start of this plane is needed as base for the precomputed offsets
451 Window win_in(window);
452 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
453 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
454
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100455 // Set offsets window
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100456 Window win_off;
457 win_off.set(Window::DimX, window[Window::DimX]);
458 win_off.set(Window::DimY, window[Window::DimY]);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100459 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
460 {
461 win_off.set(d, Window::Dimension(0, 0, 0));
462 }
463
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100464 // Create iterators
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100465 Iterator in(_input, win_in);
466 Iterator out(_output, window);
467 Iterator offsets(_offsets, win_off);
468
469 switch(_input->info()->data_type())
470 {
Sheri Zhang359c48e2020-04-30 22:53:39 +0100471 case DataType::QASYMM8_SIGNED:
472 {
473 int8x16_t tmp = vdupq_n_s8(0);
474
475 execute_window_loop(window, [&](const Coordinates & id)
476 {
477 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
478 const uint8_t *const in_ptr = in.ptr();
479
480 const int in_yi = std::floor((id.y() + _sampling_offset) * hr);
481 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
482 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
483 const int offset_row = in_yi_clamped * input_stride;
484
485 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
486 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
487 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
488 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
489 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
490 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
491 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
492 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
493 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
494 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
495 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
496 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
497 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
498 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
499 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
500 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
501
502 vst1q_s8(reinterpret_cast<int8_t *>(out.ptr()), tmp);
503 },
504 in, offsets, out);
505 break;
506 }
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000507 case DataType::QASYMM8:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100508 case DataType::U8:
509 {
510 uint8x16_t tmp = vdupq_n_u8(0);
511
512 execute_window_loop(window, [&](const Coordinates & id)
513 {
514 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
515 const uint8_t *const in_ptr = in.ptr();
516
Michalis Spyroud4733862019-07-09 14:21:06 +0100517 const int in_yi = std::floor((id.y() + _sampling_offset) * hr);
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100518 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
519 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
520 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100521
522 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
523 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
524 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
525 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
526 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
527 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
528 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
529 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
530 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
531 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
532 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
533 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
534 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
535 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
536 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
537 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
538
539 vst1q_u8(out.ptr(), tmp);
540 },
541 in, offsets, out);
542 break;
543 }
544 case DataType::S16:
545 {
546 int16x8x2_t tmp =
547 {
548 {
549 vdupq_n_s16(0),
550 vdupq_n_s16(0)
551 }
552 };
553
554 execute_window_loop(window, [&](const Coordinates & id)
555 {
556 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
557
Michalis Spyroud4733862019-07-09 14:21:06 +0100558 const int in_yi = std::floor((id.y() + _sampling_offset) * hr);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100559 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100560
561 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
562 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
563 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
564 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
565 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
566 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
567 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
568 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
569
570 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
571 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
572 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
573 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
574 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
575 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
576 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
577 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
578
579 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
580 },
581 in, offsets, out);
582 break;
583 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000584#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
585 case DataType::F16:
586 {
587 float16x8x2_t tmp =
588 {
589 {
590 vdupq_n_f16(0),
591 vdupq_n_f16(0)
592 }
593 };
594
595 execute_window_loop(window, [&](const Coordinates & id)
596 {
597 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
598
Michalis Spyroud4733862019-07-09 14:21:06 +0100599 const int in_yi = std::floor((id.y() + _sampling_offset) * hr);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000600 const int offset_row = in_yi * input_stride;
601
602 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
603 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
604 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
605 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
606 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
607 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
608 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
609 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
610
611 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
612 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
613 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
614 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
615 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
616 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
617 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
618 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
619
620 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
621 },
622 in, offsets, out);
623 break;
624 }
625#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100626 case DataType::F32:
627 {
628 float32x4x4_t tmp =
629 {
630 {
631 vdupq_n_f32(0),
632 vdupq_n_f32(0),
633 vdupq_n_f32(0),
634 vdupq_n_f32(0)
635 }
636 };
637
638 execute_window_loop(window, [&](const Coordinates & id)
639 {
640 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
641
Michalis Spyroud4733862019-07-09 14:21:06 +0100642 const int in_yi = std::floor((id.y() + _sampling_offset) * hr);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100643 const int offset_row = in_yi * input_stride;
644
645 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
646 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
647 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
648 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
649
650 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
651 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
652 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
653 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
654
655 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
656 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
657 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
658 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
659
660 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
661 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
662 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
663 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
664
665 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
666 },
667 in, offsets, out);
668 break;
669 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100670 default:
671 ARM_COMPUTE_ERROR("Not supported");
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100672 }
673}
674
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100675void NEScaleKernel::scale_bilinear_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100676{
Sheri Zhang359c48e2020-04-30 22:53:39 +0100677 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::S16, DataType::F16, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100678
679 // Compute the ratio between source height and destination height
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000680 const auto hr = arm_compute::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100681
682 // Don't increment in X and Y direction for the input tensor
683 // A pointer to the start of this plane is needed as base for the precomputed offsets
684 Window win_in(window);
685 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
686 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
687
688 Window win_off;
689 win_off.set(Window::DimX, window.x());
690 win_off.set(Window::DimY, window.y());
691
692 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
693 {
694 win_off.set(d, Window::Dimension(0, 0, 0));
695 }
696
697 Iterator in(_input, win_in);
698 Iterator out(_output, window);
699 Iterator offsets(_offsets, win_off);
700 Iterator dx(_dx, win_off);
701 Iterator dy(_dy, win_off);
702
703 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100704 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
705 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100706
Sheri Zhang359c48e2020-04-30 22:53:39 +0100707 const UniformQuantizationInfo iq_info = _input->info()->quantization_info().uniform();
708 const UniformQuantizationInfo oq_info = _output->info()->quantization_info().uniform();
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000709
Georgios Pinitas583137c2017-08-31 18:12:42 +0100710 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100711 {
Sheri Zhang359c48e2020-04-30 22:53:39 +0100712 case DataType::QASYMM8_SIGNED:
713 {
714 execute_window_loop(window, [&](const Coordinates & id)
715 {
716 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
717 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
718 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
Michele Di Giorgio6f7585b2020-05-04 16:44:28 +0100719 const auto in_ptr = reinterpret_cast<const int8_t *>(in.ptr());
Sheri Zhang359c48e2020-04-30 22:53:39 +0100720
721 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
722 const int offset_row = in_yi * in_stide_in_bytes;
723
724 int8x8_t tmp0 = vdup_n_s8(0);
725
726 tmp0 = vset_lane_s8(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);
727 tmp0 = vset_lane_s8(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);
728 tmp0 = vset_lane_s8(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);
729 tmp0 = vset_lane_s8(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);
730 tmp0 = vset_lane_s8(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);
731 tmp0 = vset_lane_s8(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);
732 tmp0 = vset_lane_s8(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);
733 tmp0 = vset_lane_s8(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);
734
735 int8x8_t tmp1 = vdup_n_s8(0);
736
737 tmp1 = vset_lane_s8(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);
738 tmp1 = vset_lane_s8(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);
739 tmp1 = vset_lane_s8(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);
740 tmp1 = vset_lane_s8(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);
741 tmp1 = vset_lane_s8(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);
742 tmp1 = vset_lane_s8(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);
743 tmp1 = vset_lane_s8(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);
744 tmp1 = vset_lane_s8(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);
745
746 vst1q_s8(reinterpret_cast<int8_t *>(out.ptr()), vcombine_s8(tmp0, tmp1));
747 },
748 in, offsets, dx, dy, out);
749 break;
750 }
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000751 case DataType::QASYMM8:
Sheri Zhang359c48e2020-04-30 22:53:39 +0100752 {
753 execute_window_loop(window, [&](const Coordinates & id)
754 {
755 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
756 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
757 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
758 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
759
760 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
761 const int offset_row = in_yi * in_stide_in_bytes;
762
763 uint8x8_t tmp0 = vdup_n_u8(0);
764
765 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);
766 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);
767 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);
768 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);
769 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);
770 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);
771 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);
772 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);
773
774 uint8x8_t tmp1 = vdup_n_u8(0);
775
776 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);
777 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);
778 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);
779 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);
780 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);
781 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);
782 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);
783 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);
784
785 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
786 },
787 in, offsets, dx, dy, out);
788 break;
789 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100790 case DataType::U8:
791 {
792 execute_window_loop(window, [&](const Coordinates & id)
793 {
794 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
795 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
796 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
797 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100798
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000799 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100800 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100801
Georgios Pinitas583137c2017-08-31 18:12:42 +0100802 uint8x8_t tmp0 = vdup_n_u8(0);
Sheri Zhang359c48e2020-04-30 22:53:39 +0100803
804 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
805 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
806 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
807 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
808 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
809 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
810 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
811 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7);
812
Georgios Pinitas583137c2017-08-31 18:12:42 +0100813 uint8x8_t tmp1 = vdup_n_u8(0);
Sheri Zhang359c48e2020-04-30 22:53:39 +0100814
815 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
816 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
817 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
818 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
819 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
820 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
821 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
822 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7);
823
Georgios Pinitas583137c2017-08-31 18:12:42 +0100824 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
825 },
826 in, offsets, dx, dy, out);
827 break;
828 }
829 case DataType::S16:
830 {
831 execute_window_loop(window, [&](const Coordinates & id)
832 {
833 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
834 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
835 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
836
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000837 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100838 const int offset_row = in_yi * in_stide_in_bytes;
839
840 int16x8x2_t tmp =
841 {
842 {
843 vdupq_n_s16(0),
844 vdupq_n_s16(0)
845 }
846 };
847
848 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);
849 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);
850 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);
851 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);
852 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);
853 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);
854 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);
855 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);
856
857 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);
858 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);
859 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);
860 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);
861 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);
862 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);
863 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);
864 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);
865
866 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
867 },
868 in, offsets, dx, dy, out);
869 break;
870 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000871#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
872 case DataType::F16:
873 {
874 execute_window_loop(window, [&](const Coordinates & id)
875 {
876 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
877 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
878 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
879
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000880 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000881 const int offset_row = in_yi * in_stide_in_bytes;
882
883 float16x8x2_t tmp =
884 {
885 {
886 vdupq_n_f16(0),
887 vdupq_n_f16(0)
888 }
889 };
890
891 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);
892 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);
893 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);
894 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);
895 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);
896 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);
897 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);
898 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);
899
900 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);
901 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);
902 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);
903 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);
904 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);
905 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);
906 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);
907 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);
908
909 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
910 },
911 in, offsets, dx, dy, out);
912 break;
913 }
914#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100915 case DataType::F32:
916 {
917 execute_window_loop(window, [&](const Coordinates & id)
918 {
919 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
920 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
921 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
922
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000923 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100924 const int offset_row = in_yi * in_stide_in_bytes;
925
926 float32x4x4_t tmp =
927 {
928 {
929 vdupq_n_f32(0),
930 vdupq_n_f32(0),
931 vdupq_n_f32(0),
932 vdupq_n_f32(0)
933 }
934 };
935
936 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);
937 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);
938 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);
939 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);
940
941 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);
942 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);
943 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);
944 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);
945
946 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);
947 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);
948 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);
949 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);
950
951 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);
952 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);
953 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);
954 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);
955
956 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
957 },
958 in, offsets, dx, dy, out);
959 break;
960 }
961 default:
962 ARM_COMPUTE_ERROR("Not supported");
963 break;
964 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100965}
966
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100967void NEScaleKernel::scale_area_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100968{
969 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
970
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100971 // Don't increment in width/height/channels for the input tensor
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100972 // A pointer to the start of this plane is needed as base for the precomputed offsets
973 Window win_in(window);
974 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
975 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100976 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100977
978 Iterator in(_input, win_in);
979 Iterator out(_output, window);
980
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000981 const auto wr = arm_compute::calculate_resize_ratio(_input->info()->dimension(0), _output->info()->dimension(0), _align_corners);
982 const auto hr = arm_compute::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100983 const auto w = _input->info()->dimension(0);
984 const auto h = _input->info()->dimension(1);
985 const size_t in_stride = _input->info()->strides_in_bytes()[1];
986
987 execute_window_loop(window, [&](const Coordinates & id)
988 {
989 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
990
991 uint8x8_t tmp0 = vdup_n_u8(0);
992 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
993 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
994 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
995 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
996 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
997 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
998 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
999 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
1000
1001 uint8x8_t tmp1 = vdup_n_u8(0);
1002 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
1003 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
1004 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
1005 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
1006 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
1007 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
1008 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
1009 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
1010
1011 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
1012 },
1013 in, out);
1014}
1015
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001016void NEScaleKernel::scale_nhwc(const Window &window)
1017{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001018 // Get data layout and width/height indices
Georgios Pinitasa5eb5912020-01-07 17:37:14 +00001019 const DataLayout data_layout = DataLayout::NHWC;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001020 const int idx_channels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1021 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1022 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1023
1024 const size_t input_stride_w = _input->info()->strides_in_bytes()[idx_width];
1025 const size_t input_stride_h = _input->info()->strides_in_bytes()[idx_height];
1026 const size_t input_stride_c = _input->info()->strides_in_bytes()[idx_channels];
1027
1028 // Compute the ratio between source height and destination height
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +00001029 const auto hr = arm_compute::calculate_resize_ratio(_input->info()->dimension(idx_height), _output->info()->dimension(idx_height), _align_corners);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001030
1031 // Don't increment in width/height/channels for the input tensor
1032 // A pointer to the start of this plane is needed as base for the precomputed offsets
1033 Window win_in(window);
1034 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
1035 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
1036 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
1037
1038 switch(_input->info()->data_type())
1039 {
Sheri Zhang359c48e2020-04-30 22:53:39 +01001040 case DataType::QASYMM8_SIGNED:
1041 {
1042 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1043 {
1044 scale_nearest_nhwc_core<int8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset);
1045 }
1046 else
1047 {
1048 scale_bilinear_nhwc_core<int8_t, int8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1049 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding);
1050 }
1051 break;
1052 }
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +00001053 case DataType::QASYMM8:
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001054 case DataType::U8:
1055 {
1056 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1057 {
Michalis Spyroud4733862019-07-09 14:21:06 +01001058 scale_nearest_nhwc_core<uint8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001059 }
1060 else
1061 {
George Wort05398a92019-01-25 15:38:33 +00001062 scale_bilinear_nhwc_core<uint8_t, uint8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1063 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 +01001064 }
1065 break;
1066 }
1067 case DataType::S16:
1068 {
1069 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1070 {
Michalis Spyroud4733862019-07-09 14:21:06 +01001071 scale_nearest_nhwc_core<int16_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001072 }
1073 else
1074 {
George Wort05398a92019-01-25 15:38:33 +00001075 scale_bilinear_nhwc_core<int16_t, int16_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1076 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 +01001077 }
1078 break;
1079 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +00001080#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1081 case DataType::F16:
1082 {
1083 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1084 {
1085 scale_nearest_nhwc_core<float16_t>(_input, _offsets, _output, hr,
Michalis Spyroud4733862019-07-09 14:21:06 +01001086 window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset);
Georgios Pinitasc47ef202018-11-16 18:19:43 +00001087 }
1088 else
1089 {
George Wort05398a92019-01-25 15:38:33 +00001090 scale_bilinear_nhwc_core<float16_t, half>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1091 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 +00001092 }
1093 break;
1094 }
1095#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001096 case DataType::F32:
1097 {
1098 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1099 {
Michalis Spyroud4733862019-07-09 14:21:06 +01001100 scale_nearest_nhwc_core<float>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001101 }
1102 else
1103 {
George Wort05398a92019-01-25 15:38:33 +00001104 scale_bilinear_nhwc_core<float, float>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1105 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 +01001106 }
1107 break;
1108 }
1109 default:
1110 ARM_COMPUTE_ERROR("Not supported");
1111 break;
1112 }
1113}
1114
Georgios Pinitas20b43132018-05-14 16:05:23 +01001115Status NEScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
1116 const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy,
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +00001117 BorderMode border_mode, PixelValue constant_border_value, SamplingPolicy sampling_policy, bool use_padding, bool align_corners)
Georgios Pinitas20b43132018-05-14 16:05:23 +01001118{
1119 BorderSize border_size(1);
1120 if(input->data_layout() == DataLayout::NHWC)
1121 {
1122 border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
1123 }
1124
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +00001125 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, policy, border_mode, constant_border_value, sampling_policy, use_padding, align_corners));
Georgios Pinitas20b43132018-05-14 16:05:23 +01001126 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
1127 dx != nullptr ? dx->clone().get() : nullptr,
1128 dy != nullptr ? dy->clone().get() : nullptr,
1129 offsets != nullptr ? offsets->clone().get() : nullptr,
1130 output->clone().get(),
George Wort05398a92019-01-25 15:38:33 +00001131 policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size, use_padding)
Georgios Pinitas20b43132018-05-14 16:05:23 +01001132 .first);
1133
1134 return Status{};
1135}
1136
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001137void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001138{
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001139 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001140 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
1141 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
1142 ARM_COMPUTE_ERROR_ON(_func == nullptr);
1143
1144 (this->*_func)(window);
1145}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001146} // namespace arm_compute