• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017-2020 Arm Limited.
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 
25 // This can only be built if the target/compiler supports FP16 arguments.
26 #ifdef __ARM_FP16_ARGS
27 
28 #include "arm_gemm.hpp"
29 
30 #include "gemm_common.hpp"
31 #include "gemm_hybrid.hpp"
32 #include "gemm_hybrid_indirect.hpp"
33 #include "gemm_implementation.hpp"
34 #include "gemm_interleaved.hpp"
35 #include "gemm_interleaved_pretransposed_2d.hpp"
36 
37 #include "kernels/a32_sgemm_8x6.hpp"
38 #include "kernels/a64_hgemm_8x24.hpp"
39 #include "kernels/a64_hybrid_fp16_mla_6x32.hpp"
40 #include "kernels/a64_sgemm_8x12.hpp"
41 #include "kernels/sve_hybrid_fp16_mla_6x4VL.hpp"
42 #include "kernels/sve_interleaved_fp16_mla_8x3VL.hpp"
43 
44 namespace arm_gemm {
45 
46 static const GemmImplementation<__fp16, __fp16> gemm_fp16_methods[] = {
47 #if defined(__ARM_FEATURE_SVE)
48 {
49     GemmMethod::GEMM_HYBRID,
50     "sve_hybrid_fp16_mla_6x4VL",
51     nullptr,
__anona6326bd60102() 52     [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
__anona6326bd60202() 53     [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp16_mla_6x32, __fp16, __fp16>(args); }
54 },
55 {
56     GemmMethod::GEMM_INTERLEAVED,
57     "sve_interleaved_fp16_mla_8x3VL",
__anona6326bd60302() 58     [](const GemmArgs &args) { return (args._Ksize > 4); },
59     nullptr,
__anona6326bd60402() 60     [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_fp16_mla_8x3VL, __fp16, __fp16>(args); }
61 },
62 #endif
63 
64 #if defined(__aarch64__) && (defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) || defined(FP16_KERNELS))
65 GemmImplementation<__fp16, __fp16>::with_estimate(
66     GemmMethod::GEMM_HYBRID,
67     "a64_hybrid_fp16_mla_6x32",
68 #ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
__anona6326bd60502() 69     [](const GemmArgs &args) { return args._ci->has_fp16(); },
70 #else
71     nullptr,
72 #endif
__anona6326bd60602() 73     [](const GemmArgs &args) { return GemmHybridIndirect<cls_a64_hybrid_fp16_mla_6x32, __fp16, __fp16>::estimate_cycles(args, cls_a64_hybrid_fp16_mla_6x32::get_performance_parameters(args._ci)); },
__anona6326bd60702() 74     [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp16_mla_6x32, __fp16, __fp16>(args); }
75 ),
76 GemmImplementation<__fp16, __fp16>::with_estimate(
77     GemmMethod::GEMM_INTERLEAVED,
78     "a64_hgemm_8x24",
79 #ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
__anona6326bd60802() 80     [](const GemmArgs &args) { return args._ci->has_fp16(); },
81 #else
82     nullptr,
83 #endif
__anona6326bd60902() 84     [](const GemmArgs &args) { return GemmInterleaved<cls_a64_hgemm_8x24, __fp16, __fp16>::estimate_cycles(args, cls_a64_hgemm_8x24::get_performance_parameters(args._ci)); },
__anona6326bd60a02() 85     [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_hgemm_8x24, __fp16, __fp16>(args); }
86 ),
87 #endif // aarch64 && FP16
88 #ifdef __aarch64__
89 {
90     GemmMethod::GEMM_INTERLEAVED,
91     "a64_sgemm_8x12",
92     nullptr,
__anona6326bd60b02() 93     [](const GemmArgs &args) { return !args._ci->has_fp16(); },
__anona6326bd60c02() 94     [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_sgemm_8x12, __fp16, __fp16>(args); }
95 },
96 #elif defined(__arm__)
97 {
98     GemmMethod::GEMM_INTERLEAVED,
99     "sgemm_8x6",
100     nullptr,
101     nullptr,
102     [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, __fp16, __fp16>(args); }
103 },
104 #else // not AArch64 or AArch32
105 # error Unknown Architecture
106 #endif
107 {
108     GemmMethod::DEFAULT,
109     "",
110     nullptr,
111     nullptr,
112     nullptr,
113 }
114 };
115 
116 template<>
gemm_implementation_list()117 const GemmImplementation<__fp16, __fp16> *gemm_implementation_list<__fp16, __fp16>() {
118     return gemm_fp16_methods;
119 }
120 
121 /* Explicitly instantiate the external functions for these types. */
122 template UniqueGemmCommon<__fp16, __fp16> gemm<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
123 template KernelDescription get_gemm_method<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
124 template std::vector<KernelDescription> get_compatible_kernels<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
125 
126 } // namespace arm_gemm
127 
128 #endif // __ARM_FP16_ARGS
129