blob: 0dc0d55b2736ac4c81b8fb42f44c9db34bcf7f71 [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Radu Salavatf1f1f872024-02-27 18:32:26 +00002 * Copyright (c) 2017-2020, 2022-2024 Arm Limited.
Pablo Telloeb82fd22018-02-23 13:43:50 +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#ifdef __aarch64__
25
26#include "arm_gemm.hpp"
27#include "gemm_common.hpp"
Georgios Pinitas1d480652019-01-23 11:24:50 +000028#include "gemm_hybrid.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000029#include "gemm_hybrid_indirect.hpp"
David Manselle39334c2018-07-06 17:53:35 +010030#include "gemm_implementation.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000031#include "gemm_interleaved.hpp"
32
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000033#include "kernels/a64_gemm_s16_8x12.hpp"
34#include "kernels/a64_gemm_s8_8x12.hpp"
David Manselle39334c2018-07-06 17:53:35 +010035#include "kernels/a64_gemm_s8_4x4.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000036#include "kernels/a64_hybrid_s8s32_dot_6x16.hpp"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010037#include "kernels/a64_hybrid_s8s32_mmla_6x16.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000038#include "kernels/a64_interleaved_s8s32_mmla_8x12.hpp"
39#include "kernels/a64_smallK_hybrid_s8s32_dot_6x4.hpp"
40#include "kernels/a64_smallK_hybrid_s8s32_dot_8x4.hpp"
41
Viet-Hoa Do03b29712022-06-01 11:47:14 +010042#ifdef ARM_COMPUTE_ENABLE_SVE
43#ifdef ARM_COMPUTE_ENABLE_SME2
44#include "kernels/sme2_interleaved_nomerge_s8s32_mopa_1VLx4VL.hpp"
45#include "kernels/sme2_interleaved_nomerge_s8s32_mopa_2VLx2VL.hpp"
46#include "kernels/sme2_interleaved_nomerge_s8s32_mopa_4VLx1VL.hpp"
47#endif // ARM_COMPUTE_ENABLE_SME2
48
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000049#include "kernels/sve_hybrid_s8s32_dot_6x4VL.hpp"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010050#include "kernels/sve_hybrid_s8s32_mmla_6x4VL.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000051#include "kernels/sve_interleaved_s8s32_dot_8x3VL.hpp"
52#include "kernels/sve_interleaved_s8s32_mmla_8x3VL.hpp"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010053#endif // ARM_COMPUTE_ENABLE_SVE
Pablo Telloeb82fd22018-02-23 13:43:50 +000054
Anthony Barbier5f707732018-07-03 16:22:02 +010055namespace arm_gemm {
56
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000057static const GemmImplementation<int8_t, int32_t> gemm_s8_methods[] = {
Michalis Spyrou20fca522021-06-07 14:23:57 +010058#ifdef ARM_COMPUTE_ENABLE_SVE
Viet-Hoa Do03b29712022-06-01 11:47:14 +010059#ifdef ARM_COMPUTE_ENABLE_SME2
60// SME kernels
61{
62 GemmMethod::GEMM_INTERLEAVED,
63 "sme2_interleaved_nomerge_s8s32_mopa_1VLx4VL",
64 [](const GemmArgs &args) { return args._ci->has_sme2(); },
65 [](const GemmArgs &args) { const auto VL = sme::get_vector_length<int32_t>();
66 return args._Msize <= VL || (2*VL < args._Msize && args._Msize <= 3*VL); },
67 [](const GemmArgs &args) { return new GemmInterleavedNoMerge<cls_sme2_interleaved_nomerge_s8s32_mopa_1VLx4VL, int8_t, int32_t>(args); }
68},
69{
70 GemmMethod::GEMM_INTERLEAVED,
71 "sme2_interleaved_nomerge_s8s32_mopa_4VLx1VL",
72 [](const GemmArgs &args) { return args._ci->has_sme2(); },
73 [](const GemmArgs &args) { const auto VL = sme::get_vector_length<int32_t>();
74 return args._Nsize <= VL || (2*VL < args._Nsize && args._Nsize <= 3*VL); },
75 [](const GemmArgs &args) { return new GemmInterleavedNoMerge<cls_sme2_interleaved_nomerge_s8s32_mopa_4VLx1VL, int8_t, int32_t>(args); }
76},
77{
78 GemmMethod::GEMM_INTERLEAVED,
79 "sme2_interleaved_nomerge_s8s32_mopa_2VLx2VL",
80 [](const GemmArgs &args) { return args._ci->has_sme2(); },
81 nullptr,
82 [](const GemmArgs &args) { return new GemmInterleavedNoMerge<cls_sme2_interleaved_nomerge_s8s32_mopa_2VLx2VL, int8_t, int32_t>(args); }
83},
84#endif // ARM_COMPUTE_ENABLE_SME2
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010085GemmImplementation<int8_t, int32_t>::with_estimate(
86 GemmMethod::GEMM_HYBRID,
87 "sve_hybrid_s8s32_mmla_6x4VL",
88 [](const GemmArgs &args) { return args._ci->has_svei8mm(); },
89 [](const GemmArgs &args) { return GemmHybridIndirect<cls_sve_hybrid_s8s32_mmla_6x4VL, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
90 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_s8s32_mmla_6x4VL, int8_t, int32_t>(args); }
91),
92GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitas94672fb2020-01-22 18:36:27 +000093 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000094 "sve_interleaved_s8s32_mmla_8x3VL",
Michalis Spyrou20fca522021-06-07 14:23:57 +010095 [](const GemmArgs &args) { return args._ci->has_svei8mm() && (args._Ksize>8); },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010096 [](const GemmArgs &args) { return GemmInterleaved<cls_sve_interleaved_s8s32_mmla_8x3VL, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000097 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_s8s32_mmla_8x3VL, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010098),
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010099GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100100 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000101 "sve_hybrid_s8s32_dot_6x4VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000102 [](const GemmArgs &args) { return args._ci->has_sve() && args._Ksize>=16; },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100103 [](const GemmArgs &args) { return GemmHybridIndirect<cls_sve_hybrid_s8s32_dot_6x4VL, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000104 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_s8s32_dot_6x4VL, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100105),
106GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000107 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000108 "sve_interleaved_s8s32_dot_8x3VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000109 [](const GemmArgs &args) { return args._ci->has_sve() && (args._Ksize>4); },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100110 [](const GemmArgs &args) { return GemmInterleaved<cls_sve_interleaved_s8s32_dot_8x3VL, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000111 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_s8s32_dot_8x3VL, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100112),
113#endif // ARM_COMPUTE_ENABLE_SVE
114GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000115 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000116 "a64_interleaved_s8s32_mmla_8x12",
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100117 [](const GemmArgs &args) { return args._ci->has_i8mm() && (args._Ksize>8); },
118 [](const GemmArgs &args) { return GemmInterleaved<cls_a64_interleaved_s8s32_mmla_8x12, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000119 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_interleaved_s8s32_mmla_8x12, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100120),
121GemmImplementation<int8_t, int32_t>::with_estimate(
122 GemmMethod::GEMM_HYBRID,
123 "a64_hybrid_s8s32_mmla_6x16",
124 [](const GemmArgs &args) { return args._ci->has_i8mm(); },
125 [](const GemmArgs &args) { return GemmHybridIndirect<cls_a64_hybrid_s8s32_mmla_6x16, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
126 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_s8s32_mmla_6x16, int8_t, int32_t>(args); }
127),
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000128{
Georgios Pinitas1d480652019-01-23 11:24:50 +0000129 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000130 "a64_smallK_hybrid_s8s32_dot_8x4",
Radu Salavatf1f1f872024-02-27 18:32:26 +0000131 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize<=32) && !args._indirect_input && !args._accumulate; },
Gunes Bayire42a87f2021-09-13 13:24:38 +0100132 [](const GemmArgs &args) { return !(args._ci->has_svei8mm() || args._ci->has_i8mm()); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000133 [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_s8s32_dot_8x4, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100134},
135{
136 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000137 "a64_smallK_hybrid_s8s32_dot_6x4",
Radu Salavatf1f1f872024-02-27 18:32:26 +0000138 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize>32) && (args._Ksize<=64) && !args._indirect_input && !args._accumulate; },
Gunes Bayire42a87f2021-09-13 13:24:38 +0100139 [](const GemmArgs &args) { return !(args._ci->has_svei8mm() || args._ci->has_i8mm()); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000140 [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_s8s32_dot_6x4, int8_t, int32_t>(args); }
141},
142{
143 GemmMethod::GEMM_INTERLEAVED,
144 "a64_gemm_s16_8x12",
145 nullptr,
Georgios Pinitascd22cbf2020-12-02 16:06:01 +0000146 [](const GemmArgs &args) { return args._ci->get_cpu_model() == CPUModel::A53 && ((args._Msize > 28) || ((args._Msize % 8) > 4)); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000147 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_s16_8x12, int8_t, int32_t>(args); },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100148},
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100149GemmImplementation<int8_t, int32_t>::with_estimate(
150
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100151 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000152 "a64_hybrid_s8s32_dot_6x16",
153 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100154 [](const GemmArgs &args) { return GemmHybridIndirect<cls_a64_hybrid_s8s32_dot_6x16, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000155 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_s8s32_dot_6x16, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100156),
157GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000158 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000159 "a64_gemm_s8_8x12",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100160 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100161 [](const GemmArgs &args) { return GemmInterleaved<cls_a64_gemm_s8_8x12, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000162 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_s8_8x12, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100163),
164GemmImplementation<int8_t, int32_t>::with_estimate(
David Mansell9e698d52020-08-25 15:02:02 +0100165 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000166 "a64_gemm_s8_4x4",
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000167 nullptr,
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100168 [](const GemmArgs &args) { return GemmInterleaved<cls_a64_gemm_s8_4x4, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000169 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_s8_4x4, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100170),
171
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000172{
173 GemmMethod::DEFAULT,
174 "",
175 nullptr,
176 nullptr,
177 nullptr
178}
David Manselle39334c2018-07-06 17:53:35 +0100179};
180
181template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000182const GemmImplementation<int8_t, int32_t> *gemm_implementation_list<int8_t, int32_t>() {
David Manselle39334c2018-07-06 17:53:35 +0100183 return gemm_s8_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000184}
185
David Manselle39334c2018-07-06 17:53:35 +0100186/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100187template UniqueGemmCommon<int8_t, int32_t> gemm<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
Francesco Petrogalli553f6952022-06-30 10:22:01 +0000188template bool has_opt_gemm<int8_t, int32_t, Nothing>(WeightFormat &weight_format, const GemmArgs &args, const Nothing &);
Michael Tyler74921ee2023-04-12 17:43:17 +0100189template KernelDescription get_gemm_method<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100190template std::vector<KernelDescription> get_compatible_kernels<int8_t, int32_t, Nothing> (const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100191
Pablo Telloeb82fd22018-02-23 13:43:50 +0000192} // namespace arm_gemm
193
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100194#endif // __aarch64__