Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +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 | */ |
| 24 | #include "arm_gemm.hpp" |
| 25 | #include "gemm_common.hpp" |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 26 | #include "gemm_hybrid.hpp" |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 27 | #include "gemm_hybrid_indirect.hpp" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 28 | #include "gemm_implementation.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 29 | #include "gemm_interleaved.hpp" |
David Mansell | ce8f605 | 2018-05-17 18:51:26 +0100 | [diff] [blame] | 30 | #include "gemv_batched.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 31 | #include "gemv_pretransposed.hpp" |
| 32 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 33 | #include "kernels/a32_sgemm_8x6.hpp" |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 34 | #include "kernels/a64_gemv_fp32_mla_32.hpp" |
| 35 | #include "kernels/a64_hybrid_fp32_mla_6x16.hpp" |
| 36 | #include "kernels/a64_hybrid_fp32_mla_8x4.hpp" |
| 37 | #include "kernels/a64_sgemm_8x12.hpp" |
| 38 | #include "kernels/a64_smallK_hybrid_fp32_mla_6x4.hpp" |
| 39 | #include "kernels/a64_smallK_hybrid_fp32_mla_8x4.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 40 | |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 41 | #include "kernels/sve_gemv_fp32_mla_8VL.hpp" |
| 42 | #include "kernels/sve_hybrid_fp32_mla_6x4VL.hpp" |
| 43 | #include "kernels/sve_hybrid_fp32_mla_8x1VL.hpp" |
| 44 | #include "kernels/sve_interleaved_fp32_mla_8x3VL.hpp" |
| 45 | #include "kernels/sve_interleaved_fp32_mmla_8x3VL.hpp" |
| 46 | #include "kernels/sve_smallK_hybrid_fp32_mla_8x1VL.hpp" |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 47 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 48 | namespace arm_gemm { |
| 49 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 50 | static const GemmImplementation<float, float> gemm_fp32_methods[] = |
| 51 | { |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 52 | // GEMV cases - starting with 'gemv_batched' wrapper to turn batched GEMV into GEMM. |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 53 | { |
| 54 | GemmMethod::GEMV_BATCHED, |
| 55 | "gemv_batched", |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 56 | [](const GemmArgs &args) { return args._Msize==1 && args._nbatches>1 && !args._indirect_input; }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 57 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 58 | [](const GemmArgs &args) { return new GemvBatched<float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 59 | }, |
| 60 | #ifdef __aarch64__ |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 61 | #ifdef __ARM_FEATURE_SVE |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 62 | { |
| 63 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 64 | "sve_gemv_fp32_mla_8VL", |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 65 | [](const GemmArgs &args) { return args._ci->has_sve() && args._Msize==1 && args._nbatches==1 && !args._indirect_input; }, |
| 66 | [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN; }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 67 | [](const GemmArgs &args) { return new GemvPretransposed<cls_sve_gemv_fp32_mla_8VL, float, float>(args); } |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 68 | }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 69 | #endif |
| 70 | { |
| 71 | GemmMethod::GEMM_HYBRID, |
| 72 | "a64_gemv_fp32_mla_32", |
| 73 | [](const GemmArgs &args) { return args._Msize==1 && args._nbatches==1 && !args._indirect_input; }, |
| 74 | nullptr, |
| 75 | [](const GemmArgs &args) { return new GemvPretransposed<cls_a64_gemv_fp32_mla_32, float, float>(args); } |
| 76 | }, |
| 77 | |
| 78 | // MMLA next due to higher throughput (SVE only) |
| 79 | #if defined(__ARM_FEATURE_SVE) && defined(MMLA_FP32) |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 80 | { |
| 81 | GemmMethod::GEMM_INTERLEAVED, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 82 | "sve_interleaved_fp32_mmla_8x3VL", |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 83 | [](const GemmArgs &args) { return args._ci->has_sve() && (args._Ksize>4); }, |
| 84 | [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN; }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 85 | [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_fp32_mmla_8x3VL, float, float>(args); } |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 86 | }, |
| 87 | #endif // __ARM_FEATURE_SVE && MMLA_FP32 |
| 88 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 89 | #ifdef __ARM_FEATURE_SVE |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 90 | // SVE smallk / hybrid methods |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 91 | { |
| 92 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 93 | "sve_smallK_hybrid_fp32_mla_8x1VL", |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 94 | [](const GemmArgs &args) { return args._ci->has_sve() && args._Ksize <= 24 && !args._indirect_input; }, |
| 95 | [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN; }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 96 | [](const GemmArgs &args) { return new GemmHybrid<cls_sve_smallK_hybrid_fp32_mla_8x1VL, float, float>(args); } |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 97 | }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 98 | { |
| 99 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 100 | "sve_hybrid_fp32_mla_8x1VL", |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 101 | [](const GemmArgs &args) { return args._ci->has_sve(); }, |
| 102 | [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN && (args._Nsize < 12); }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 103 | [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_fp32_mla_8x1VL, float, float>(args); } |
| 104 | }, |
| 105 | { |
| 106 | GemmMethod::GEMM_HYBRID, |
| 107 | "sve_hybrid_fp32_mla_6x4VL", |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 108 | [](const GemmArgs &args) { return args._ci->has_sve(); }, |
| 109 | [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN && (((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8))); }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 110 | [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_fp32_mla_6x4VL, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 111 | }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 112 | #endif // __ARM_FEATURE_SVE |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 113 | |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 114 | // Neon hybrid methods |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 115 | { |
| 116 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 117 | "a64_smallK_hybrid_fp32_mla_8x4", |
| 118 | [](const GemmArgs &args) { return args._Ksize <= 8 && (args._Nsize % 4)==0 && !args._indirect_input; }, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 119 | nullptr, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 120 | [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_fp32_mla_8x4, float, float>(args); } |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 121 | }, |
| 122 | { |
| 123 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 124 | "a64_smallK_hybrid_fp32_mla_6x4", |
| 125 | [](const GemmArgs &args) { return (args._Ksize > 8 && args._Ksize <= 16) && (args._Nsize % 4)==0 && !args._indirect_input; }, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 126 | nullptr, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 127 | [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_fp32_mla_6x4, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 128 | }, |
| 129 | { |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 130 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 131 | "a64_hybrid_fp32_mla_8x4", |
| 132 | nullptr, |
Michalis Spyrou | 71ac903 | 2019-11-14 14:31:44 +0000 | [diff] [blame] | 133 | [](const GemmArgs &args) { return (args._Nsize < 12); }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 134 | [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp32_mla_8x4, float, float>(args); } |
Michalis Spyrou | 71ac903 | 2019-11-14 14:31:44 +0000 | [diff] [blame] | 135 | }, |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 136 | GemmImplementation<float, float>::with_estimate( |
Michalis Spyrou | 71ac903 | 2019-11-14 14:31:44 +0000 | [diff] [blame] | 137 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 138 | "a64_hybrid_fp32_mla_6x16", |
| 139 | nullptr, |
| 140 | [](const GemmArgs &args) { return GemmHybridIndirect<cls_a64_hybrid_fp32_mla_6x16, float, float>::estimate_cycles(args, cls_a64_hybrid_fp32_mla_6x16::get_performance_parameters(args._ci)); }, |
| 141 | [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp32_mla_6x16, float, float>(args); } |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 142 | ), |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 143 | #ifdef __ARM_FEATURE_SVE |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 144 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 145 | GemmMethod::GEMM_INTERLEAVED, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 146 | "sve_interleaved_fp32_mla_8x3VL", |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 147 | [](const GemmArgs &args) { return args._ci->has_sve() && (args._Ksize>4); }, |
| 148 | [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN; }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 149 | [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_fp32_mla_8x3VL, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 150 | }, |
| 151 | #endif // __ARM_FEATURE_SVE |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 152 | GemmImplementation<float, float>::with_estimate( |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 153 | GemmMethod::GEMM_INTERLEAVED, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 154 | "a64_sgemm_8x12", |
Gian Marco Iodice | 463f976 | 2020-05-19 14:12:27 +0100 | [diff] [blame] | 155 | nullptr, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 156 | [](const GemmArgs &args) { return GemmInterleaved<cls_a64_sgemm_8x12, float, float>::estimate_cycles(args, cls_a64_sgemm_8x12::get_performance_parameters(args._ci)); }, |
| 157 | [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_sgemm_8x12, float, float>(args); } |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 158 | ), |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 159 | #endif // __aarch64__ |
| 160 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 161 | #ifdef __arm__ |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 162 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 163 | GemmMethod::GEMM_INTERLEAVED, |
| 164 | "sgemm_8x6", |
| 165 | nullptr, |
| 166 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 167 | [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 168 | }, |
| 169 | #endif // __arm__ |
| 170 | { |
| 171 | GemmMethod::DEFAULT, |
| 172 | "", |
| 173 | nullptr, |
| 174 | nullptr, |
| 175 | nullptr |
| 176 | } |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | /* Templated function to return this list. */ |
| 180 | template<> |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 181 | const GemmImplementation<float, float> *gemm_implementation_list<float, float>() { |
| 182 | return gemm_fp32_methods; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 183 | } |
| 184 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 185 | /* Explicitly instantiate the external functions for these types. */ |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 186 | template UniqueGemmCommon<float, float> gemm<float, float, Nothing>(const GemmArgs &args, const Nothing &); |
| 187 | template KernelDescription get_gemm_method<float, float, Nothing>(const GemmArgs &args, const Nothing &); |
| 188 | template std::vector<KernelDescription> get_compatible_kernels<float, float, Nothing> (const GemmArgs &args, const Nothing &); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 189 | |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 190 | } // namespace arm_gemm |