Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +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" |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 25 | #include "bfloat.hpp" |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 26 | #include "gemm_common.hpp" |
| 27 | #include "gemm_hybrid.hpp" |
| 28 | #include "gemm_implementation.hpp" |
| 29 | #include "gemm_interleaved.hpp" |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 30 | #include "gemv_batched.hpp" |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 31 | #include "gemv_pretransposed.hpp" |
| 32 | |
| 33 | #include "kernels/a64_interleaved_bf16fp32_dot_12x8.hpp" |
| 34 | #include "kernels/a64_interleaved_bf16fp32_mmla_12x8.hpp" |
| 35 | #include "kernels/a64_sgemm_12x8.hpp" |
| 36 | #include "kernels/a32_sgemm_8x6.hpp" |
| 37 | #include "kernels/sve_interleaved_bf16fp32_dot_3VLx8.hpp" |
| 38 | #include "kernels/sve_interleaved_bf16fp32_mmla_3VLx8.hpp" |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 39 | #include "kernels/sve_hybrid_bf16fp32_dot_4VLx4.hpp" |
| 40 | #include "kernels/sve_hybrid_bf16fp32_mmla_4VLx4.hpp" |
| 41 | #include "kernels/sve_hybrid_bf16fp32_mmla_6VLx2.hpp" |
| 42 | #include "kernels/sve_hybrid_bf16fp32_mmla_8VLx2.hpp" |
| 43 | |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 44 | namespace arm_gemm { |
| 45 | |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 46 | static const GemmImplementation<bfloat16, float> gemm_bf16_methods[] = |
| 47 | { |
| 48 | #ifdef V8P6_BF |
| 49 | # ifdef __ARM_FEATURE_SVE |
| 50 | { |
| 51 | GemmMethod::GEMM_HYBRID, |
| 52 | "hybrid_bf16fp32_mmla_6VLx2", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 53 | [](const GemmArgs &args) { return (args._Ksize>=8); }, |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 54 | [](const GemmArgs &args) { return ((args._Msize <= 4) && (args._Nsize <= hybrid_bf16fp32_mmla_6VLx2::out_width())); }, |
| 55 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_bf16fp32_mmla_6VLx2, bfloat16, float>(args); } |
| 56 | }, |
| 57 | { |
| 58 | GemmMethod::GEMM_HYBRID, |
| 59 | "hybrid_bf16fp32_mmla_8VLx2", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 60 | [](const GemmArgs &args) { return (args._Ksize>=8); }, |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 61 | [](const GemmArgs &args) { return (args._Msize <= 4); }, |
| 62 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_bf16fp32_mmla_8VLx2, bfloat16, float>(args); } |
| 63 | }, |
| 64 | { |
| 65 | GemmMethod::GEMM_HYBRID, |
| 66 | "hybrid_bf16fp32_mmla_4VLx4", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 67 | [](const GemmArgs &args) { return (args._Ksize>=8); }, |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 68 | [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)); }, |
| 69 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_bf16fp32_mmla_4VLx4, bfloat16, float>(args); } |
| 70 | }, |
| 71 | { |
| 72 | GemmMethod::GEMM_HYBRID, |
| 73 | "hybrid_bf16fp32_dot_4VLx4", |
Georgios Pinitas | 0cc50ed | 2020-07-06 19:10:38 +0100 | [diff] [blame] | 74 | [](const GemmArgs &args) { return (args._Ksize>=8); }, |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 75 | [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)); }, |
| 76 | [](const GemmArgs &args) { return new GemmHybrid<hybrid_bf16fp32_dot_4VLx4, bfloat16, float>(args); } |
| 77 | }, |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 78 | { // gemm_bf16_interleaved |
| 79 | GemmMethod::GEMM_INTERLEAVED, |
| 80 | "interleaved_bf16fp32_mmla_3VLx8", |
| 81 | [](const GemmArgs &args) { return (args._Ksize>4); }, |
| 82 | nullptr, |
| 83 | [](const GemmArgs &args) { return new GemmInterleaved<interleaved_bf16fp32_mmla_3VLx8, bfloat16, float>(args); } |
| 84 | }, |
| 85 | { // gemm_bf16_interleaved |
| 86 | GemmMethod::GEMM_INTERLEAVED, |
| 87 | "interleaved_bf16fp32_dot_3VLx8", |
| 88 | [](const GemmArgs &args) { return (args._Ksize>2); }, |
| 89 | nullptr, |
| 90 | [](const GemmArgs &args) { return new GemmInterleaved<interleaved_bf16fp32_dot_3VLx8, bfloat16, float>(args); } |
| 91 | }, |
| 92 | # endif // SVE |
| 93 | { // gemm_bf16_interleaved |
| 94 | GemmMethod::GEMM_INTERLEAVED, |
| 95 | "interleaved_bf16fp32_mmla_12x8", |
| 96 | [](const GemmArgs &args) { return (args._Ksize>4); }, |
| 97 | nullptr, |
| 98 | [](const GemmArgs &args) { return new GemmInterleaved<interleaved_bf16fp32_mmla_12x8, bfloat16, float>(args); } |
| 99 | }, |
| 100 | { // gemm_bf16_interleaved |
| 101 | GemmMethod::GEMM_INTERLEAVED, |
| 102 | "interleaved_bf16fp32_dot_12x8", |
| 103 | [](const GemmArgs &args) { return (args._Ksize>2); }, |
| 104 | nullptr, |
| 105 | [](const GemmArgs &args) { return new GemmInterleaved<interleaved_bf16fp32_dot_12x8, bfloat16, float>(args); } |
| 106 | }, |
| 107 | #endif // V8P6_BF |
| 108 | #ifdef __aarch64__ |
| 109 | { |
| 110 | GemmMethod::GEMM_INTERLEAVED, |
| 111 | "sgemm_12x8", |
| 112 | nullptr, |
| 113 | nullptr, |
| 114 | [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, bfloat16, float>(args); } |
| 115 | }, |
| 116 | #elif defined(__arm__) |
| 117 | { |
| 118 | GemmMethod::GEMM_INTERLEAVED, |
| 119 | "sgemm_8x6", |
| 120 | nullptr, |
| 121 | nullptr, |
| 122 | [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, bfloat16, float>(args); } |
| 123 | }, |
| 124 | #else |
| 125 | # error "Unknown Architecture" |
| 126 | #endif |
| 127 | { |
| 128 | GemmMethod::DEFAULT, |
| 129 | "", |
| 130 | nullptr, |
| 131 | nullptr, |
| 132 | nullptr |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | template<> |
| 137 | const GemmImplementation<bfloat16, float> *gemm_implementation_list<bfloat16, float>() { |
| 138 | return gemm_bf16_methods; |
| 139 | } |
| 140 | |
| 141 | /* Explicitly instantiate the external functions for these types. */ |
| 142 | template UniqueGemmCommon<bfloat16, float> gemm<bfloat16, float, Nothing>(const GemmArgs &args, const Nothing &); |
| 143 | template KernelDescription get_gemm_method<bfloat16, float, Nothing>(const GemmArgs &args, const Nothing &); |
| 144 | template std::vector<KernelDescription> get_compatible_kernels<bfloat16, float, Nothing>(const GemmArgs &args, const Nothing &); |
| 145 | |
| 146 | } // namespace arm_gemm |