Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 1 | /* |
Francesco.Petrogalli@arm.com | 193cad3 | 2022-03-07 13:39:21 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, 2022 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. |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 26 | #if defined(__aarch64__) && (defined(FP16_KERNELS) || defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)) |
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" |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 32 | #include "gemm_hybrid_indirect.hpp" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 33 | #include "gemm_implementation.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 34 | #include "gemm_interleaved.hpp" |
| 35 | |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 36 | #include "kernels/a32_sgemm_8x6.hpp" |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 37 | #ifdef ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
Francesco.Petrogalli@arm.com | 5fcf22d | 2022-04-05 10:31:08 +0000 | [diff] [blame] | 38 | #include "kernels/a64_ffhybrid_fp16_mla_6x32.hpp" |
| 39 | #include "kernels/a64_ffinterleaved_fp16_mla_8x24.hpp" |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 40 | #endif // ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 41 | #include "kernels/a64_hgemm_8x24.hpp" |
| 42 | #include "kernels/a64_hybrid_fp16_mla_6x32.hpp" |
| 43 | #include "kernels/a64_sgemm_8x12.hpp" |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 44 | #ifdef ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
Francesco.Petrogalli@arm.com | 5fcf22d | 2022-04-05 10:31:08 +0000 | [diff] [blame] | 45 | #include "kernels/sve_ffhybrid_fp16_mla_6x4VL.hpp" |
| 46 | #include "kernels/sve_ffinterleaved_fp16_mla_8x3VL.hpp" |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 47 | #endif // ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 48 | #include "kernels/sve_hybrid_fp16_mla_6x4VL.hpp" |
| 49 | #include "kernels/sve_interleaved_fp16_mla_8x3VL.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 50 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 51 | namespace arm_gemm { |
| 52 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 53 | static const GemmImplementation<__fp16, __fp16> gemm_fp16_methods[] = { |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 54 | #ifdef ARM_COMPUTE_ENABLE_SVE |
| 55 | GemmImplementation<__fp16, __fp16>::with_estimate( |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 56 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 57 | "sve_hybrid_fp16_mla_6x4VL", |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 58 | [](const GemmArgs &args) { return args._ci->has_sve(); }, |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 59 | [](const GemmArgs &args) { return GemmHybridIndirect<cls_sve_hybrid_fp16_mla_6x4VL, __fp16, __fp16>::estimate_cycles<__fp16>(args); }, |
| 60 | [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_fp16_mla_6x4VL, __fp16, __fp16>(args); } |
| 61 | ), |
| 62 | GemmImplementation<__fp16, __fp16>::with_estimate( |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 63 | GemmMethod::GEMM_INTERLEAVED, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 64 | "sve_interleaved_fp16_mla_8x3VL", |
Pablo Marquez Tello | a50f193 | 2021-03-08 17:27:05 +0000 | [diff] [blame] | 65 | [](const GemmArgs &args) { return args._ci->has_sve() && (args._Ksize > 4); }, |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 66 | [](const GemmArgs &args) { return GemmInterleaved<cls_sve_interleaved_fp16_mla_8x3VL, __fp16, __fp16>::estimate_cycles<__fp16>(args); }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 67 | [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_fp16_mla_8x3VL, __fp16, __fp16>(args); } |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 68 | ), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 69 | #ifdef ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
Francesco.Petrogalli@arm.com | 5fcf22d | 2022-04-05 10:31:08 +0000 | [diff] [blame] | 70 | GemmImplementation<__fp16, __fp16>::with_estimate( |
| 71 | GemmMethod::GEMM_INTERLEAVED, |
| 72 | "sve_ffinterleaved_fp16_mla_8x3VL", |
| 73 | KernelWeightFormat::VL1VL_BL16, |
| 74 | [](const GemmArgs &args) { return args._ci->has_sve(); }, |
| 75 | [](const GemmArgs &args) { return GemmInterleavedFixedFormat<cls_sve_ffinterleaved_fp16_mla_8x3VL, __fp16, __fp16>::estimate_cycles<__fp16>(args); }, |
| 76 | [](const GemmArgs &args) { return new GemmInterleavedFixedFormat<cls_sve_ffinterleaved_fp16_mla_8x3VL, __fp16, __fp16>(args); } |
| 77 | ), |
| 78 | GemmImplementation<__fp16, __fp16>::with_estimate( |
| 79 | GemmMethod::GEMM_HYBRID, |
| 80 | "sve_ffhybrid_fp16_mla_6x4VL", |
| 81 | KernelWeightFormat::VL1VL_BL16, |
| 82 | [](const GemmArgs &args) { return args._ci->has_sve(); }, |
| 83 | [](const GemmArgs &args) { return GemmHybridIndirectFixedFormat<cls_sve_ffhybrid_fp16_mla_6x4VL, __fp16, __fp16>::estimate_cycles<__fp16>(args); }, |
| 84 | [](const GemmArgs &args) { return new GemmHybridIndirectFixedFormat<cls_sve_ffhybrid_fp16_mla_6x4VL, __fp16, __fp16>(args); } |
| 85 | ), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 86 | #endif // ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 87 | #endif // ARM_COMPUTE_ENABLE_SVE |
| 88 | #if defined(__aarch64__) |
Georgios Pinitas | 40943df | 2020-11-17 18:46:40 +0000 | [diff] [blame] | 89 | GemmImplementation<__fp16, __fp16>::with_estimate( |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 90 | GemmMethod::GEMM_HYBRID, |
| 91 | "a64_hybrid_fp16_mla_6x32", |
cfRod | 534fdea | 2020-06-25 18:12:25 +0100 | [diff] [blame] | 92 | [](const GemmArgs &args) { return args._ci->has_fp16(); }, |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 93 | [](const GemmArgs &args) { return GemmHybridIndirect<cls_a64_hybrid_fp16_mla_6x32, __fp16, __fp16>::estimate_cycles<__fp16>(args); }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 94 | [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp16_mla_6x32, __fp16, __fp16>(args); } |
Georgios Pinitas | 40943df | 2020-11-17 18:46:40 +0000 | [diff] [blame] | 95 | ), |
| 96 | GemmImplementation<__fp16, __fp16>::with_estimate( |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 97 | GemmMethod::GEMM_INTERLEAVED, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 98 | "a64_hgemm_8x24", |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 99 | [](const GemmArgs &args) { return args._ci->has_fp16(); }, |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 100 | [](const GemmArgs &args) { return GemmInterleaved<cls_a64_hgemm_8x24, __fp16, __fp16>::estimate_cycles<__fp16>(args); }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 101 | [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_hgemm_8x24, __fp16, __fp16>(args); } |
Georgios Pinitas | 40943df | 2020-11-17 18:46:40 +0000 | [diff] [blame] | 102 | ), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 103 | #ifdef ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
Francesco.Petrogalli@arm.com | 5fcf22d | 2022-04-05 10:31:08 +0000 | [diff] [blame] | 104 | GemmImplementation<__fp16, __fp16>::with_estimate( |
| 105 | GemmMethod::GEMM_INTERLEAVED, |
| 106 | "a64_ffinterleaved_fp16_mla_8x24", |
| 107 | KernelWeightFormat::VL128_BL16, |
| 108 | [](const GemmArgs &args) { return args._ci->has_fp16(); }, |
| 109 | [](const GemmArgs &args) { return GemmInterleavedFixedFormat<cls_a64_ffinterleaved_fp16_mla_8x24, __fp16, __fp16>::estimate_cycles<__fp16>(args); }, |
| 110 | [](const GemmArgs &args) { return new GemmInterleavedFixedFormat<cls_a64_ffinterleaved_fp16_mla_8x24, __fp16, __fp16>(args); } |
| 111 | ), |
| 112 | GemmImplementation<__fp16, __fp16>::with_estimate( |
| 113 | GemmMethod::GEMM_HYBRID, |
| 114 | "a64_ffhybrid_fp16_mla_6x32", |
| 115 | KernelWeightFormat::VL128_BL16, |
| 116 | [](const GemmArgs &args) { return args._ci->has_fp16(); }, |
| 117 | [](const GemmArgs &args) { return GemmHybridIndirectFixedFormat<cls_a64_ffhybrid_fp16_mla_6x32, __fp16, __fp16>::estimate_cycles<__fp16>(args); }, |
| 118 | [](const GemmArgs &args) { return new GemmHybridIndirectFixedFormat<cls_a64_ffhybrid_fp16_mla_6x32, __fp16, __fp16>(args); } |
| 119 | ), |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 120 | #endif // ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 121 | { |
| 122 | GemmMethod::GEMM_INTERLEAVED, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 123 | "a64_sgemm_8x12", |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 124 | nullptr, |
Georgios Pinitas | 40943df | 2020-11-17 18:46:40 +0000 | [diff] [blame] | 125 | [](const GemmArgs &args) { return !args._ci->has_fp16(); }, |
Georgios Pinitas | c0b6f76 | 2020-11-02 01:37:17 +0000 | [diff] [blame] | 126 | [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_sgemm_8x12, __fp16, __fp16>(args); } |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 127 | }, |
| 128 | #elif defined(__arm__) |
Georgios Pinitas | a41c54b | 2019-01-30 18:16:43 +0000 | [diff] [blame] | 129 | { |
| 130 | GemmMethod::GEMM_INTERLEAVED, |
| 131 | "sgemm_8x6", |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 132 | nullptr, |
| 133 | nullptr, |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 134 | [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, __fp16, __fp16>(args); } |
Georgios Pinitas | a41c54b | 2019-01-30 18:16:43 +0000 | [diff] [blame] | 135 | }, |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 136 | #else // not AArch64 or AArch32 |
| 137 | # error Unknown Architecture |
Georgios Pinitas | a41c54b | 2019-01-30 18:16:43 +0000 | [diff] [blame] | 138 | #endif |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 139 | { |
| 140 | GemmMethod::DEFAULT, |
| 141 | "", |
| 142 | nullptr, |
| 143 | nullptr, |
| 144 | nullptr, |
| 145 | } |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | template<> |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 149 | const GemmImplementation<__fp16, __fp16> *gemm_implementation_list<__fp16, __fp16>() { |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 150 | return gemm_fp16_methods; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 151 | } |
| 152 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 153 | /* Explicitly instantiate the external functions for these types. */ |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 154 | template UniqueGemmCommon<__fp16, __fp16> gemm<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &); |
Francesco Petrogalli | 553f695 | 2022-06-30 10:22:01 +0000 | [diff] [blame] | 155 | template bool has_opt_gemm<__fp16, __fp16, Nothing>(WeightFormat &weight_format, const GemmArgs &args, const Nothing &); |
Francesco.Petrogalli@arm.com | 5fcf22d | 2022-04-05 10:31:08 +0000 | [diff] [blame] | 156 | template KernelDescription get_gemm_method<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &); |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 157 | 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] | 158 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 159 | } // namespace arm_gemm |
| 160 | |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 161 | #endif // defined(__aarch64__) && (defined(FP16_KERNELS) || defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)) |