blob: 7ce1786d5773f0c1bd174d706a80cd880f846f74 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * 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"
Sang-Hoon Park94d50512020-07-02 10:49:39 +010031#include "arm_compute/core/utils/misc/Rounding.h"
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010032#include "arm_compute/core/utils/misc/Utility.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
Sang-Hoon Park3687ee12020-06-24 13:34:04 +010034#include "src/core/utils/ScaleUtils.h"
35
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036#include <arm_neon.h>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010038namespace arm_compute
39{
40namespace
41{
Georgios Pinitas20b43132018-05-14 16:05:23 +010042Status validate_arguments(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
Sang-Hoon Parkc2617982020-05-20 22:13:47 +010043 const ITensorInfo *offsets, ITensorInfo *output, const ScaleKernelInfo &info)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010044{
Georgios Pinitasc47ef202018-11-16 18:19:43 +000045 ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input);
Sheri Zhang359c48e2020-04-30 22:53:39 +010046 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 +010047 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
48 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
49 ARM_COMPUTE_RETURN_ERROR_ON(output == input);
Sang-Hoon Parkc2617982020-05-20 22:13:47 +010050 ARM_COMPUTE_RETURN_ERROR_ON(info.sampling_policy != SamplingPolicy::CENTER && info.sampling_policy != SamplingPolicy::TOP_LEFT);
51 ARM_COMPUTE_RETURN_ERROR_ON(!info.use_padding && info.border_mode != BorderMode::CONSTANT);
52 ARM_COMPUTE_UNUSED(info.constant_border_value);
Georgios Pinitas20b43132018-05-14 16:05:23 +010053
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +000054 const DataLayout data_layout = input->data_layout();
55 const auto width_index = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
56 const auto height_index = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
57 const auto output_width = output->dimension(width_index);
58 const auto output_height = output->dimension(height_index);
59 ARM_COMPUTE_RETURN_ERROR_ON(output_width == 0);
60 ARM_COMPUTE_RETURN_ERROR_ON(output_height == 0);
Georgios Pinitas20b43132018-05-14 16:05:23 +010061
Sang-Hoon Parkc2617982020-05-20 22:13:47 +010062 if(info.interpolation_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
Georgios Pinitas20b43132018-05-14 16:05:23 +010063 {
64 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
65 }
66
Sang-Hoon Parkc2617982020-05-20 22:13:47 +010067 if(info.interpolation_policy == InterpolationPolicy::BILINEAR)
Georgios Pinitas20b43132018-05-14 16:05:23 +010068 {
69 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
70 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32);
71 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32);
Sang-Hoon Parkf025a772020-05-26 11:11:32 +010072 }
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +000073
Sang-Hoon Park3687ee12020-06-24 13:34:04 +010074 ARM_COMPUTE_RETURN_ERROR_ON(info.align_corners && !arm_compute::scale_utils::is_align_corners_allowed_sampling_policy(info.sampling_policy));
Georgios Pinitas20b43132018-05-14 16:05:23 +010075
Sang-Hoon Parkc2617982020-05-20 22:13:47 +010076 if(info.interpolation_policy == InterpolationPolicy::AREA)
Georgios Pinitas20b43132018-05-14 16:05:23 +010077 {
78 ARM_COMPUTE_RETURN_ERROR_ON(data_layout != DataLayout::NCHW);
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +000079 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
Georgios Pinitas20b43132018-05-14 16:05:23 +010080 }
81
82 return Status{};
83}
84
85std::pair<Status, Window> validate_and_configure_window_nchw(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output,
Sang-Hoon Parkc2617982020-05-20 22:13:47 +010086 const ScaleKernelInfo &info, BorderSize border_size)
Georgios Pinitas20b43132018-05-14 16:05:23 +010087{
88 bool window_changed{ false };
89 Window win{};
90
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010091 constexpr unsigned int num_elems_processed_per_iteration = 16;
92
93 // Configure kernel window
Georgios Pinitas20b43132018-05-14 16:05:23 +010094 win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010095
Georgios Pinitas20b43132018-05-14 16:05:23 +010096 const ValidRegion &input_valid_region = input->valid_region();
97
98 if(offsets != nullptr)
99 {
100 AccessWindowHorizontal offsets_access(offsets, 0, num_elems_processed_per_iteration);
101 window_changed = window_changed || update_window_and_padding(win, offsets_access);
102 }
103 if(dx != nullptr && dy != nullptr)
104 {
105 AccessWindowHorizontal dx_access(dx, 0, num_elems_processed_per_iteration);
106 AccessWindowHorizontal dy_access(dy, 0, num_elems_processed_per_iteration);
107 window_changed = window_changed || update_window_and_padding(win, dx_access, dy_access);
108 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100109
110 // Reads can occur within the valid region of the input
Georgios Pinitas20b43132018-05-14 16:05:23 +0100111 AccessWindowStatic input_access(input, input_valid_region.anchor[0] - border_size.left,
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100112 input_valid_region.anchor[1] - border_size.top,
113 input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size.right,
114 input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size.bottom);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100115 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
116 window_changed = window_changed || update_window_and_padding(win, input_access, output_access);
117 output_access.set_valid_region(win, calculate_valid_region_scale(*input, output->tensor_shape(),
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100118 info.interpolation_policy, info.sampling_policy, info.border_mode == BorderMode::UNDEFINED));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100119
Georgios Pinitas20b43132018-05-14 16:05:23 +0100120 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
121 return std::make_pair(err, win);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100122}
Georgios Pinitas20b43132018-05-14 16:05:23 +0100123
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100124std::pair<Status, Window> validate_and_configure_window_nhwc(ITensorInfo *input, ITensorInfo *output, const ScaleKernelInfo &info, BorderSize border_size)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100125{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100126 bool window_changed{ false };
127 Window win{};
128
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100129 const unsigned int num_elems_processed_per_iteration = (info.use_padding && info.interpolation_policy == InterpolationPolicy::NEAREST_NEIGHBOR) ? 16 / input->element_size() : 1;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100130
131 // Configure kernel window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100132 win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100133
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100134 if(info.use_padding)
George Wort05398a92019-01-25 15:38:33 +0000135 {
Georgios Pinitas32620422019-06-27 17:14:32 +0100136 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 +0000137 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
138 window_changed = update_window_and_padding(win, input_access, output_access);
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100139 output->set_valid_region(calculate_valid_region_scale(*input, output->tensor_shape(), info.interpolation_policy, info.sampling_policy, info.border_mode == BorderMode::UNDEFINED));
George Wort05398a92019-01-25 15:38:33 +0000140 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100141
Georgios Pinitas20b43132018-05-14 16:05:23 +0100142 Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
143 return std::make_pair(err, win);
144}
145
146std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *dx, ITensorInfo *dy, ITensorInfo *offsets, ITensorInfo *output,
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100147 const ScaleKernelInfo &info, BorderSize border_size)
Georgios Pinitas20b43132018-05-14 16:05:23 +0100148{
149 std::pair<Status, Window> win_config;
150 switch(input->data_layout())
151 {
152 case DataLayout::NCHW:
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100153 if(!info.use_padding)
George Wort05398a92019-01-25 15:38:33 +0000154 {
155 return std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Padding required for NCHW"), Window{});
156 }
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100157 win_config = validate_and_configure_window_nchw(input, dx, dy, offsets, output, info, border_size);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100158 break;
159 case DataLayout::NHWC:
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100160 win_config = validate_and_configure_window_nhwc(input, output, info, border_size);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100161 break;
162 default:
163 win_config = std::make_pair(ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Unsupported data layout!"), Window{});
164 }
165
166 return win_config;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100167}
168
169template <typename T>
170inline void scale_nearest_nhwc_core(const ITensor *input, const ITensor *offsets, ITensor *output,
Sang-Hoon Park94d50512020-07-02 10:49:39 +0100171 float hr, Window window, const Window &win_in, size_t stride_w, size_t stride_h, size_t stride_c, float sampling_offset, bool align_corners)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100172{
George Wort05398a92019-01-25 15:38:33 +0000173 const int window_step_x = 16 / sizeof(T);
174 const auto window_start_x = static_cast<int32_t>(window.x().start());
175 const auto window_end_x = static_cast<int32_t>(window.x().end());
176
177 window.set(Window::DimX, Window::Dimension(0, 1, 1));
178
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100179 Iterator in(input, win_in);
180 Iterator out(output, window);
181
182 const size_t offsets_stride = stride_w / sizeof(T);
183
184 execute_window_loop(window, [&](const Coordinates & id)
185 {
George Wort05398a92019-01-25 15:38:33 +0000186 const int32_t offset = *reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z())));
Sang-Hoon Park94d50512020-07-02 10:49:39 +0100187 const auto in_yi = static_cast<int>(align_corners ? arm_compute::utils::rounding::round_half_away_from_zero((id.z() + sampling_offset) * hr) : std::floor((id.z() + sampling_offset) * hr));
George Wort05398a92019-01-25 15:38:33 +0000188 const int offset_row = in_yi * stride_h;
189 int32_t x = window_start_x;
190 for(; x < window_end_x - window_step_x; x += window_step_x)
191 {
192 wrapper::vstore(reinterpret_cast<T *>(out.ptr()) + x,
193 wrapper::vloadq(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row + x * stride_c)));
194 }
195 for(; x < window_end_x; ++x)
196 {
197 *(reinterpret_cast<T *>(out.ptr()) + x) =
198 *(reinterpret_cast<const T *>(in.ptr() + offset * offsets_stride + offset_row + x * stride_c));
199 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100200 },
201 in, out);
202}
203
George Wort05398a92019-01-25 15:38:33 +0000204template <typename T, typename ConstType>
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100205inline 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 +0000206 float hr, float sampling_offset, Window window, const Window &win_in, size_t stride_w, size_t stride_h,
207 size_t stride_c, BorderMode border_mode, PixelValue constant_border_value, bool use_padding)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100208{
209 Iterator in(input, win_in);
210 Iterator out(output, window);
211
212 const size_t stride_w_elems = stride_w / sizeof(T);
213 const size_t stride_h_elems = stride_h / sizeof(T);
214
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100215 const int input_width = input->info()->dimension(1);
216 const int input_height = input->info()->dimension(2);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100217
George Wort05398a92019-01-25 15:38:33 +0000218 T border_value;
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100219 if(use_padding && border_mode != BorderMode::REPLICATE)
George Wort05398a92019-01-25 15:38:33 +0000220 {
Pablo Tello10971472019-05-15 15:14:46 +0100221 // 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 +0000222 border_value = *reinterpret_cast<T *>(input->buffer() + input->info()->offset_first_element_in_bytes() - stride_w);
223 }
224 else
225 {
226 border_value = static_cast<T>(constant_border_value.get<ConstType>());
227 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100228
Michalis Spyroufae513c2019-10-16 17:41:33 +0100229 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 +0100230 {
231 return !(x < low_x || x > high_x || y < low_y || y > high_y);
232 };
233
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100234 int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1;
235
Sheri Zhang359c48e2020-04-30 22:53:39 +0100236 const UniformQuantizationInfo iq_info = input->info()->quantization_info().uniform();
237 const UniformQuantizationInfo oq_info = output->info()->quantization_info().uniform();
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000238
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100239 execute_window_loop(window, [&](const Coordinates & id)
240 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100241 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 +0100242 const auto dx_scale = *reinterpret_cast<const float *>(dx->ptr_to_element(Coordinates(id.y(), id.z())));
243 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 +0000244 const int in_yi = std::floor((id.z() + sampling_offset) * hr - sampling_offset);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100245 const int offset_row = in_yi * stride_h + id.x() * stride_c;
246 const T *in_ptr = reinterpret_cast<T *>(in.ptr() + offset * stride_w + offset_row);
247
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100248 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 +0100249 {
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100250 T a00 = 0;
251 T a01 = 0;
252 T a10 = 0;
253 T a11 = 0;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100254
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100255 if(border_mode == BorderMode::CONSTANT)
256 {
George Wort05398a92019-01-25 15:38:33 +0000257 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : border_value;
258 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : border_value;
259 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : border_value;
260 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 +0100261 }
262 else if(border_mode == BorderMode::REPLICATE)
263 {
264 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
265 auto clamped_x1 = utility::clamp<int>(offset + 1, 0, input_width - 1);
266 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
267 auto clamped_y1 = utility::clamp<int>(in_yi + 1, 0, input_height - 1);
268
269 a00 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
270 a01 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y * stride_h + id.x() * stride_c);
271 a10 = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
272 a11 = *reinterpret_cast<T *>(in.ptr() + clamped_x1 * stride_w + clamped_y1 * stride_h + id.x() * stride_c);
273 }
274 else
275 {
276 a00 = is_valid(offset, 0, input_width - 1, in_yi, 0, input_height - 1) ? *in_ptr : 0;
277 a01 = is_valid(offset + 1, 0, input_width - 1, in_yi, 0, input_height - 1) ? *(in_ptr + stride_w_elems) : 0;
278 a10 = is_valid(offset, 0, input_width - 1, in_yi + 1, 0, input_height - 1) ? *(in_ptr + stride_h_elems) : 0;
279 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;
280 }
281
282 // Perform interpolation
283 const float dx1 = 1.0f - dx_scale;
284 const float dy1 = 1.0f - dy_scale;
285
286 const float w1 = dx1 * dy1;
287 const float w2 = dx_scale * dy1;
288 const float w3 = dx1 * dy_scale;
289 const float w4 = dx_scale * dy_scale;
290
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000291 T res = 0;
292 //dequantize quantized input
Sheri Zhang359c48e2020-04-30 22:53:39 +0100293 if(input->info()->data_type() == DataType::QASYMM8)
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000294 {
Georgios Pinitas4c5469b2019-05-21 13:32:43 +0100295 float inp00 = dequantize_qasymm8(a00, iq_info);
296 float inp01 = dequantize_qasymm8(a01, iq_info);
297 float inp10 = dequantize_qasymm8(a10, iq_info);
298 float inp11 = dequantize_qasymm8(a11, iq_info);
299 res = static_cast<T>(quantize_qasymm8((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), oq_info));
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000300 }
Sheri Zhang359c48e2020-04-30 22:53:39 +0100301 else if(input->info()->data_type() == DataType::QASYMM8_SIGNED)
302 {
303 float inp00 = dequantize_qasymm8_signed(a00, iq_info);
304 float inp01 = dequantize_qasymm8_signed(a01, iq_info);
305 float inp10 = dequantize_qasymm8_signed(a10, iq_info);
306 float inp11 = dequantize_qasymm8_signed(a11, iq_info);
307 res = static_cast<T>(quantize_qasymm8_signed((inp00 * w1 + inp01 * w2 + inp10 * w3 + inp11 * w4), oq_info));
308 }
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000309 else
310 {
311 res = static_cast<T>(a00 * w1 + a01 * w2 + a10 * w3 + a11 * w4);
312 }
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100313 // Store result
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000314 *reinterpret_cast<T *>(out.ptr()) = res;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100315 }
316 else
317 {
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100318 if(border_mode == BorderMode::CONSTANT)
319 {
George Wort05398a92019-01-25 15:38:33 +0000320 *reinterpret_cast<T *>(out.ptr()) = border_value;
Georgios Pinitasfa7ad562018-05-15 17:38:40 +0100321 }
322 else if(border_mode == BorderMode::REPLICATE)
323 {
324 auto clamped_x = utility::clamp<int>(offset, 0, input_width - 1);
325 auto clamped_y = utility::clamp<int>(in_yi, 0, input_height - 1);
326 *reinterpret_cast<T *>(out.ptr()) = *reinterpret_cast<T *>(in.ptr() + clamped_x * stride_w + clamped_y * stride_h + id.x() * stride_c);
327 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100328 }
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100329 },
330 in, out);
331}
332} // namespace
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100333
334NEScaleKernel::NEScaleKernel()
Manuel Bottinif00d3322019-03-05 15:53:25 +0000335 : _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 +0000336 _sampling_offset(0), _use_padding(true), _align_corners(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100337{
338}
339
340BorderSize NEScaleKernel::border_size() const
341{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100342 return _border_size;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343}
344
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100345void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets,
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100346 ITensor *output, const ScaleKernelInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100347{
Georgios Pinitas20b43132018-05-14 16:05:23 +0100348 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
Georgios Pinitas20b43132018-05-14 16:05:23 +0100349 // Perform validation step
350 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
351 dx != nullptr ? dx->info() : nullptr,
352 dy != nullptr ? dy->info() : nullptr,
353 offsets != nullptr ? offsets->info() : nullptr,
354 output->info(),
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100355 info));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100356
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100357 // Get data layout and width/height indices
358 const DataLayout data_layout = input->info()->data_layout();
359 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
360 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100361
George Wort05398a92019-01-25 15:38:33 +0000362 _input = input;
363 _output = output;
364 _offsets = offsets;
365 _dx = dx;
366 _dy = dy;
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100367 _policy = info.interpolation_policy;
George Wort05398a92019-01-25 15:38:33 +0000368 _border_size = BorderSize(1);
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100369 _border_mode = info.border_mode;
370 _constant_border_value = info.constant_border_value;
371 _use_padding = info.use_padding;
Sang-Hoon Park3687ee12020-06-24 13:34:04 +0100372 _align_corners = info.align_corners && arm_compute::scale_utils::is_align_corners_allowed_output_shape(output->info()->tensor_shape(), data_layout);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100373
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100374 if(info.sampling_policy == SamplingPolicy::CENTER)
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000375 {
376 _sampling_offset = 0.5f;
377 }
378
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100379 // Compute the ratio between source width/height and destination width/height
Sang-Hoon Park3687ee12020-06-24 13:34:04 +0100380 const auto wr = arm_compute::scale_utils::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), _align_corners);
381 const auto hr = arm_compute::scale_utils::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), _align_corners);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100382
383 // Add constant border only on top in case of NHWC layout
384 if(data_layout == DataLayout::NHWC)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100385 {
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100386 _border_size = (info.border_mode != BorderMode::REPLICATE && info.interpolation_policy == InterpolationPolicy::BILINEAR && info.use_padding) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100387 }
388
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100389 // Area interpolation behaves as Nearest Neighbour in case of up-sampling
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100390 const auto policy_to_use = (info.interpolation_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) ? InterpolationPolicy::NEAREST_NEIGHBOR : _policy;
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100391
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100392 // Select interpolation function
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100393 switch(policy_to_use)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100394 {
395 case InterpolationPolicy::NEAREST_NEIGHBOR:
396 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100397 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100398 break;
399 }
400 case InterpolationPolicy::BILINEAR:
401 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100402 _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100403 break;
404 }
405 case InterpolationPolicy::AREA:
406 {
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100407 _func = &NEScaleKernel::scale_area_nchw;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100408 break;
409 }
410 default:
411 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
412 }
413
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100414 // Configure window
Georgios Pinitas20b43132018-05-14 16:05:23 +0100415 std::pair<Status, Window> win_config = validate_and_configure_window(input->info(),
416 dx != nullptr ? dx->info() : nullptr,
417 dy != nullptr ? dy->info() : nullptr,
418 offsets != nullptr ? offsets->info() : nullptr,
419 output->info(),
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100420 info, border_size());
George Wort05398a92019-01-25 15:38:33 +0000421
Georgios Pinitas20b43132018-05-14 16:05:23 +0100422 ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
423 INEKernel::configure(win_config.second);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100424}
425
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100426void NEScaleKernel::scale_nearest_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100427{
428 const size_t input_stride = _input->info()->strides_in_bytes()[1];
429
430 // Compute the ratio between source height and destination height
Sang-Hoon Park3687ee12020-06-24 13:34:04 +0100431 const auto hr = arm_compute::scale_utils::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100432
433 // Don't increment in X and Y direction for the input tensor
434 // A pointer to the start of this plane is needed as base for the precomputed offsets
435 Window win_in(window);
436 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
437 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
438
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100439 // Set offsets window
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100440 Window win_off;
441 win_off.set(Window::DimX, window[Window::DimX]);
442 win_off.set(Window::DimY, window[Window::DimY]);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100443 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
444 {
445 win_off.set(d, Window::Dimension(0, 0, 0));
446 }
447
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100448 // Create iterators
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100449 Iterator in(_input, win_in);
450 Iterator out(_output, window);
451 Iterator offsets(_offsets, win_off);
452
453 switch(_input->info()->data_type())
454 {
Sheri Zhang359c48e2020-04-30 22:53:39 +0100455 case DataType::QASYMM8_SIGNED:
456 {
457 int8x16_t tmp = vdupq_n_s8(0);
458
459 execute_window_loop(window, [&](const Coordinates & id)
460 {
461 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
462 const uint8_t *const in_ptr = in.ptr();
463
Sang-Hoon Park94d50512020-07-02 10:49:39 +0100464 const auto in_yi = static_cast<int>(_align_corners ? arm_compute::utils::rounding::round_half_away_from_zero((id.y() + _sampling_offset) * hr) : std::floor((id.y() + _sampling_offset) * hr));
465 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
Sheri Zhang359c48e2020-04-30 22:53:39 +0100466 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
467 const int offset_row = in_yi_clamped * input_stride;
468
469 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
470 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
471 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
472 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
473 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
474 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
475 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
476 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
477 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
478 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
479 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
480 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
481 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
482 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
483 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
484 tmp = vsetq_lane_s8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
485
486 vst1q_s8(reinterpret_cast<int8_t *>(out.ptr()), tmp);
487 },
488 in, offsets, out);
489 break;
490 }
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000491 case DataType::QASYMM8:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100492 case DataType::U8:
493 {
494 uint8x16_t tmp = vdupq_n_u8(0);
495
496 execute_window_loop(window, [&](const Coordinates & id)
497 {
498 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
499 const uint8_t *const in_ptr = in.ptr();
500
Sang-Hoon Park94d50512020-07-02 10:49:39 +0100501 const auto in_yi = static_cast<int>(_align_corners ? arm_compute::utils::rounding::round_half_away_from_zero((id.y() + _sampling_offset) * hr) : std::floor((id.y() + _sampling_offset) * hr));
502 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100503 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
504 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100505
506 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
507 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
508 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
509 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
510 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
511 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
512 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
513 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
514 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
515 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
516 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
517 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
518 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
519 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
520 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
521 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
522
523 vst1q_u8(out.ptr(), tmp);
524 },
525 in, offsets, out);
526 break;
527 }
528 case DataType::S16:
529 {
530 int16x8x2_t tmp =
531 {
532 {
533 vdupq_n_s16(0),
534 vdupq_n_s16(0)
535 }
536 };
537
538 execute_window_loop(window, [&](const Coordinates & id)
539 {
540 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
Sang-Hoon Park94d50512020-07-02 10:49:39 +0100541 const auto in_yi = static_cast<int>(_align_corners ? arm_compute::utils::rounding::round_half_away_from_zero((id.y() + _sampling_offset) * hr) : std::floor((id.y() + _sampling_offset) * hr));
542 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100543
544 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
545 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
546 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
547 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
548 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
549 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
550 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
551 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
552
553 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
554 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
555 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
556 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
557 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
558 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
559 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
560 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
561
562 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
563 },
564 in, offsets, out);
565 break;
566 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000567#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
568 case DataType::F16:
569 {
570 float16x8x2_t tmp =
571 {
572 {
573 vdupq_n_f16(0),
574 vdupq_n_f16(0)
575 }
576 };
577
578 execute_window_loop(window, [&](const Coordinates & id)
579 {
580 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
Sang-Hoon Park94d50512020-07-02 10:49:39 +0100581 const auto in_yi = static_cast<int>(_align_corners ? arm_compute::utils::rounding::round_half_away_from_zero((id.y() + _sampling_offset) * hr) : std::floor((id.y() + _sampling_offset) * hr));
582 const int offset_row = in_yi * input_stride;
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000583
584 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
585 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
586 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
587 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
588 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
589 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
590 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
591 tmp.val[0] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
592
593 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
594 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
595 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
596 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
597 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
598 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
599 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
600 tmp.val[1] = vsetq_lane_f16(*reinterpret_cast<const __fp16 *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
601
602 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
603 },
604 in, offsets, out);
605 break;
606 }
607#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100608 case DataType::F32:
609 {
610 float32x4x4_t tmp =
611 {
612 {
613 vdupq_n_f32(0),
614 vdupq_n_f32(0),
615 vdupq_n_f32(0),
616 vdupq_n_f32(0)
617 }
618 };
619
620 execute_window_loop(window, [&](const Coordinates & id)
621 {
622 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
Sang-Hoon Park94d50512020-07-02 10:49:39 +0100623 const auto in_yi = static_cast<int>(_align_corners ? arm_compute::utils::rounding::round_half_away_from_zero((id.y() + _sampling_offset) * hr) : std::floor((id.y() + _sampling_offset) * hr));
624 const int offset_row = in_yi * input_stride;
Georgios Pinitas583137c2017-08-31 18:12:42 +0100625
626 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
627 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
628 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
629 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
630
631 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
632 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
633 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
634 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
635
636 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
637 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
638 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
639 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
640
641 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
642 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
643 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
644 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
645
646 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
647 },
648 in, offsets, out);
649 break;
650 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100651 default:
652 ARM_COMPUTE_ERROR("Not supported");
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100653 }
654}
655
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100656void NEScaleKernel::scale_bilinear_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100657{
Sheri Zhang359c48e2020-04-30 22:53:39 +0100658 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 +0100659
660 // Compute the ratio between source height and destination height
Sang-Hoon Park3687ee12020-06-24 13:34:04 +0100661 const auto hr = arm_compute::scale_utils::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100662
663 // Don't increment in X and Y direction for the input tensor
664 // A pointer to the start of this plane is needed as base for the precomputed offsets
665 Window win_in(window);
666 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
667 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
668
669 Window win_off;
670 win_off.set(Window::DimX, window.x());
671 win_off.set(Window::DimY, window.y());
672
673 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
674 {
675 win_off.set(d, Window::Dimension(0, 0, 0));
676 }
677
678 Iterator in(_input, win_in);
679 Iterator out(_output, window);
680 Iterator offsets(_offsets, win_off);
681 Iterator dx(_dx, win_off);
682 Iterator dy(_dy, win_off);
683
684 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100685 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
686 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100687
Sheri Zhang359c48e2020-04-30 22:53:39 +0100688 const UniformQuantizationInfo iq_info = _input->info()->quantization_info().uniform();
689 const UniformQuantizationInfo oq_info = _output->info()->quantization_info().uniform();
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000690
Georgios Pinitas583137c2017-08-31 18:12:42 +0100691 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100692 {
Sheri Zhang359c48e2020-04-30 22:53:39 +0100693 case DataType::QASYMM8_SIGNED:
694 {
695 execute_window_loop(window, [&](const Coordinates & id)
696 {
697 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
698 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
699 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
Michele Di Giorgio6f7585b2020-05-04 16:44:28 +0100700 const auto in_ptr = reinterpret_cast<const int8_t *>(in.ptr());
Sheri Zhang359c48e2020-04-30 22:53:39 +0100701
702 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
703 const int offset_row = in_yi * in_stide_in_bytes;
704
705 int8x8_t tmp0 = vdup_n_s8(0);
706
707 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);
708 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);
709 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);
710 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);
711 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);
712 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);
713 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);
714 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);
715
716 int8x8_t tmp1 = vdup_n_s8(0);
717
718 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);
719 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);
720 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);
721 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);
722 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);
723 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);
724 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);
725 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);
726
727 vst1q_s8(reinterpret_cast<int8_t *>(out.ptr()), vcombine_s8(tmp0, tmp1));
728 },
729 in, offsets, dx, dy, out);
730 break;
731 }
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000732 case DataType::QASYMM8:
Sheri Zhang359c48e2020-04-30 22:53:39 +0100733 {
734 execute_window_loop(window, [&](const Coordinates & id)
735 {
736 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
737 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
738 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
739 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
740
741 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
742 const int offset_row = in_yi * in_stide_in_bytes;
743
744 uint8x8_t tmp0 = vdup_n_u8(0);
745
746 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);
747 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);
748 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);
749 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);
750 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);
751 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);
752 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);
753 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);
754
755 uint8x8_t tmp1 = vdup_n_u8(0);
756
757 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);
758 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);
759 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);
760 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);
761 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);
762 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);
763 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);
764 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);
765
766 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
767 },
768 in, offsets, dx, dy, out);
769 break;
770 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100771 case DataType::U8:
772 {
773 execute_window_loop(window, [&](const Coordinates & id)
774 {
775 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
776 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
777 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
778 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100779
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000780 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100781 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100782
Georgios Pinitas583137c2017-08-31 18:12:42 +0100783 uint8x8_t tmp0 = vdup_n_u8(0);
Sheri Zhang359c48e2020-04-30 22:53:39 +0100784
785 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
786 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
787 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
788 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
789 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
790 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
791 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
792 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7);
793
Georgios Pinitas583137c2017-08-31 18:12:42 +0100794 uint8x8_t tmp1 = vdup_n_u8(0);
Sheri Zhang359c48e2020-04-30 22:53:39 +0100795
796 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
797 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
798 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
799 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
800 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
801 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
802 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
803 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7);
804
Georgios Pinitas583137c2017-08-31 18:12:42 +0100805 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
806 },
807 in, offsets, dx, dy, out);
808 break;
809 }
810 case DataType::S16:
811 {
812 execute_window_loop(window, [&](const Coordinates & id)
813 {
814 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
815 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
816 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
817
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000818 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100819 const int offset_row = in_yi * in_stide_in_bytes;
820
821 int16x8x2_t tmp =
822 {
823 {
824 vdupq_n_s16(0),
825 vdupq_n_s16(0)
826 }
827 };
828
829 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);
830 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);
831 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);
832 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);
833 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);
834 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);
835 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);
836 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);
837
838 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);
839 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);
840 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);
841 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);
842 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);
843 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);
844 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);
845 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);
846
847 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
848 },
849 in, offsets, dx, dy, out);
850 break;
851 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000852#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
853 case DataType::F16:
854 {
855 execute_window_loop(window, [&](const Coordinates & id)
856 {
857 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
858 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
859 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
860
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000861 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000862 const int offset_row = in_yi * in_stide_in_bytes;
863
864 float16x8x2_t tmp =
865 {
866 {
867 vdupq_n_f16(0),
868 vdupq_n_f16(0)
869 }
870 };
871
872 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);
873 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);
874 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);
875 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);
876 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);
877 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);
878 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);
879 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);
880
881 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);
882 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);
883 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);
884 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);
885 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);
886 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);
887 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);
888 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);
889
890 vst2q_f16(reinterpret_cast<__fp16 *>(out.ptr()), tmp);
891 },
892 in, offsets, dx, dy, out);
893 break;
894 }
895#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100896 case DataType::F32:
897 {
898 execute_window_loop(window, [&](const Coordinates & id)
899 {
900 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
901 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
902 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
903
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000904 const int in_yi = std::floor((id.y() + _sampling_offset) * hr - _sampling_offset);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100905 const int offset_row = in_yi * in_stide_in_bytes;
906
907 float32x4x4_t tmp =
908 {
909 {
910 vdupq_n_f32(0),
911 vdupq_n_f32(0),
912 vdupq_n_f32(0),
913 vdupq_n_f32(0)
914 }
915 };
916
917 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);
918 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);
919 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);
920 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);
921
922 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);
923 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);
924 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);
925 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);
926
927 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);
928 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);
929 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);
930 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);
931
932 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);
933 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);
934 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);
935 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);
936
937 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
938 },
939 in, offsets, dx, dy, out);
940 break;
941 }
942 default:
943 ARM_COMPUTE_ERROR("Not supported");
944 break;
945 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100946}
947
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100948void NEScaleKernel::scale_area_nchw(const Window &window)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100949{
950 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
951
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100952 // Don't increment in width/height/channels for the input tensor
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100953 // A pointer to the start of this plane is needed as base for the precomputed offsets
954 Window win_in(window);
955 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
956 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100957 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100958
959 Iterator in(_input, win_in);
960 Iterator out(_output, window);
961
Sang-Hoon Park3687ee12020-06-24 13:34:04 +0100962 const auto wr = arm_compute::scale_utils::calculate_resize_ratio(_input->info()->dimension(0), _output->info()->dimension(0), _align_corners);
963 const auto hr = arm_compute::scale_utils::calculate_resize_ratio(_input->info()->dimension(1), _output->info()->dimension(1), _align_corners);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100964 const auto w = _input->info()->dimension(0);
965 const auto h = _input->info()->dimension(1);
966 const size_t in_stride = _input->info()->strides_in_bytes()[1];
967
968 execute_window_loop(window, [&](const Coordinates & id)
969 {
970 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
971
972 uint8x8_t tmp0 = vdup_n_u8(0);
973 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
974 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
975 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
976 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
977 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
978 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
979 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
980 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
981
982 uint8x8_t tmp1 = vdup_n_u8(0);
983 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
984 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
985 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
986 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
987 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
988 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
989 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
990 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
991
992 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
993 },
994 in, out);
995}
996
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100997void NEScaleKernel::scale_nhwc(const Window &window)
998{
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100999 // Get data layout and width/height indices
Georgios Pinitasa5eb5912020-01-07 17:37:14 +00001000 const DataLayout data_layout = DataLayout::NHWC;
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001001 const int idx_channels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1002 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1003 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1004
1005 const size_t input_stride_w = _input->info()->strides_in_bytes()[idx_width];
1006 const size_t input_stride_h = _input->info()->strides_in_bytes()[idx_height];
1007 const size_t input_stride_c = _input->info()->strides_in_bytes()[idx_channels];
1008
1009 // Compute the ratio between source height and destination height
Sang-Hoon Park3687ee12020-06-24 13:34:04 +01001010 const auto hr = arm_compute::scale_utils::calculate_resize_ratio(_input->info()->dimension(idx_height), _output->info()->dimension(idx_height), _align_corners);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001011
1012 // Don't increment in width/height/channels for the input tensor
1013 // A pointer to the start of this plane is needed as base for the precomputed offsets
1014 Window win_in(window);
1015 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
1016 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
1017 win_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
1018
1019 switch(_input->info()->data_type())
1020 {
Sheri Zhang359c48e2020-04-30 22:53:39 +01001021 case DataType::QASYMM8_SIGNED:
1022 {
1023 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1024 {
Sang-Hoon Park94d50512020-07-02 10:49:39 +01001025 scale_nearest_nhwc_core<int8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset, _align_corners);
Sheri Zhang359c48e2020-04-30 22:53:39 +01001026 }
1027 else
1028 {
1029 scale_bilinear_nhwc_core<int8_t, int8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1030 window, win_in, input_stride_w, input_stride_h, input_stride_c, _border_mode, _constant_border_value, _use_padding);
1031 }
1032 break;
1033 }
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +00001034 case DataType::QASYMM8:
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001035 case DataType::U8:
1036 {
1037 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1038 {
Sang-Hoon Park94d50512020-07-02 10:49:39 +01001039 scale_nearest_nhwc_core<uint8_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset, _align_corners);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001040 }
1041 else
1042 {
George Wort05398a92019-01-25 15:38:33 +00001043 scale_bilinear_nhwc_core<uint8_t, uint8_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1044 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 +01001045 }
1046 break;
1047 }
1048 case DataType::S16:
1049 {
1050 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1051 {
Sang-Hoon Park94d50512020-07-02 10:49:39 +01001052 scale_nearest_nhwc_core<int16_t>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset, _align_corners);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001053 }
1054 else
1055 {
George Wort05398a92019-01-25 15:38:33 +00001056 scale_bilinear_nhwc_core<int16_t, int16_t>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1057 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 +01001058 }
1059 break;
1060 }
Georgios Pinitasc47ef202018-11-16 18:19:43 +00001061#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1062 case DataType::F16:
1063 {
1064 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1065 {
1066 scale_nearest_nhwc_core<float16_t>(_input, _offsets, _output, hr,
Sang-Hoon Park94d50512020-07-02 10:49:39 +01001067 window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset, _align_corners);
Georgios Pinitasc47ef202018-11-16 18:19:43 +00001068 }
1069 else
1070 {
George Wort05398a92019-01-25 15:38:33 +00001071 scale_bilinear_nhwc_core<float16_t, half>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1072 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 +00001073 }
1074 break;
1075 }
1076#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001077 case DataType::F32:
1078 {
1079 if(_policy == InterpolationPolicy::NEAREST_NEIGHBOR)
1080 {
Sang-Hoon Park94d50512020-07-02 10:49:39 +01001081 scale_nearest_nhwc_core<float>(_input, _offsets, _output, hr, window, win_in, input_stride_w, input_stride_h, input_stride_c, _sampling_offset, _align_corners);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001082 }
1083 else
1084 {
George Wort05398a92019-01-25 15:38:33 +00001085 scale_bilinear_nhwc_core<float, float>(_input, _offsets, _dx, _dy, _output, hr, _sampling_offset,
1086 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 +01001087 }
1088 break;
1089 }
1090 default:
1091 ARM_COMPUTE_ERROR("Not supported");
1092 break;
1093 }
1094}
1095
Georgios Pinitas20b43132018-05-14 16:05:23 +01001096Status NEScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy,
Sang-Hoon Parkc2617982020-05-20 22:13:47 +01001097 const ITensorInfo *offsets, ITensorInfo *output, const ScaleKernelInfo &info)
Georgios Pinitas20b43132018-05-14 16:05:23 +01001098{
1099 BorderSize border_size(1);
1100 if(input->data_layout() == DataLayout::NHWC)
1101 {
Sang-Hoon Parkc2617982020-05-20 22:13:47 +01001102 border_size = (info.border_mode == BorderMode::CONSTANT && info.interpolation_policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
Georgios Pinitas20b43132018-05-14 16:05:23 +01001103 }
1104
Sang-Hoon Parkc2617982020-05-20 22:13:47 +01001105 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, info));
Georgios Pinitas20b43132018-05-14 16:05:23 +01001106 ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(),
1107 dx != nullptr ? dx->clone().get() : nullptr,
1108 dy != nullptr ? dy->clone().get() : nullptr,
1109 offsets != nullptr ? offsets->clone().get() : nullptr,
1110 output->clone().get(),
Sang-Hoon Parkc2617982020-05-20 22:13:47 +01001111 info, border_size)
Georgios Pinitas20b43132018-05-14 16:05:23 +01001112 .first);
1113
1114 return Status{};
1115}
1116
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001117void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001118{
Moritz Pflanzerc186b572017-09-07 09:48:04 +01001119 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001120 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
1121 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
1122 ARM_COMPUTE_ERROR_ON(_func == nullptr);
1123
1124 (this->*_func)(window);
1125}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +01001126} // namespace arm_compute