blob: 852ec3e023ed2f1c80321d6878430499f739679f [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Diego Lopez Recasff860cf2018-02-22 13:08:01 +00002 * Copyright (c) 2016-2018 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"
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
Diego Lopez Recas00854292018-02-22 13:08:01 +0000145 output_access.set_valid_region(win, calculate_valid_region_scale(*(input->info()),
146 output->info()->tensor_shape(),
147 policy,
148 sampling_policy,
149 border_undefined));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100150 INEKernel::configure(win);
151}
152
153void NEScaleKernel::scale_nearest(const Window &window)
154{
155 const size_t input_stride = _input->info()->strides_in_bytes()[1];
156
157 // Compute the ratio between source height and destination height
158 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
159
160 // Don't increment in X and Y direction for the input tensor
161 // A pointer to the start of this plane is needed as base for the precomputed offsets
162 Window win_in(window);
163 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
164 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
165
166 Window win_off;
167 win_off.set(Window::DimX, window[Window::DimX]);
168 win_off.set(Window::DimY, window[Window::DimY]);
169
170 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
171 {
172 win_off.set(d, Window::Dimension(0, 0, 0));
173 }
174
175 Iterator in(_input, win_in);
176 Iterator out(_output, window);
177 Iterator offsets(_offsets, win_off);
178
179 switch(_input->info()->data_type())
180 {
181 case DataType::U8:
182 {
183 uint8x16_t tmp = vdupq_n_u8(0);
184
185 execute_window_loop(window, [&](const Coordinates & id)
186 {
187 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
188 const uint8_t *const in_ptr = in.ptr();
189
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100190 const int in_yi = std::floor((id.y() + 0.5f) * hr);
191 const int in_yi_clamped = std::min(static_cast<int>(_input->info()->dimension(1)), std::max(in_yi, -1));
192 ARM_COMPUTE_ERROR_ON(in_yi_clamped < -1 || in_yi_clamped > static_cast<int>(_input->info()->dimension(1)));
193 const int offset_row = in_yi_clamped * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100194
195 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0);
196 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1);
197 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2);
198 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3);
199 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4);
200 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5);
201 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6);
202 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7);
203 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8);
204 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9);
205 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10);
206 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11);
207 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12);
208 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13);
209 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14);
210 tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15);
211
212 vst1q_u8(out.ptr(), tmp);
213 },
214 in, offsets, out);
215 break;
216 }
217 case DataType::S16:
218 {
219 int16x8x2_t tmp =
220 {
221 {
222 vdupq_n_s16(0),
223 vdupq_n_s16(0)
224 }
225 };
226
227 execute_window_loop(window, [&](const Coordinates & id)
228 {
229 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
230
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100231 const int in_yi = (id.y() + 0.5f) * hr;
232 const int offset_row = in_yi * input_stride;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100233
234 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
235 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1);
236 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2);
237 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3);
238 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4);
239 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5);
240 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6);
241 tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7);
242
243 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
244 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1);
245 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2);
246 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3);
247 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4);
248 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5);
249 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6);
250 tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7);
251
252 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
253 },
254 in, offsets, out);
255 break;
256 }
Georgios Pinitas583137c2017-08-31 18:12:42 +0100257 case DataType::F32:
258 {
259 float32x4x4_t tmp =
260 {
261 {
262 vdupq_n_f32(0),
263 vdupq_n_f32(0),
264 vdupq_n_f32(0),
265 vdupq_n_f32(0)
266 }
267 };
268
269 execute_window_loop(window, [&](const Coordinates & id)
270 {
271 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
272
273 const int in_yi = (id.y() + 0.5f) * hr;
274 const int offset_row = in_yi * input_stride;
275
276 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0);
277 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 1);
278 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 2);
279 tmp.val[0] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 3);
280
281 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0);
282 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 1);
283 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 2);
284 tmp.val[1] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 3);
285
286 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[2], 0);
287 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[2], 1);
288 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[2], 2);
289 tmp.val[2] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[2], 3);
290
291 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[3], 0);
292 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[3], 1);
293 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[3], 2);
294 tmp.val[3] = vsetq_lane_f32(*reinterpret_cast<const float *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[3], 3);
295
296 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
297 },
298 in, offsets, out);
299 break;
300 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100301 default:
302 ARM_COMPUTE_ERROR("Not supported");
303 break;
304 }
305}
306
307void NEScaleKernel::scale_bilinear(const Window &window)
308{
Georgios Pinitas583137c2017-08-31 18:12:42 +0100309 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8, DataType::S16, DataType::F32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100310
311 // Compute the ratio between source height and destination height
312 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
313
314 // Don't increment in X and Y direction for the input tensor
315 // A pointer to the start of this plane is needed as base for the precomputed offsets
316 Window win_in(window);
317 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
318 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
319
320 Window win_off;
321 win_off.set(Window::DimX, window.x());
322 win_off.set(Window::DimY, window.y());
323
324 for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d)
325 {
326 win_off.set(d, Window::Dimension(0, 0, 0));
327 }
328
329 Iterator in(_input, win_in);
330 Iterator out(_output, window);
331 Iterator offsets(_offsets, win_off);
332 Iterator dx(_dx, win_off);
333 Iterator dy(_dy, win_off);
334
335 /* Input image stride */
Georgios Pinitas583137c2017-08-31 18:12:42 +0100336 const size_t in_stide_in_bytes = _input->info()->strides_in_bytes()[1];
337 const size_t in_stride = in_stide_in_bytes / _input->info()->element_size();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100338
Georgios Pinitas583137c2017-08-31 18:12:42 +0100339 switch(_input->info()->data_type())
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100340 {
Georgios Pinitas583137c2017-08-31 18:12:42 +0100341 case DataType::U8:
342 {
343 execute_window_loop(window, [&](const Coordinates & id)
344 {
345 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
346 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
347 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
348 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100349
Georgios Pinitas583137c2017-08-31 18:12:42 +0100350 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
351 const int offset_row = in_yi * in_stide_in_bytes;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100352
Georgios Pinitas583137c2017-08-31 18:12:42 +0100353 uint8x8_t tmp0 = vdup_n_u8(0);
354 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0);
355 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1);
356 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2);
357 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3);
358 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4);
359 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5);
360 tmp0 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6);
361 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 +0100362
Georgios Pinitas583137c2017-08-31 18:12:42 +0100363 uint8x8_t tmp1 = vdup_n_u8(0);
364 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0);
365 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1);
366 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2);
367 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3);
368 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4);
369 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5);
370 tmp1 = vset_lane_u8(delta_bilinear_c1(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6);
371 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 +0100372
Georgios Pinitas583137c2017-08-31 18:12:42 +0100373 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
374 },
375 in, offsets, dx, dy, out);
376 break;
377 }
378 case DataType::S16:
379 {
380 execute_window_loop(window, [&](const Coordinates & id)
381 {
382 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
383 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
384 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
385
386 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
387 const int offset_row = in_yi * in_stide_in_bytes;
388
389 int16x8x2_t tmp =
390 {
391 {
392 vdupq_n_s16(0),
393 vdupq_n_s16(0)
394 }
395 };
396
397 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);
398 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);
399 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);
400 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);
401 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);
402 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);
403 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);
404 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);
405
406 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);
407 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);
408 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);
409 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);
410 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);
411 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);
412 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);
413 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);
414
415 vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp);
416 },
417 in, offsets, dx, dy, out);
418 break;
419 }
420 case DataType::F32:
421 {
422 execute_window_loop(window, [&](const Coordinates & id)
423 {
424 const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr());
425 const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr());
426 const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr());
427
428 const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f);
429 const int offset_row = in_yi * in_stide_in_bytes;
430
431 float32x4x4_t tmp =
432 {
433 {
434 vdupq_n_f32(0),
435 vdupq_n_f32(0),
436 vdupq_n_f32(0),
437 vdupq_n_f32(0)
438 }
439 };
440
441 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);
442 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);
443 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);
444 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);
445
446 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);
447 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);
448 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);
449 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);
450
451 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);
452 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);
453 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);
454 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);
455
456 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);
457 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);
458 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);
459 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);
460
461 vst4q_f32(reinterpret_cast<float *>(out.ptr()), tmp);
462 },
463 in, offsets, dx, dy, out);
464 break;
465 }
466 default:
467 ARM_COMPUTE_ERROR("Not supported");
468 break;
469 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100470}
471
472void NEScaleKernel::scale_area(const Window &window)
473{
474 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8);
475
476 // Don't increment in X and Y direction for the input tensor
477 // A pointer to the start of this plane is needed as base for the precomputed offsets
478 Window win_in(window);
479 win_in.set(Window::DimX, Window::Dimension(0, 0, 0));
480 win_in.set(Window::DimY, Window::Dimension(0, 0, 0));
481
482 Iterator in(_input, win_in);
483 Iterator out(_output, window);
484
485 const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0));
486 const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1));
487 const auto w = _input->info()->dimension(0);
488 const auto h = _input->info()->dimension(1);
489 const size_t in_stride = _input->info()->strides_in_bytes()[1];
490
491 execute_window_loop(window, [&](const Coordinates & id)
492 {
493 const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr());
494
495 uint8x8_t tmp0 = vdup_n_u8(0);
496 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0);
497 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1);
498 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2);
499 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3);
500 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4);
501 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5);
502 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6);
503 tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7);
504
505 uint8x8_t tmp1 = vdup_n_u8(0);
506 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0);
507 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1);
508 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2);
509 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3);
510 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4);
511 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5);
512 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6);
513 tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7);
514
515 vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1));
516 },
517 in, out);
518}
519
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100520void NEScaleKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100521{
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100522 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100523 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
524 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
525 ARM_COMPUTE_ERROR_ON(_func == nullptr);
526
527 (this->*_func)(window);
528}