Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 39 | using namespace arm_compute; |
| 40 | |
| 41 | NEScaleKernel::NEScaleKernel() |
| 42 | : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | BorderSize NEScaleKernel::border_size() const |
| 47 | { |
| 48 | return BorderSize(1); |
| 49 | } |
| 50 | |
| 51 | void NEScaleKernel::configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output, InterpolationPolicy policy, bool border_undefined) |
| 52 | { |
| 53 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S16); |
| 54 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8, DataType::S16); |
| 55 | |
| 56 | if(policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
| 57 | { |
| 58 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32); |
| 59 | } |
| 60 | |
| 61 | if(policy == InterpolationPolicy::BILINEAR) |
| 62 | { |
| 63 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(offsets, 1, DataType::S32); |
| 64 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dx, 1, DataType::F32); |
| 65 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(dy, 1, DataType::F32); |
| 66 | } |
| 67 | |
| 68 | ARM_COMPUTE_ERROR_ON(output->info()->dimension(0) == 0); |
| 69 | ARM_COMPUTE_ERROR_ON(output->info()->dimension(1) == 0); |
| 70 | |
| 71 | for(size_t i = 2; i < Coordinates::num_max_dimensions; ++i) |
| 72 | { |
| 73 | ARM_COMPUTE_ERROR_ON(input->info()->dimension(i) != output->info()->dimension(i)); |
| 74 | } |
| 75 | |
| 76 | _input = input; |
| 77 | _output = output; |
| 78 | _offsets = offsets; |
| 79 | _dx = dx; |
| 80 | _dy = dy; |
| 81 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 82 | /* Compute the ratio between source width/height and destination width/height */ |
| 83 | const auto wr = static_cast<float>(input->info()->dimension(0)) / static_cast<float>(output->info()->dimension(0)); |
| 84 | const auto hr = static_cast<float>(input->info()->dimension(1)) / static_cast<float>(output->info()->dimension(1)); |
| 85 | |
| 86 | /* Area interpolation behaves as Nearest Neighbour in case of up-sampling */ |
| 87 | if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) |
| 88 | { |
| 89 | policy = InterpolationPolicy::NEAREST_NEIGHBOR; |
| 90 | } |
| 91 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 92 | switch(policy) |
| 93 | { |
| 94 | case InterpolationPolicy::NEAREST_NEIGHBOR: |
| 95 | { |
| 96 | _func = &NEScaleKernel::scale_nearest; |
| 97 | break; |
| 98 | } |
| 99 | case InterpolationPolicy::BILINEAR: |
| 100 | { |
| 101 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_dx, 1, DataType::F32); |
| 102 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_dy, 1, DataType::F32); |
| 103 | |
| 104 | _func = &NEScaleKernel::scale_bilinear; |
| 105 | break; |
| 106 | } |
| 107 | case InterpolationPolicy::AREA: |
| 108 | { |
| 109 | _func = &NEScaleKernel::scale_area; |
| 110 | break; |
| 111 | } |
| 112 | default: |
| 113 | ARM_COMPUTE_ERROR("Unsupported interpolation mode"); |
| 114 | } |
| 115 | |
| 116 | constexpr unsigned int num_elems_processed_per_iteration = 16; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 117 | |
| 118 | // Configure kernel window |
| 119 | Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration)); |
| 120 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 121 | const ValidRegion &input_valid_region = input->info()->valid_region(); |
| 122 | |
| 123 | // Reads can occur within the valid region of the input |
| 124 | AccessWindowStatic input_access(input->info(), |
| 125 | input_valid_region.anchor[0] - border_size().left, input_valid_region.anchor[1] - border_size().top, |
| 126 | input_valid_region.anchor[0] + input_valid_region.shape[0] + border_size().right, |
| 127 | input_valid_region.anchor[1] + input_valid_region.shape[1] + border_size().bottom); |
| 128 | AccessWindowHorizontal offsets_access(offsets == nullptr ? nullptr : offsets->info(), 0, num_elems_processed_per_iteration); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 129 | AccessWindowHorizontal dx_access(dx == nullptr ? nullptr : dx->info(), 0, num_elems_processed_per_iteration); |
| 130 | AccessWindowHorizontal dy_access(dy == nullptr ? nullptr : dy->info(), 0, num_elems_processed_per_iteration); |
| 131 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration); |
| 132 | |
| 133 | update_window_and_padding(win, |
| 134 | input_access, |
| 135 | offsets_access, |
| 136 | dx_access, |
| 137 | dy_access, |
| 138 | output_access); |
| 139 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 140 | output_access.set_valid_region(win, calculate_valid_region_scale(*(input->info()), output->info()->tensor_shape(), policy, border_size(), border_undefined)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 141 | INEKernel::configure(win); |
| 142 | } |
| 143 | |
| 144 | void NEScaleKernel::scale_nearest(const Window &window) |
| 145 | { |
| 146 | const size_t input_stride = _input->info()->strides_in_bytes()[1]; |
| 147 | |
| 148 | // Compute the ratio between source height and destination height |
| 149 | const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1)); |
| 150 | |
| 151 | // Don't increment in X and Y direction for the input tensor |
| 152 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 153 | Window win_in(window); |
| 154 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 155 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 156 | |
| 157 | Window win_off; |
| 158 | win_off.set(Window::DimX, window[Window::DimX]); |
| 159 | win_off.set(Window::DimY, window[Window::DimY]); |
| 160 | |
| 161 | for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d) |
| 162 | { |
| 163 | win_off.set(d, Window::Dimension(0, 0, 0)); |
| 164 | } |
| 165 | |
| 166 | Iterator in(_input, win_in); |
| 167 | Iterator out(_output, window); |
| 168 | Iterator offsets(_offsets, win_off); |
| 169 | |
| 170 | switch(_input->info()->data_type()) |
| 171 | { |
| 172 | case DataType::U8: |
| 173 | { |
| 174 | uint8x16_t tmp = vdupq_n_u8(0); |
| 175 | |
| 176 | execute_window_loop(window, [&](const Coordinates & id) |
| 177 | { |
| 178 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 179 | const uint8_t *const in_ptr = in.ptr(); |
| 180 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 181 | const int in_yi = std::floor((id.y() + 0.5f) * hr); |
| 182 | const int offset_row = in_yi * input_stride; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 183 | |
| 184 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[0] + offset_row], tmp, 0); |
| 185 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[1] + offset_row], tmp, 1); |
| 186 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[2] + offset_row], tmp, 2); |
| 187 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[3] + offset_row], tmp, 3); |
| 188 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[4] + offset_row], tmp, 4); |
| 189 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[5] + offset_row], tmp, 5); |
| 190 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[6] + offset_row], tmp, 6); |
| 191 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[7] + offset_row], tmp, 7); |
| 192 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[8] + offset_row], tmp, 8); |
| 193 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[9] + offset_row], tmp, 9); |
| 194 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[10] + offset_row], tmp, 10); |
| 195 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[11] + offset_row], tmp, 11); |
| 196 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[12] + offset_row], tmp, 12); |
| 197 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[13] + offset_row], tmp, 13); |
| 198 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[14] + offset_row], tmp, 14); |
| 199 | tmp = vsetq_lane_u8(in_ptr[offsets_ptr[15] + offset_row], tmp, 15); |
| 200 | |
| 201 | vst1q_u8(out.ptr(), tmp); |
| 202 | }, |
| 203 | in, offsets, out); |
| 204 | break; |
| 205 | } |
| 206 | case DataType::S16: |
| 207 | { |
| 208 | int16x8x2_t tmp = |
| 209 | { |
| 210 | { |
| 211 | vdupq_n_s16(0), |
| 212 | vdupq_n_s16(0) |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | execute_window_loop(window, [&](const Coordinates & id) |
| 217 | { |
| 218 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 219 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 220 | const int in_yi = (id.y() + 0.5f) * hr; |
| 221 | const int offset_row = in_yi * input_stride; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 222 | |
| 223 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[0] + offset_row), tmp.val[0], 0); |
| 224 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[2] + offset_row), tmp.val[0], 1); |
| 225 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[4] + offset_row), tmp.val[0], 2); |
| 226 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[6] + offset_row), tmp.val[0], 3); |
| 227 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[8] + offset_row), tmp.val[0], 4); |
| 228 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[10] + offset_row), tmp.val[0], 5); |
| 229 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[12] + offset_row), tmp.val[0], 6); |
| 230 | tmp.val[0] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[14] + offset_row), tmp.val[0], 7); |
| 231 | |
| 232 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[1] + offset_row), tmp.val[1], 0); |
| 233 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[3] + offset_row), tmp.val[1], 1); |
| 234 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[5] + offset_row), tmp.val[1], 2); |
| 235 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[7] + offset_row), tmp.val[1], 3); |
| 236 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[9] + offset_row), tmp.val[1], 4); |
| 237 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[11] + offset_row), tmp.val[1], 5); |
| 238 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[13] + offset_row), tmp.val[1], 6); |
| 239 | tmp.val[1] = vsetq_lane_s16(*reinterpret_cast<const int16_t *>(in.ptr() + offsets_ptr[15] + offset_row), tmp.val[1], 7); |
| 240 | |
| 241 | vst2q_s16(reinterpret_cast<int16_t *>(out.ptr()), tmp); |
| 242 | }, |
| 243 | in, offsets, out); |
| 244 | break; |
| 245 | } |
| 246 | default: |
| 247 | ARM_COMPUTE_ERROR("Not supported"); |
| 248 | break; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | void NEScaleKernel::scale_bilinear(const Window &window) |
| 253 | { |
| 254 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8); |
| 255 | |
| 256 | // Compute the ratio between source height and destination height |
| 257 | const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1)); |
| 258 | |
| 259 | // Don't increment in X and Y direction for the input tensor |
| 260 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 261 | Window win_in(window); |
| 262 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 263 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 264 | |
| 265 | Window win_off; |
| 266 | win_off.set(Window::DimX, window.x()); |
| 267 | win_off.set(Window::DimY, window.y()); |
| 268 | |
| 269 | for(size_t d = Window::DimZ; d < _offsets->info()->num_dimensions(); ++d) |
| 270 | { |
| 271 | win_off.set(d, Window::Dimension(0, 0, 0)); |
| 272 | } |
| 273 | |
| 274 | Iterator in(_input, win_in); |
| 275 | Iterator out(_output, window); |
| 276 | Iterator offsets(_offsets, win_off); |
| 277 | Iterator dx(_dx, win_off); |
| 278 | Iterator dy(_dy, win_off); |
| 279 | |
| 280 | /* Input image stride */ |
| 281 | const size_t in_stride = _input->info()->strides_in_bytes()[1]; |
| 282 | |
| 283 | execute_window_loop(window, [&](const Coordinates & id) |
| 284 | { |
| 285 | const auto offsets_ptr = reinterpret_cast<const int32_t *>(offsets.ptr()); |
| 286 | const auto dx_ptr = reinterpret_cast<const float *>(dx.ptr()); |
| 287 | const auto dy_ptr = reinterpret_cast<const float *>(dy.ptr()); |
| 288 | const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr()); |
| 289 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 290 | const int in_yi = std::floor((id.y() + 0.5f) * hr - 0.5f); |
| 291 | const int offset_row = in_yi * in_stride; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 292 | |
| 293 | uint8x8_t tmp0 = vdup_n_u8(0); |
| 294 | tmp0 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[0] + offset_row], in_stride, dx_ptr[0], dy_ptr[0]), tmp0, 0); |
| 295 | tmp0 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[1] + offset_row], in_stride, dx_ptr[1], dy_ptr[1]), tmp0, 1); |
| 296 | tmp0 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[2] + offset_row], in_stride, dx_ptr[2], dy_ptr[2]), tmp0, 2); |
| 297 | tmp0 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[3] + offset_row], in_stride, dx_ptr[3], dy_ptr[3]), tmp0, 3); |
| 298 | tmp0 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[4] + offset_row], in_stride, dx_ptr[4], dy_ptr[4]), tmp0, 4); |
| 299 | tmp0 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[5] + offset_row], in_stride, dx_ptr[5], dy_ptr[5]), tmp0, 5); |
| 300 | tmp0 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[6] + offset_row], in_stride, dx_ptr[6], dy_ptr[6]), tmp0, 6); |
| 301 | tmp0 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[7] + offset_row], in_stride, dx_ptr[7], dy_ptr[7]), tmp0, 7); |
| 302 | |
| 303 | uint8x8_t tmp1 = vdup_n_u8(0); |
| 304 | tmp1 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[8] + offset_row], in_stride, dx_ptr[8], dy_ptr[8]), tmp1, 0); |
| 305 | tmp1 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[9] + offset_row], in_stride, dx_ptr[9], dy_ptr[9]), tmp1, 1); |
| 306 | tmp1 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[10] + offset_row], in_stride, dx_ptr[10], dy_ptr[10]), tmp1, 2); |
| 307 | tmp1 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[11] + offset_row], in_stride, dx_ptr[11], dy_ptr[11]), tmp1, 3); |
| 308 | tmp1 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[12] + offset_row], in_stride, dx_ptr[12], dy_ptr[12]), tmp1, 4); |
| 309 | tmp1 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[13] + offset_row], in_stride, dx_ptr[13], dy_ptr[13]), tmp1, 5); |
| 310 | tmp1 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[14] + offset_row], in_stride, dx_ptr[14], dy_ptr[14]), tmp1, 6); |
| 311 | tmp1 = vset_lane_u8(delta_bilinear_c1u8(&in_ptr[offsets_ptr[15] + offset_row], in_stride, dx_ptr[15], dy_ptr[15]), tmp1, 7); |
| 312 | |
| 313 | vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1)); |
| 314 | }, |
| 315 | in, offsets, dx, dy, out); |
| 316 | } |
| 317 | |
| 318 | void NEScaleKernel::scale_area(const Window &window) |
| 319 | { |
| 320 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(_input, 1, DataType::U8); |
| 321 | |
| 322 | // Don't increment in X and Y direction for the input tensor |
| 323 | // A pointer to the start of this plane is needed as base for the precomputed offsets |
| 324 | Window win_in(window); |
| 325 | win_in.set(Window::DimX, Window::Dimension(0, 0, 0)); |
| 326 | win_in.set(Window::DimY, Window::Dimension(0, 0, 0)); |
| 327 | |
| 328 | Iterator in(_input, win_in); |
| 329 | Iterator out(_output, window); |
| 330 | |
| 331 | const auto wr = static_cast<float>(_input->info()->dimension(0)) / static_cast<float>(_output->info()->dimension(0)); |
| 332 | const auto hr = static_cast<float>(_input->info()->dimension(1)) / static_cast<float>(_output->info()->dimension(1)); |
| 333 | const auto w = _input->info()->dimension(0); |
| 334 | const auto h = _input->info()->dimension(1); |
| 335 | const size_t in_stride = _input->info()->strides_in_bytes()[1]; |
| 336 | |
| 337 | execute_window_loop(window, [&](const Coordinates & id) |
| 338 | { |
| 339 | const auto in_ptr = reinterpret_cast<const uint8_t *>(in.ptr()); |
| 340 | |
| 341 | uint8x8_t tmp0 = vdup_n_u8(0); |
| 342 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x(), id.y()), tmp0, 0); |
| 343 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 1, id.y()), tmp0, 1); |
| 344 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 2, id.y()), tmp0, 2); |
| 345 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 3, id.y()), tmp0, 3); |
| 346 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 4, id.y()), tmp0, 4); |
| 347 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 5, id.y()), tmp0, 5); |
| 348 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 6, id.y()), tmp0, 6); |
| 349 | tmp0 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 7, id.y()), tmp0, 7); |
| 350 | |
| 351 | uint8x8_t tmp1 = vdup_n_u8(0); |
| 352 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 8, id.y()), tmp1, 0); |
| 353 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 9, id.y()), tmp1, 1); |
| 354 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 10, id.y()), tmp1, 2); |
| 355 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 11, id.y()), tmp1, 3); |
| 356 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 12, id.y()), tmp1, 4); |
| 357 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 13, id.y()), tmp1, 5); |
| 358 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 14, id.y()), tmp1, 6); |
| 359 | tmp1 = vset_lane_u8(pixel_area_c1u8_clamp(in_ptr, in_stride, w, h, wr, hr, id.x() + 15, id.y()), tmp1, 7); |
| 360 | |
| 361 | vst1q_u8(out.ptr(), vcombine_u8(tmp0, tmp1)); |
| 362 | }, |
| 363 | in, out); |
| 364 | } |
| 365 | |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 366 | void NEScaleKernel::run(const Window &window, const ThreadInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 367 | { |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 368 | ARM_COMPUTE_UNUSED(info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 369 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 370 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window); |
| 371 | ARM_COMPUTE_ERROR_ON(_func == nullptr); |
| 372 | |
| 373 | (this->*_func)(window); |
| 374 | } |