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