Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020-2021 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 | */ |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 24 | #ifndef SRC_CORE_SVE_KERNELS_ADD_LIST_H |
| 25 | #define SRC_CORE_SVE_KERNELS_ADD_LIST_H |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 26 | |
| 27 | #if defined(__ARM_FEATURE_SVE) |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "arm_compute/core/utils/misc/Traits.h" |
| 30 | #include "src/core/NEON/SVEMath.h" |
| 31 | #include "src/core/NEON/wrapper/intrinsics/intrinsics.h" |
| 32 | #include <arm_sve.h> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace cpu |
| 37 | { |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 38 | #define DECLARE_ADD_KERNEL(func_name) \ |
| 39 | void func_name(const ITensor *src0, const ITensor *src1, ITensor *dst, const ConvertPolicy &policy, const Window &window) |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 40 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 41 | DECLARE_ADD_KERNEL(add_qasymm8_sve); |
| 42 | DECLARE_ADD_KERNEL(add_qasymm8_signed_sve); |
| 43 | DECLARE_ADD_KERNEL(add_qsymm16_sve); |
| 44 | DECLARE_ADD_KERNEL(add_s16_u8_s16_sve); |
| 45 | DECLARE_ADD_KERNEL(add_u8_s16_s16_sve); |
| 46 | DECLARE_ADD_KERNEL(add_u8_u8_s16_sve); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 47 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 48 | #undef DECLARE_ADD_KERNEL |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 49 | |
| 50 | template <typename ScalarType> |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 51 | void add_same_sve(const ITensor *src0, const ITensor *src1, ITensor *dst, const ConvertPolicy &policy, const Window &window) |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 52 | { |
| 53 | const auto all_true_pg = wrapper::svptrue<ScalarType>(); |
| 54 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 55 | const auto window_end_x = static_cast<int>(window.x().end()); |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 56 | const bool is_broadcast_across_x = src0->info()->tensor_shape().x() != src1->info()->tensor_shape().x(); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 57 | const bool is_sat = (policy == ConvertPolicy::SATURATE); |
| 58 | |
| 59 | // Clear X Dimension on execution window as we handle manually |
| 60 | Window win = window; |
| 61 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 62 | |
| 63 | // Create input windows |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 64 | Window input1_win = window.broadcast_if_dimension_le_one(src0->info()->tensor_shape()); |
| 65 | Window input2_win = window.broadcast_if_dimension_le_one(src1->info()->tensor_shape()); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 66 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 67 | Iterator input1(src0, window.broadcast_if_dimension_le_one(src0->info()->tensor_shape())); |
| 68 | Iterator input2(src1, window.broadcast_if_dimension_le_one(src1->info()->tensor_shape())); |
| 69 | Iterator output(dst, window); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 70 | |
| 71 | if(is_broadcast_across_x) |
| 72 | { |
| 73 | const bool is_broadcast_input_2 = input2_win.x().step() == 0; |
| 74 | Window broadcast_win = is_broadcast_input_2 ? input2_win : input1_win; |
| 75 | Window non_broadcast_win = !is_broadcast_input_2 ? input2_win : input1_win; |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 76 | const ITensor *broadcast_tensor = is_broadcast_input_2 ? src1 : src0; |
| 77 | const ITensor *non_broadcast_tensor = !is_broadcast_input_2 ? src1 : src0; |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 78 | |
| 79 | // Clear X Dimension on execution window as we handle manually |
| 80 | non_broadcast_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 81 | |
| 82 | Iterator broadcast_input(broadcast_tensor, broadcast_win); |
| 83 | Iterator non_broadcast_input(non_broadcast_tensor, non_broadcast_win); |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 84 | Iterator output(dst, win); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 85 | |
| 86 | execute_window_loop(win, [&](const Coordinates &) |
| 87 | { |
| 88 | const auto non_broadcast_input_ptr = reinterpret_cast<const ScalarType *>(non_broadcast_input.ptr()); |
| 89 | const auto output_ptr = reinterpret_cast<ScalarType *>(output.ptr()); |
| 90 | |
| 91 | const ScalarType broadcast_value = *reinterpret_cast<const ScalarType *>(broadcast_input.ptr()); |
| 92 | const auto broadcast_value_vec = wrapper::svdup_n(broadcast_value); |
| 93 | |
| 94 | int x = window_start_x; |
| 95 | svbool_t pg = wrapper::svwhilelt<ScalarType>(x, window_end_x); |
| 96 | do |
| 97 | { |
| 98 | const auto non_broadcast_v = svld1(pg, non_broadcast_input_ptr + x); |
| 99 | auto res = is_sat ? wrapper::svqadd(broadcast_value_vec, non_broadcast_v) : svadd_z(pg, broadcast_value_vec, non_broadcast_v); |
| 100 | svst1(pg, output_ptr + x, res); |
| 101 | |
| 102 | x += wrapper::svcnt<ScalarType>(); |
| 103 | pg = wrapper::svwhilelt<ScalarType>(x, window_end_x); |
| 104 | } |
| 105 | while(svptest_any(all_true_pg, pg)); |
| 106 | }, |
| 107 | broadcast_input, non_broadcast_input, output); |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | // Clear X Dimension on execution window as we handle manually |
| 112 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 113 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 114 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 115 | Iterator input1(src0, input1_win); |
| 116 | Iterator input2(src1, input2_win); |
| 117 | Iterator output(dst, win); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 118 | |
| 119 | execute_window_loop(win, [&](const Coordinates &) |
| 120 | { |
| 121 | const auto input1_ptr = reinterpret_cast<const ScalarType *>(input1.ptr()); |
| 122 | const auto input2_ptr = reinterpret_cast<const ScalarType *>(input2.ptr()); |
| 123 | const auto output_ptr = reinterpret_cast<ScalarType *>(output.ptr()); |
| 124 | |
| 125 | int x = window_start_x; |
| 126 | svbool_t pg = wrapper::svwhilelt<ScalarType>(x, window_end_x); |
| 127 | do |
| 128 | { |
| 129 | const auto val1 = svld1(pg, input1_ptr + x); |
| 130 | const auto val2 = svld1(pg, input2_ptr + x); |
| 131 | const auto res = is_sat ? wrapper::svqadd(val1, val2) : svadd_z(pg, val1, val2); |
| 132 | svst1(pg, output_ptr + x, res); |
| 133 | |
| 134 | x += wrapper::svcnt<ScalarType>(); |
| 135 | pg = wrapper::svwhilelt<ScalarType>(x, window_end_x); |
| 136 | } |
| 137 | while(svptest_any(all_true_pg, pg)); |
| 138 | }, |
| 139 | input1, input2, output); |
| 140 | } |
| 141 | } |
| 142 | } // namespace cpu |
| 143 | } // namespace arm_compute |
| 144 | #endif // defined(__ARM_FEATURE_SVE) |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame^] | 145 | #endif // SRC_CORE_SVE_KERNELS_ADD_LIST_H |