blob: f3b66528a4613745d018cfcd9a45499e1f7dfaf8 [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"
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000030#include "gemv_batched.hpp"
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000031#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 Pinitasc7b183a2020-03-06 18:12:09 +000039#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 Pinitasc7b183a2020-03-06 18:12:09 +000044namespace arm_gemm {
45
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000046static 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 Pinitas0cc50ed2020-07-06 19:10:38 +010053 [](const GemmArgs &args) { return (args._Ksize>=8); },
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000054 [](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 Pinitas0cc50ed2020-07-06 19:10:38 +010060 [](const GemmArgs &args) { return (args._Ksize>=8); },
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000061 [](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 Pinitas0cc50ed2020-07-06 19:10:38 +010067 [](const GemmArgs &args) { return (args._Ksize>=8); },
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000068 [](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 Pinitas0cc50ed2020-07-06 19:10:38 +010074 [](const GemmArgs &args) { return (args._Ksize>=8); },
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000075 [](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 Pinitasc7b183a2020-03-06 18:12:09 +000078{ // 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
136template<>
137const GemmImplementation<bfloat16, float> *gemm_implementation_list<bfloat16, float>() {
138 return gemm_bf16_methods;
139}
140
141/* Explicitly instantiate the external functions for these types. */
142template UniqueGemmCommon<bfloat16, float> gemm<bfloat16, float, Nothing>(const GemmArgs &args, const Nothing &);
143template KernelDescription get_gemm_method<bfloat16, float, Nothing>(const GemmArgs &args, const Nothing &);
144template std::vector<KernelDescription> get_compatible_kernels<bfloat16, float, Nothing>(const GemmArgs &args, const Nothing &);
145
146} // namespace arm_gemm