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 | */ |
| 24 | #include "arm_compute/core/Helpers.h" |
| 25 | #include "arm_compute/core/ITensor.h" |
| 26 | #include "arm_compute/core/Types.h" |
| 27 | #include "arm_compute/core/utils/misc/Traits.h" |
| 28 | #include "src/core/NEON/wrapper/intrinsics/intrinsics.h" |
| 29 | #if defined(__ARM_FEATURE_SVE) |
| 30 | #include "src/core/NEON/SVEMath.h" |
| 31 | #include <arm_sve.h> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace cpu |
| 36 | { |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 37 | void add_u8_u8_s16_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] | 38 | { |
| 39 | // Create input windows |
| 40 | Window win = window; |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 41 | Window input1_win = window.broadcast_if_dimension_le_one(src0->info()->tensor_shape()); |
| 42 | 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] | 43 | |
| 44 | // Clear X Dimension on execution window as we handle manually |
| 45 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 46 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 47 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 48 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 49 | Iterator input1(src0, input1_win); |
| 50 | Iterator input2(src1, input2_win); |
| 51 | Iterator output(dst, win); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 52 | |
| 53 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 54 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 55 | const auto all_true_pg = svptrue_b8(); |
| 56 | |
| 57 | execute_window_loop(win, [&](const Coordinates &) |
| 58 | { |
| 59 | const auto input1_ptr = reinterpret_cast<const uint8_t *>(input1.ptr()); |
| 60 | const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr()); |
| 61 | const auto output_ptr = reinterpret_cast<int16_t *>(output.ptr()); |
| 62 | |
| 63 | if(policy == ConvertPolicy::WRAP) |
| 64 | { |
| 65 | int x = window_start_x; |
| 66 | svbool_t pg_u = svwhilelt_b8(x, window_end_x); |
| 67 | svbool_t pg_0 = svwhilelt_b16(x, window_end_x); |
| 68 | svbool_t pg_1 = svwhilelt_b16(x, static_cast<int>(window_end_x + svcnth())); |
| 69 | do |
| 70 | { |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 71 | const auto vsrc0 = svld1(pg_u, input1_ptr + x); |
| 72 | const auto vsrc1 = svld1(pg_u, input2_ptr + x); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 73 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 74 | const auto vsrc0_lo = svreinterpret_s16_u16(svunpklo(vsrc0)); |
| 75 | const auto vsrc0_hi = svreinterpret_s16_u16(svunpkhi(vsrc0)); |
| 76 | const auto vsrc1_lo = svreinterpret_s16_u16(svunpklo(vsrc1)); |
| 77 | const auto vsrc1_hi = svreinterpret_s16_u16(svunpkhi(vsrc1)); |
| 78 | svst1(pg_0, output_ptr + x, svqadd(vsrc0_lo, vsrc1_lo)); |
| 79 | svst1(pg_1, output_ptr + x + svcnth(), svqadd(vsrc0_hi, vsrc1_hi)); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 80 | |
| 81 | x += svcntb(); |
| 82 | pg_u = svwhilelt_b8(x, window_end_x); |
| 83 | pg_0 = svwhilelt_b16(x, window_end_x); |
| 84 | pg_1 = svwhilelt_b16(x, static_cast<int>(window_end_x + svcnth())); |
| 85 | } |
| 86 | while(svptest_any(all_true_pg, pg_u)); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | int x = window_start_x; |
| 91 | svbool_t pg_u = svwhilelt_b8(x, window_end_x); |
| 92 | svbool_t pg_0 = svwhilelt_b16(x, window_end_x); |
| 93 | svbool_t pg_1 = svwhilelt_b16(x, static_cast<int>(window_end_x + svcnth())); |
| 94 | do |
| 95 | { |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 96 | const auto vsrc0 = svld1(pg_u, input1_ptr + x); |
| 97 | const auto vsrc1 = svld1(pg_u, input2_ptr + x); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 98 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 99 | const auto vsrc0_lo = svreinterpret_s16_u16(svunpklo(vsrc0)); |
| 100 | const auto vsrc0_hi = svreinterpret_s16_u16(svunpkhi(vsrc0)); |
| 101 | const auto vsrc1_lo = svreinterpret_s16_u16(svunpklo(vsrc1)); |
| 102 | const auto vsrc1_hi = svreinterpret_s16_u16(svunpkhi(vsrc1)); |
| 103 | svst1(pg_0, output_ptr + x, svqadd(vsrc0_lo, vsrc1_lo)); |
| 104 | svst1(pg_1, output_ptr + x + svcnth(), svqadd(vsrc0_hi, vsrc1_hi)); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 105 | |
| 106 | x += svcntb(); |
| 107 | pg_u = svwhilelt_b8(x, window_end_x); |
| 108 | pg_0 = svwhilelt_b16(x, window_end_x); |
| 109 | pg_1 = svwhilelt_b16(x, static_cast<int>(window_end_x + svcnth())); |
| 110 | } |
| 111 | while(svptest_any(all_true_pg, pg_u)); |
| 112 | } |
| 113 | }, |
| 114 | input1, input2, output); |
| 115 | } |
| 116 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 117 | void add_s16_u8_s16_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] | 118 | { |
| 119 | // Create input windows |
| 120 | Window win = window; |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 121 | Window input1_win = window.broadcast_if_dimension_le_one(src0->info()->tensor_shape()); |
| 122 | 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] | 123 | |
| 124 | // Clear X Dimension on execution window as we handle manually |
| 125 | win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 126 | input1_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 127 | input2_win.set(Window::DimX, Window::Dimension(0, 1, 1)); |
| 128 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 129 | Iterator input1(src0, input1_win); |
| 130 | Iterator input2(src1, input2_win); |
| 131 | Iterator output(dst, win); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 132 | |
| 133 | const auto window_start_x = static_cast<int>(window.x().start()); |
| 134 | const auto window_end_x = static_cast<int>(window.x().end()); |
| 135 | const auto all_true_pg = svptrue_b8(); |
| 136 | |
| 137 | execute_window_loop(win, [&](const Coordinates &) |
| 138 | { |
| 139 | const auto input1_ptr = reinterpret_cast<const int16_t *>(input1.ptr()); |
| 140 | const auto input2_ptr = reinterpret_cast<const uint8_t *>(input2.ptr()); |
| 141 | const auto output_ptr = reinterpret_cast<int16_t *>(output.ptr()); |
| 142 | |
| 143 | if(policy == ConvertPolicy::WRAP) |
| 144 | { |
| 145 | int x = window_start_x; |
| 146 | svbool_t pg_u = svwhilelt_b8(x, window_end_x); |
| 147 | svbool_t pg_0 = svwhilelt_b16(x, window_end_x); |
| 148 | svbool_t pg_1 = svwhilelt_b16(x + static_cast<int>(svcnth()), window_end_x); |
| 149 | do |
| 150 | { |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 151 | const auto vsrc0_0 = svld1_s16(pg_0, input1_ptr + x); |
| 152 | const auto vsrc0_1 = svld1_s16(pg_1, input1_ptr + x + svcnth()); |
| 153 | const auto vsrc1_u8 = svld1_u8(pg_u, input2_ptr + x); |
| 154 | const auto vsrc1_0 = svreinterpret_s16_u16(svunpklo(vsrc1_u8)); |
| 155 | const auto vsrc1_1 = svreinterpret_s16_u16(svunpkhi(vsrc1_u8)); |
| 156 | svst1_s16(pg_0, output_ptr + x, svadd_s16_z(pg_0, vsrc0_0, vsrc1_0)); |
Sang-Hoon Park | 32e0646 | 2021-03-23 15:34:04 +0000 | [diff] [blame] | 157 | svst1_s16(pg_1, output_ptr + x + svcnth(), svadd_s16_z(pg_1, vsrc0_1, vsrc1_1)); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 158 | |
Sang-Hoon Park | 32e0646 | 2021-03-23 15:34:04 +0000 | [diff] [blame] | 159 | x += svcntb(); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 160 | pg_u = svwhilelt_b8(x, window_end_x); |
| 161 | pg_0 = svwhilelt_b16(x, window_end_x); |
| 162 | pg_1 = svwhilelt_b16(x + static_cast<int>(svcnth()), window_end_x); |
| 163 | } |
| 164 | while(svptest_any(all_true_pg, pg_u)); |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | int x = window_start_x; |
| 169 | svbool_t pg_u = svwhilelt_b8(x, window_end_x); |
| 170 | svbool_t pg_0 = svwhilelt_b16(x, window_end_x); |
| 171 | svbool_t pg_1 = svwhilelt_b16(x + static_cast<int>(svcnth()), window_end_x); |
| 172 | do |
| 173 | { |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 174 | const auto vsrc0_0 = svld1_s16(pg_0, input1_ptr + x); |
Sang-Hoon Park | 32e0646 | 2021-03-23 15:34:04 +0000 | [diff] [blame] | 175 | const auto vsrc0_1 = svld1_s16(pg_1, input1_ptr + x + svcnth()); |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 176 | const auto vsrc1_u8 = svld1_u8(pg_u, input2_ptr + x); |
| 177 | const auto vsrc1_0 = svreinterpret_s16_u16(svunpklo(vsrc1_u8)); |
| 178 | const auto vsrc1_1 = svreinterpret_s16_u16(svunpkhi(vsrc1_u8)); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 179 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 180 | svst1_s16(pg_0, output_ptr + x, svqadd(vsrc0_0, vsrc1_0)); |
Sang-Hoon Park | 32e0646 | 2021-03-23 15:34:04 +0000 | [diff] [blame] | 181 | svst1_s16(pg_1, output_ptr + x + svcnth(), svqadd(vsrc0_1, vsrc1_1)); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 182 | |
Sang-Hoon Park | 32e0646 | 2021-03-23 15:34:04 +0000 | [diff] [blame] | 183 | x += svcntb(); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 184 | pg_u = svwhilelt_b8(x, window_end_x); |
| 185 | pg_0 = svwhilelt_b16(x, window_end_x); |
| 186 | pg_1 = svwhilelt_b16(x + static_cast<int>(svcnth()), window_end_x); |
| 187 | } |
| 188 | while(svptest_any(all_true_pg, pg_u)); |
| 189 | } |
| 190 | }, |
| 191 | input1, input2, output); |
| 192 | } |
| 193 | |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 194 | void add_u8_s16_s16_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] | 195 | { |
| 196 | // Simply swap the two input buffers: |
Sheri Zhang | 6124390 | 2021-01-12 18:25:16 +0000 | [diff] [blame] | 197 | add_s16_u8_s16_sve(src1, src0, dst, policy, window); |
Michalis Spyrou | a3c9a3b | 2020-12-08 21:02:16 +0000 | [diff] [blame] | 198 | } |
| 199 | } // namespace cpu |
| 200 | } // namespace arm_compute |
| 201 | #endif /* defined(__ARM_FEATURE_SVE) */ |