Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 1 | /* |
alerah01 | 4cbcb84 | 2022-02-28 06:38:08 +0200 | [diff] [blame] | 2 | * Copyright (c) 2021-2022 Arm Limited. |
Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 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 | */ |
alerah01 | 4cbcb84 | 2022-02-28 06:38:08 +0200 | [diff] [blame] | 24 | |
Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 25 | #include "arm_compute/core/Helpers.h" |
| 26 | #include "arm_compute/core/ITensorPack.h" |
| 27 | #include "arm_compute/core/Window.h" |
| 28 | #include "src/core/NEON/NEMath.h" |
| 29 | #include "src/core/NEON/wrapper/wrapper.h" |
Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 30 | #include "src/core/helpers/ScaleHelpers.h" |
| 31 | #include "src/core/helpers/ScaleHelpers.h" |
| 32 | #include "src/core/utils/ScaleUtils.h" |
| 33 | #include "support/Rounding.h" |
| 34 | |
Georgios Pinitas | bdcdc39 | 2021-04-22 16:42:03 +0100 | [diff] [blame] | 35 | #include <arm_sve.h> |
Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 36 | #include <cmath> |
| 37 | #include <cstddef> |
| 38 | |
Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace |
| 42 | { |
| 43 | void qasymm8_signed_sve_scale_nearest(const ITensor *src, ITensor *dst, const ITensor *offsets, |
| 44 | float sampling_offset, bool align_corners, const Window &window) |
| 45 | { |
| 46 | const size_t in_stride_c = src->info()->dimension(0) + src->info()->padding().left + src->info()->padding().right; |
| 47 | const size_t in_stride_w = src->info()->dimension(1) + src->info()->padding().top + src->info()->padding().bottom; |
| 48 | const size_t in_stride_wc = in_stride_w * in_stride_c; |
| 49 | const size_t in_dim_h = src->info()->dimension(2); |
| 50 | |
| 51 | // Compute the ratio between source height and destination height |
| 52 | const auto hr = scale_utils::calculate_resize_ratio(in_dim_h, dst->info()->dimension(2), align_corners); |
| 53 | const auto window_start_x = static_cast<int32_t>(window.x().start()); |
| 54 | const auto window_end_x = static_cast<int32_t>(window.x().end()); |
| 55 | |
| 56 | Window win(window); |
| 57 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 58 | Iterator out(dst, win); |
| 59 | |
| 60 | const uint8_t *in_ptr_start = src->buffer() + src->info()->offset_first_element_in_bytes(); |
| 61 | const unsigned int in_stride_bytes_hwc = src->info()->strides_in_bytes()[3]; |
| 62 | |
| 63 | execute_window_loop(win, [&](const Coordinates & id) |
| 64 | { |
| 65 | const int32_t offset = *reinterpret_cast<const int32_t *>(offsets->ptr_to_element(Coordinates(id.y(), id.z()))) * in_stride_c; |
| 66 | const auto in_hi = static_cast<int>(align_corners ? utils::rounding::round_half_away_from_zero((id.z() + sampling_offset) * hr) : std::floor((id.z() + sampling_offset) * hr)); |
| 67 | const int offset_row = in_hi * in_stride_wc; |
| 68 | const auto in_ptr = reinterpret_cast<const int8_t *>(in_ptr_start + in_stride_bytes_hwc * id[3]); |
| 69 | const auto out_ptr = reinterpret_cast<int8_t *>(out.ptr()); |
| 70 | |
| 71 | // Compute S elements per iteration |
| 72 | int x = window_start_x; |
| 73 | svbool_t pg = svwhilelt_b8(x, window_end_x); |
| 74 | do |
| 75 | { |
| 76 | // Store results |
| 77 | svst1_s8(pg, out_ptr + x, svld1_s8(pg, in_ptr + offset + offset_row + x)); |
| 78 | |
| 79 | x += svcntw(); |
| 80 | pg = svwhilelt_b8(x, window_end_x); |
| 81 | } |
| 82 | while(svptest_any(svptrue_b8(), pg)); |
| 83 | }, |
| 84 | out); |
| 85 | } |
Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 86 | } |
| 87 | namespace cpu |
| 88 | { |
| 89 | void qasymm8_signed_sve_scale(const ITensor *src, ITensor *dst, const ITensor *offsets, const ITensor *dx, const ITensor *dy, |
| 90 | InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, float sampling_offset, |
| 91 | bool align_corners, const Window &window) |
| 92 | { |
Gunes Bayir | c4f2743 | 2022-09-11 15:59:19 +0100 | [diff] [blame^] | 93 | ARM_COMPUTE_UNUSED(dx, dy, border_mode, constant_border_value); |
| 94 | if(policy == InterpolationPolicy::NEAREST_NEIGHBOR) |
Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 95 | { |
| 96 | qasymm8_signed_sve_scale_nearest(src, dst, offsets, sampling_offset, align_corners, window); |
| 97 | } |
Gunes Bayir | c4f2743 | 2022-09-11 15:59:19 +0100 | [diff] [blame^] | 98 | else |
| 99 | { |
| 100 | ARM_COMPUTE_ERROR("Not Implemented"); |
| 101 | } |
Sheri Zhang | 23adc4c | 2021-01-05 12:48:45 +0000 | [diff] [blame] | 102 | } |
| 103 | } // namespace cpu |
| 104 | } // namespace arm_compute |