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 | */ |
Pablo Tello | 99ef840 | 2018-03-20 16:46:55 +0000 | [diff] [blame] | 24 | |
| 25 | // This can only be built if the target/compiler supports FP16 arguments. |
| 26 | #ifdef __ARM_FP16_ARGS |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 27 | |
| 28 | #include "arm_gemm.hpp" |
| 29 | |
| 30 | #include "gemm_common.hpp" |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 31 | #include "gemm_hybrid.hpp" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 32 | #include "gemm_implementation.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 33 | #include "gemm_interleaved.hpp" |
cfRod | 534fdea | 2020-06-25 18:12:25 +0100 | [diff] [blame^] | 34 | #include "gemm_interleaved_pretransposed_2d.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 35 | |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 36 | #include "kernels/a32_sgemm_8x6.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 37 | #include "kernels/a64_hgemm_24x8.hpp" |
| 38 | #include "kernels/a64_sgemm_12x8.hpp" |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 39 | #include "kernels/sve_hybrid_fp16_mla_4VLx4.hpp" |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 40 | #include "kernels/sve_interleaved_fp16_mla_3VLx8.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 41 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 42 | namespace arm_gemm { |
| 43 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 44 | static const GemmImplementation<__fp16, __fp16> gemm_fp16_methods[] = { |
| 45 | #if defined(__ARM_FEATURE_SVE) |
| 46 | { |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 47 | GemmMethod::GEMM_HYBRID, |
| 48 | "hybrid_fp16_mla_4VLx4", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 49 | [](const GemmArgs &args) { return (args._Ksize >= 8); }, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 50 | [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); }, |
| 51 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp16_mla_4VLx4, __fp16, __fp16>(args); } |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 52 | }, |
| 53 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 54 | GemmMethod::GEMM_INTERLEAVED, |
| 55 | "interleaved_fp16_mla_3VLx8", |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 56 | [](const GemmArgs &args) { return (args._Ksize > 4); }, |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 57 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 58 | [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp16_mla_3VLx8, __fp16, __fp16>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 59 | }, |
| 60 | #endif |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 61 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 62 | #if defined(__aarch64__) && (defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) || defined(FP16_KERNELS)) |
| 63 | { |
cfRod | 534fdea | 2020-06-25 18:12:25 +0100 | [diff] [blame^] | 64 | GemmMethod::GEMM_INTERLEAVED_2D, |
| 65 | "hgemm_24x8_2d", |
| 66 | #ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 67 | [](const GemmArgs &args) { return args._ci->has_fp16(); }, |
| 68 | #else |
| 69 | nullptr, |
| 70 | #endif |
| 71 | [](const GemmArgs &args) { return args._maxthreads >= 8; }, |
| 72 | [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<hgemm_24x8, __fp16, __fp16>(args); } |
| 73 | }, |
| 74 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 75 | GemmMethod::GEMM_INTERLEAVED, |
cfRod | 534fdea | 2020-06-25 18:12:25 +0100 | [diff] [blame^] | 76 | "hgemm_24x8_1d", |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 77 | #ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 78 | [](const GemmArgs &args) { return args._ci->has_fp16(); }, |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 79 | #else |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 80 | nullptr, |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 81 | #endif |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 82 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 83 | [](const GemmArgs &args) { return new GemmInterleaved<hgemm_24x8, __fp16, __fp16>(args); } |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 84 | }, |
cfRod | 534fdea | 2020-06-25 18:12:25 +0100 | [diff] [blame^] | 85 | |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 86 | #endif // aarch64 && FP16 |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 87 | #ifdef __aarch64__ |
cfRod | 534fdea | 2020-06-25 18:12:25 +0100 | [diff] [blame^] | 88 | //Pretranpose, 2D split |
| 89 | { |
| 90 | GemmMethod::GEMM_INTERLEAVED_2D, |
| 91 | "sgemm_12x8_2d", |
| 92 | nullptr, |
| 93 | [](const GemmArgs &args) { return args._maxthreads >= 8; }, |
| 94 | [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<sgemm_12x8, __fp16, __fp16>(args); } |
| 95 | }, |
| 96 | //Tranpose, 1D split, with blockmanager |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 97 | { |
| 98 | GemmMethod::GEMM_INTERLEAVED, |
cfRod | 534fdea | 2020-06-25 18:12:25 +0100 | [diff] [blame^] | 99 | "sgemm_12x8_1d", |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 100 | nullptr, |
| 101 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 102 | [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, __fp16, __fp16>(args); } |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 103 | }, |
| 104 | #elif defined(__arm__) |
Georgios Pinitas | a41c54b | 2019-01-30 18:16:43 +0000 | [diff] [blame] | 105 | { |
| 106 | GemmMethod::GEMM_INTERLEAVED, |
| 107 | "sgemm_8x6", |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 108 | nullptr, |
| 109 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 110 | [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, __fp16, __fp16>(args); } |
Georgios Pinitas | a41c54b | 2019-01-30 18:16:43 +0000 | [diff] [blame] | 111 | }, |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 112 | #else // not AArch64 or AArch32 |
| 113 | # error Unknown Architecture |
Georgios Pinitas | a41c54b | 2019-01-30 18:16:43 +0000 | [diff] [blame] | 114 | #endif |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 115 | { |
| 116 | GemmMethod::DEFAULT, |
| 117 | "", |
| 118 | nullptr, |
| 119 | nullptr, |
| 120 | nullptr, |
| 121 | } |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | template<> |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 125 | const GemmImplementation<__fp16, __fp16> *gemm_implementation_list<__fp16, __fp16>() { |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 126 | return gemm_fp16_methods; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 127 | } |
| 128 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 129 | /* Explicitly instantiate the external functions for these types. */ |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 130 | template UniqueGemmCommon<__fp16, __fp16> gemm<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &); |
| 131 | template KernelDescription get_gemm_method<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &); |
| 132 | template std::vector<KernelDescription> get_compatible_kernels<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &); |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 133 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 134 | } // namespace arm_gemm |
| 135 | |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 136 | #endif // __ARM_FP16_ARGS |