blob: 1918a773006b5a6d8dd13ba3a096d6447d371286 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
3 *
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"
27#include "arm_compute/core/Coordinates.h"
28#include "arm_compute/core/Error.h"
29#include "arm_compute/core/Helpers.h"
30#include "arm_compute/core/ITensor.h"
31#include "arm_compute/core/TensorInfo.h"
32#include "arm_compute/core/Validate.h"
33#include "arm_compute/core/Window.h"
34
35#include <arm_neon.h>
36#include <cstddef>
37#include <cstdint>
38
39using namespace arm_compute;
40
41NEScaleKernel::NEScaleKernel()
42 : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr)
43{
44}
45
46BorderSize NEScaleKernel::border_size() const
47{
48 return BorderSize(1);
49}
50
Daniil Efremov02bf80d2017-11-22 00:26:51 +070051void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output, InterpolationPolicy policy, bool border_undefined,
52 SamplingPolicy sampling_policy)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053{
Georgios Pinitas583137c2017-08-31 18:12:42 +010054 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16, DataType::F32);
55 ARM_COMPUTE_ERROR_ON_NULLPTR(output);
56 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
57 ARM_COMPUTE_ERROR_ON(output == input);
Daniil Efremov02bf80d2017-11-22 00:26:51 +070058 ARM_COMPUTE_ERROR_ON(sampling_policy != SamplingPolicy::CENTER);
59 ARM_COMPUTE_UNUSED(sampling_policy);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060
61 if(policy == InterpolationPolicy::NEAREST_NEIGHBOR)
62 {
63 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
64 }
65
66 if(policy == InterpolationPolicy::BILINEAR)
67 {
68 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32);
69 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32);
70 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32);
71 }
72
73 ARM_COMPUTE_ERROR_ON(output->info()->dimension(0) == 0);
74 ARM_COMPUTE_ERROR_ON(output->info()->dimension(1) == 0);
75
76 for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i)
77 {
78 ARM_COMPUTE_ERROR_ON(input->info()->dimension(i) != output->info()->dimension(i));
79 }
80
81 _input = input;
82 _output = output;
83 _offsets = offsets;
84 _dx = dx;
85 _dy = dy;
86
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010087 /* Compute the ratio between source width/height and destination width/height */
88 const auto wr = static_cast<float>(input->info()->dimension(0)) / static_cast<float>(output->info()->dimension(0));
89 const auto hr = static_cast<float>(input->info()->dimension(1)) / static_cast<float>(output->info()->dimension(1));
90
91 /* Area interpolation behaves as Nearest Neighbour in case of up-sampling */
92 if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
93 {
94 policy = InterpolationPolicy::NEAREST_NEIGHBOR;
95 }
96
Anthony Barbier6ff3b192017-09-04 18:44:23 +010097 switch(policy)
98 {
99 case InterpolationPolicy::NEAREST_NEIGHBOR:
100 {
101 _func = &NEScaleKernel::scale_nearest;
102 break;
103 }
104 case InterpolationPolicy::BILINEAR:
105 {
106 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_dx, 1, DataType::F32);
107 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_dy, 1, DataType::F32);
108
109 _func = &NEScaleKernel::scale_bilinear;
110 break;
111 }
112 case InterpolationPolicy::AREA:
113 {
114 _func = &NEScaleKernel::scale_area;
115 break;
116 }
117 default:
118 ARM_COMPUTE_ERROR("Unsupported interpolation mode");
119 }
120
121 constexpr unsigned int num_elems_processed_per_iteration = 16;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122
123 // Configure kernel window
124 Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
125
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100126 const ValidRegion &input_valid_region = input->info()->valid_region();
127
128 // Reads can occur within the valid region of the input
129 AccessWindowStatic input_access(input->info(),
130 input_valid_region.anchor[0] - border_size().left, input_valid_region.anchor[1] - border_size().top,
131 input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size().right,
132 input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size().bottom);
133 AccessWindowHorizontal offsets_access(offsets == nullptr ? nullptr : offsets->info(), 0, num_elems_processed_per_iteration);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134 AccessWindowHorizontal dx_access(dx == nullptr ? nullptr : dx->info(), 0, num_elems_processed_per_iteration);
135 AccessWindowHorizontal dy_access(dy == nullptr ? nullptr : dy->info(), 0, num_elems_processed_per_iteration);
136 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
137
138 update_window_and_padding(win,
139 input_access,
140 offsets_access,
141 dx_access,
142 dy_access,
143 output_access);
144
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100145 output_access.set_valid_region(win, calculate_valid_region_scale(*(input->info()), output->info()->tensor_shape(), policy, border_size(), border_undefined));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100146 INEKernel::configure(win);
147}
148
149void NEScaleKernel::scale_nearest(const Window &window)
150{
151 const size_t input_stride = _input->info()->strides_in_bytes()[1];
152
153 // Compute the ratio between source height and destination height
154 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
155
156 // Don't increment in X and Y direction for the input tensor
157 // A pointer to the start of this plane is needed as base for the precomputed offsets
158 Window win_in(window);
159 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
160 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
161
162 Window win_off;
163 win_off.set(Window::DimX, window[Window::DimX]);
164 win_off.set(Window::DimY, window[Window::DimY]);
165
166 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
167 {
168 win_off.set(d, Window::Dimension(0, 0, 0));
169 }
170
171 Iterator in(_input, win_in);
172 Iterator out(_output, window);
173 Iterator offsets(_offsets, win_off);
174
175 switch(_input->info()->data_type())
176 {
177 case DataType::U8:
178 {
179 uint8x16_t tmp = vdupq_n_u8(0);
180
181 execute_window_loop(window, [&](const Coordinates & id)
182 {
183 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
184 const uint8_t *const in_ptr = in.ptr();
185
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100186 const int in_yi = std::floor((id.y() + 0.5f) * hr);
187 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
188 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
189 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100190
191 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
192 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
193 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
194 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
195 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
196 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
197 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
198 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
199 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
200 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
201 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
202 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
203 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
204 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
205 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
206 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
207
208 vst1q_u8(out.ptr(), tmp);
209 },
210 in, offsets, out);
211 break;
212 }
213 case DataType::S16:
214 {
215 int16x8x2_t tmp =
216 {
217 {
218 vdupq_n_s16(0),
219 vdupq_n_s16(0)
220 }
221 };
222
223 execute_window_loop(window, [&](const Coordinates & id)
224 {
225 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
226
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100227 const int in_yi = (id.y() + 0.5f) * hr;
228 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100229
230 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
231 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
232 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
233 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
234 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
235 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
236 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
237 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
238
239 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
240 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
241 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
242 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
243 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
244 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
245 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
246 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
247
248 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
249 },
250 in, offsets, out);
251 break;
252 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100253 case DataType::F32:
254 {
255 float32x4x4_t tmp =
256 {
257 {
258 vdupq_n_f32(0),
259 vdupq_n_f32(0),
260 vdupq_n_f32(0),
261 vdupq_n_f32(0)
262 }
263 };
264
265 execute_window_loop(window, [&](const Coordinates & id)
266 {
267 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
268
269 const int in_yi = (id.y() + 0.5f) * hr;
270 const int offset_row = in_yi * input_stride;
271
272 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
273 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
274 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
275 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
276
277 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
278 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
279 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
280 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
281
282 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
283 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
284 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
285 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
286
287 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
288 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
289 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
290 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
291
292 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
293 },
294 in, offsets, out);
295 break;
296 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100297 default:
298 ARM_COMPUTE_ERROR("Not supported");
299 break;
300 }
301}
302
303void NEScaleKernel::scale_bilinear(const Window &window)
304{
Georgios Pinitas583137c2017-08-31 18:12:42 +0100305 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::S16, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100306
307 // Compute the ratio between source height and destination height
308 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
309
310 // Don't increment in X and Y direction for the input tensor
311 // A pointer to the start of this plane is needed as base for the precomputed offsets
312 Window win_in(window);
313 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
314 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
315
316 Window win_off;
317 win_off.set(Window::DimX, window.x());
318 win_off.set(Window::DimY, window.y());
319
320 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
321 {
322 win_off.set(d, Window::Dimension(0, 0, 0));
323 }
324
325 Iterator in(_input, win_in);
326 Iterator out(_output, window);
327 Iterator offsets(_offsets, win_off);
328 Iterator dx(_dx, win_off);
329 Iterator dy(_dy, win_off);
330
331 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100332 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
333 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100334
Georgios Pinitas583137c2017-08-31 18:12:42 +0100335 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100336 {
Georgios Pinitas583137c2017-08-31 18:12:42 +0100337 case DataType::U8:
338 {
339 execute_window_loop(window, [&](const Coordinates & id)
340 {
341 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
342 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
343 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
344 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100345
Georgios Pinitas583137c2017-08-31 18:12:42 +0100346 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
347 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100348
Georgios Pinitas583137c2017-08-31 18:12:42 +0100349 uint8x8_t tmp0 = vdup_n_u8(0);
350 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
351 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
352 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
353 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
354 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
355 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
356 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
357 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100358
Georgios Pinitas583137c2017-08-31 18:12:42 +0100359 uint8x8_t tmp1 = vdup_n_u8(0);
360 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
361 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
362 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
363 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
364 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
365 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
366 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
367 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100368
Georgios Pinitas583137c2017-08-31 18:12:42 +0100369 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
370 },
371 in, offsets, dx, dy, out);
372 break;
373 }
374 case DataType::S16:
375 {
376 execute_window_loop(window, [&](const Coordinates & id)
377 {
378 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
379 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
380 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
381
382 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
383 const int offset_row = in_yi * in_stide_in_bytes;
384
385 int16x8x2_t tmp =
386 {
387 {
388 vdupq_n_s16(0),
389 vdupq_n_s16(0)
390 }
391 };
392
393 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);
394 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);
395 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);
396 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);
397 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);
398 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);
399 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);
400 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);
401
402 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);
403 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);
404 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);
405 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);
406 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);
407 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);
408 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);
409 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);
410
411 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
412 },
413 in, offsets, dx, dy, out);
414 break;
415 }
416 case DataType::F32:
417 {
418 execute_window_loop(window, [&](const Coordinates & id)
419 {
420 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
421 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
422 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
423
424 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
425 const int offset_row = in_yi * in_stide_in_bytes;
426
427 float32x4x4_t tmp =
428 {
429 {
430 vdupq_n_f32(0),
431 vdupq_n_f32(0),
432 vdupq_n_f32(0),
433 vdupq_n_f32(0)
434 }
435 };
436
437 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);
438 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);
439 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);
440 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);
441
442 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);
443 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);
444 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);
445 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);
446
447 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);
448 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);
449 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);
450 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);
451
452 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);
453 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);
454 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);
455 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);
456
457 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
458 },
459 in, offsets, dx, dy, out);
460 break;
461 }
462 default:
463 ARM_COMPUTE_ERROR("Not supported");
464 break;
465 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100466}
467
468void NEScaleKernel::scale_area(const Window &window)
469{
470 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
471
472 // Don't increment in X and Y direction for the input tensor
473 // A pointer to the start of this plane is needed as base for the precomputed offsets
474 Window win_in(window);
475 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
476 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
477
478 Iterator in(_input, win_in);
479 Iterator out(_output, window);
480
481 const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0));
482 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
483 const auto w = _input->info()->dimension(0);
484 const auto h = _input->info()->dimension(1);
485 const size_t in_stride = _input->info()->strides_in_bytes()[1];
486
487 execute_window_loop(window, [&](const Coordinates & id)
488 {
489 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
490
491 uint8x8_t tmp0 = vdup_n_u8(0);
492 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
493 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
494 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
495 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
496 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
497 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
498 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
499 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
500
501 uint8x8_t tmp1 = vdup_n_u8(0);
502 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
503 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
504 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
505 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
506 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
507 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
508 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
509 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
510
511 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
512 },
513 in, out);
514}
515
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100516void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100517{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100518 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100519 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
520 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
521 ARM_COMPUTE_ERROR_ON(_func == nullptr);
522
523 (this->*_func)(window);
524}