Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 1 | /* |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2019-2021, 2023 Arm Limited. |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +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 | * |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 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 |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 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. |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 23 | */ |
| 24 | #pragma once |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 25 | #ifdef __aarch64__ |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 26 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 27 | #include "../std_transforms_fixed.hpp" |
Georgios Pinitas | 33e0307 | 2021-01-14 13:43:40 +0000 | [diff] [blame] | 28 | #include "../performance_parameters.hpp" |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 29 | |
| 30 | #define ARGLIST \ |
Georgios Pinitas | 33e0307 | 2021-01-14 13:43:40 +0000 | [diff] [blame] | 31 | unsigned int, const unsigned int *, \ |
| 32 | IndirectInputArg<int8_t>, \ |
| 33 | size_t, size_t, \ |
| 34 | const int8_t *, \ |
| 35 | IndirectOutputArg<int32_t>, \ |
| 36 | const int32_t *, Activation, bool |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 37 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 38 | namespace arm_gemm |
| 39 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 40 | // Actual kernel implementations |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 41 | void a64_hybrid_s8s32_dot_6x16( ARGLIST ); |
Georgios Pinitas | e28cf39 | 2021-01-31 05:18:43 +0000 | [diff] [blame] | 42 | void a64_hybrid_s8s32_dot_6x16_a55( ARGLIST ); |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 43 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 44 | class cls_a64_hybrid_s8s32_dot_6x16 |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 45 | { |
| 46 | public: |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 47 | typedef int8_t lhs_operand_type; |
| 48 | typedef int8_t rhs_operand_type; |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 49 | typedef int32_t result_type; |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 50 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 51 | typedef void (*kern_type)( ARGLIST ); |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 52 | |
| 53 | /* Kernel blocking parameters */ |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 54 | static constexpr unsigned int out_height() |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 55 | { |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 56 | return 6; |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 59 | static unsigned int out_width() |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 60 | { |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 61 | return 16; |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 64 | static constexpr unsigned int k_unroll() |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 65 | { |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 66 | return 4; |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 69 | static constexpr bool supports_accumulate() |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 70 | { |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 71 | return true; |
| 72 | } |
| 73 | |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 74 | StdTransformsFixed<rhs_operand_type, result_type, 6, 16, 4> transforms = {}; |
| 75 | template<typename T> |
| 76 | static inline PerformanceParameters get_performance_parameters(const CPUInfo *ci) |
Georgios Pinitas | e28cf39 | 2021-01-31 05:18:43 +0000 | [diff] [blame] | 77 | { |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 78 | if (std::is_same<T, int32_t>::value) { |
| 79 | switch (ci->get_cpu_model()) { |
| 80 | default: |
| 81 | return { 31.65 }; |
| 82 | case CPUModel::A510: |
| 83 | return { 15.87 }; |
| 84 | case CPUModel::V1: |
| 85 | return { 54.50 }; |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 86 | case CPUModel::A55r1: |
| 87 | return { 9.217 }; |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 88 | } |
Georgios Pinitas | 33e0307 | 2021-01-14 13:43:40 +0000 | [diff] [blame] | 89 | } |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 90 | |
| 91 | if (std::is_same<T, int8_t>::value) { |
| 92 | switch (ci->get_cpu_model()) { |
| 93 | case CPUModel::A55r1: |
| 94 | return { 9.5238, 2.0799, 0.2279 }; |
| 95 | default: |
| 96 | return { 29.6736, 11.4025, 0.5591 }; |
| 97 | case CPUModel::A510: |
| 98 | return { 16.66, 3.92, 0.48 }; |
| 99 | case CPUModel::V1: |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 100 | return { 42.62, 16.32, 0.83 }; |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | return { 1.0 }; |
Georgios Pinitas | 33e0307 | 2021-01-14 13:43:40 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 107 | // Default to the generic kernel |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 108 | kern_type kernel=a64_hybrid_s8s32_dot_6x16; |
Georgios Pinitas | e28cf39 | 2021-01-31 05:18:43 +0000 | [diff] [blame] | 109 | cls_a64_hybrid_s8s32_dot_6x16(const CPUInfo *ci) |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 110 | { |
Georgios Pinitas | e28cf39 | 2021-01-31 05:18:43 +0000 | [diff] [blame] | 111 | switch(ci->get_cpu_model()) { |
| 112 | default: |
| 113 | break; |
| 114 | case CPUModel::A55r1: |
| 115 | kernel=a64_hybrid_s8s32_dot_6x16_a55; |
| 116 | break; |
| 117 | } |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 118 | } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | } // namespace arm_gemm |
| 122 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 123 | #undef ARGLIST |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 124 | #endif // __aarch64__ |