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" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 27 | #include "gemm_implementation.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 28 | #include "gemm_interleaved.hpp" |
Joseph Dobson | 6f8b17d | 2020-02-11 19:32:11 +0000 | [diff] [blame] | 29 | #include "gemm_interleaved_pretransposed_2d.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 | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 34 | #include "kernels/a64_hybrid_fp32_mla_16x4.hpp" |
Michalis Spyrou | 71ac903 | 2019-11-14 14:31:44 +0000 | [diff] [blame] | 35 | #include "kernels/a64_hybrid_fp32_mla_4x8.hpp" |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 36 | #include "kernels/a64_smallK_hybrid_fp32_mla_4x6.hpp" |
| 37 | #include "kernels/a64_smallK_hybrid_fp32_mla_4x8.hpp" |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 38 | #include "kernels/a64_sgemm_12x8.hpp" |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 39 | #include "kernels/a64_sgemv_pretransposed.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 40 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 41 | #include "kernels/sve_hybrid_fp32_mla_4VLx4.hpp" |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 42 | #include "kernels/sve_hybrid_fp32_mmla_4VLx4.hpp" |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 43 | #include "kernels/sve_interleaved_fp32_mla_3VLx8.hpp" |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 44 | #include "kernels/sve_interleaved_fp32_mmla_3VLx8.hpp" |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 45 | #include "kernels/sve_smallK_hybrid_fp32_mla_1VLx8.hpp" |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 46 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 47 | namespace arm_gemm { |
| 48 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 49 | static const GemmImplementation<float, float> gemm_fp32_methods[] = |
| 50 | { |
| 51 | { |
| 52 | GemmMethod::GEMV_BATCHED, |
| 53 | "gemv_batched", |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 54 | [](const GemmArgs &args) { return (args._Msize==1) && (args._nbatches>1); }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 55 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 56 | [](const GemmArgs &args) { return new GemvBatched<float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 57 | }, |
| 58 | #ifdef __aarch64__ |
| 59 | { |
| 60 | GemmMethod::GEMV_PRETRANSPOSED, |
| 61 | "sgemv_pretransposed", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 62 | [](const GemmArgs &args) { return (args._Msize==1 && args._nbatches==1); }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 63 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 64 | [](const GemmArgs &args) { return new GemvPretransposed<sgemv_pretransposed, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 65 | }, |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 66 | #if defined(__ARM_FEATURE_SVE) && defined(MMLA_FP32) |
| 67 | { |
| 68 | GemmMethod::GEMM_HYBRID, |
| 69 | "hybrid_fp32_mmla_4VLx4", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 70 | [](const GemmArgs &args) { return (args._Ksize >= 4); }, |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 71 | [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); }, |
| 72 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mmla_4VLx4, float, float>(args); } |
| 73 | }, |
| 74 | { |
| 75 | GemmMethod::GEMM_INTERLEAVED, |
| 76 | "interleaved_fp32_mmla_3VLx8", |
| 77 | [](const GemmArgs &args) { return (args._Ksize>4); }, |
| 78 | nullptr, |
| 79 | [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp32_mmla_3VLx8, float, float>(args); } |
| 80 | }, |
| 81 | #endif // __ARM_FEATURE_SVE && MMLA_FP32 |
| 82 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 83 | #ifdef __ARM_FEATURE_SVE |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 84 | // SVE smallk / hybrid methods |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 85 | { |
| 86 | GemmMethod::GEMM_HYBRID, |
| 87 | "smallK_hybrid_fp32_mla_1VLx8", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 88 | [](const GemmArgs &args) { return (args._Ksize <= 24); }, |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 89 | nullptr, |
| 90 | [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_1VLx8, float, float>(args); } |
| 91 | }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 92 | { |
| 93 | GemmMethod::GEMM_HYBRID, |
| 94 | "hybrid_fp32_mla_4VLx4", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 95 | [](const GemmArgs &args) { return (args._Ksize >= 4); }, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 96 | [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); }, |
| 97 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4VLx4, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 98 | }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 99 | #endif // __ARM_FEATURE_SVE |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 100 | |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 101 | // NEON hybrid methods |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 102 | { |
| 103 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 104 | "smallK_hybrid_fp32_mla_4x8", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 105 | [](const GemmArgs &args) { return (args._Ksize <= 8) && (args._Nsize % 4)==0; }, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 106 | nullptr, |
| 107 | [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x8, float, float>(args); } |
| 108 | }, |
| 109 | { |
| 110 | GemmMethod::GEMM_HYBRID, |
| 111 | "smallK_hybrid_fp32_mla_4x6", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 112 | [](const GemmArgs &args) { return (args._Ksize > 8) && (args._Ksize <= 16) && (args._Nsize % 4)==0; }, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 113 | nullptr, |
| 114 | [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x6, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 115 | }, |
| 116 | { |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 117 | GemmMethod::GEMM_HYBRID, |
Michalis Spyrou | 71ac903 | 2019-11-14 14:31:44 +0000 | [diff] [blame] | 118 | "hybrid_fp32_mla_4x8_normal", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 119 | [](const GemmArgs &args) { return (args._Ksize >= 4); }, |
Michalis Spyrou | 71ac903 | 2019-11-14 14:31:44 +0000 | [diff] [blame] | 120 | [](const GemmArgs &args) { return (args._Nsize < 12); }, |
| 121 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4x8, float, float>(args); } |
| 122 | }, |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 123 | GemmImplementation<float, float>::with_estimate( |
Michalis Spyrou | 71ac903 | 2019-11-14 14:31:44 +0000 | [diff] [blame] | 124 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 125 | "hybrid_fp32_mla_16x4", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 126 | [](const GemmArgs &args) { return (args._Ksize >= 4); }, |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 127 | [](const GemmArgs &args) { return GemmHybrid<hybrid_fp32_mla_16x4, float, float>::estimate_cycles(args, hybrid_fp32_mla_16x4::get_performance_parameters(args._ci)); }, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 128 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_16x4, float, float>(args); } |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 129 | ), |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 130 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 131 | #ifdef __ARM_FEATURE_SVE |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 132 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 133 | GemmMethod::GEMM_INTERLEAVED, |
| 134 | "interleaved_fp32_mla_3VLx8", |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 135 | [](const GemmArgs &args) { return (args._Ksize>4); }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 136 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 137 | [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp32_mla_3VLx8, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 138 | }, |
| 139 | #endif // __ARM_FEATURE_SVE |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 140 | // Pretranposed, 2D split |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 141 | GemmImplementation<float, float>::with_estimate( |
Joseph Dobson | 6f8b17d | 2020-02-11 19:32:11 +0000 | [diff] [blame] | 142 | GemmMethod::GEMM_INTERLEAVED_2D, |
Gian Marco Iodice | 463f976 | 2020-05-19 14:12:27 +0100 | [diff] [blame] | 143 | "sgemm_12x8_2d", |
| 144 | nullptr, |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 145 | [](const GemmArgs &args) { return GemmInterleavedPretransposed2d<sgemm_12x8, float, float>::estimate_cycles(args, sgemm_12x8::get_performance_parameters(args._ci)); }, |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 146 | [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<sgemm_12x8, float, float>(args); } |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 147 | ), |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 148 | // 1D split (with pretransposed or not) |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 149 | GemmImplementation<float, float>::with_estimate( |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 150 | GemmMethod::GEMM_INTERLEAVED, |
Gian Marco Iodice | 463f976 | 2020-05-19 14:12:27 +0100 | [diff] [blame] | 151 | "sgemm_12x8_1d", |
| 152 | nullptr, |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 153 | [](const GemmArgs &args) { return GemmInterleaved<sgemm_12x8, float, float>::estimate_cycles(args, sgemm_12x8::get_performance_parameters(args._ci)); }, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 154 | [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, float, float>(args); } |
David Mansell | 318c9f4 | 2020-07-08 13:28:45 +0100 | [diff] [blame] | 155 | ), |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 156 | #endif // __aarch64__ |
| 157 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 158 | #ifdef __arm__ |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 159 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 160 | GemmMethod::GEMM_INTERLEAVED, |
| 161 | "sgemm_8x6", |
| 162 | nullptr, |
| 163 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 164 | [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, float, float>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 165 | }, |
| 166 | #endif // __arm__ |
| 167 | { |
| 168 | GemmMethod::DEFAULT, |
| 169 | "", |
| 170 | nullptr, |
| 171 | nullptr, |
| 172 | nullptr |
| 173 | } |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | /* Templated function to return this list. */ |
| 177 | template<> |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 178 | const GemmImplementation<float, float> *gemm_implementation_list<float, float>() { |
| 179 | return gemm_fp32_methods; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 180 | } |
| 181 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 182 | /* Explicitly instantiate the external functions for these types. */ |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 183 | template UniqueGemmCommon<float, float> gemm<float, float, Nothing>(const GemmArgs &args, const Nothing &); |
| 184 | template KernelDescription get_gemm_method<float, float, Nothing>(const GemmArgs &args, const Nothing &); |
| 185 | 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] | 186 | |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 187 | } // namespace arm_gemm |