blob: 24507486ac753f75f7f94c95288941d8b6a15dea [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Francesco.Petrogalli@arm.com193cad32022-03-07 13:39:21 +00002 * Copyright (c) 2017-2020, 2022 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
42#include "kernels/sve_hybrid_s8s32_dot_6x4VL.hpp"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010043#include "kernels/sve_hybrid_s8s32_mmla_6x4VL.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000044#include "kernels/sve_interleaved_s8s32_dot_8x3VL.hpp"
45#include "kernels/sve_interleaved_s8s32_mmla_8x3VL.hpp"
46#include "kernels/sve_smallK_hybrid_s8s32_dot_8x1VL.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000047
Anthony Barbier5f707732018-07-03 16:22:02 +010048namespace arm_gemm {
49
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000050static const GemmImplementation<int8_t, int32_t> gemm_s8_methods[] = {
Michalis Spyrou20fca522021-06-07 14:23:57 +010051#ifdef ARM_COMPUTE_ENABLE_SVE
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010052GemmImplementation<int8_t, int32_t>::with_estimate(
53 GemmMethod::GEMM_HYBRID,
54 "sve_hybrid_s8s32_mmla_6x4VL",
55 [](const GemmArgs &args) { return args._ci->has_svei8mm(); },
56 [](const GemmArgs &args) { return GemmHybridIndirect<cls_sve_hybrid_s8s32_mmla_6x4VL, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
57 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_s8s32_mmla_6x4VL, int8_t, int32_t>(args); }
58),
59GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitas94672fb2020-01-22 18:36:27 +000060 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000061 "sve_interleaved_s8s32_mmla_8x3VL",
Michalis Spyrou20fca522021-06-07 14:23:57 +010062 [](const GemmArgs &args) { return args._ci->has_svei8mm() && (args._Ksize>8); },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010063 [](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 +000064 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_s8s32_mmla_8x3VL, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010065),
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000066{
Georgios Pinitas14613832019-03-01 19:07:11 +000067 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000068 "sve_smallK_hybrid_s8s32_dot_8x1VL",
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010069 [](const GemmArgs &args) { return args._ci->has_svei8mm() && args._Ksize<=64 && !args._indirect_input; },
Gunes Bayire42a87f2021-09-13 13:24:38 +010070 [](const GemmArgs &args) { return !(args._ci->has_svei8mm() || args._ci->has_i8mm()); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000071 [](const GemmArgs &args) { return new GemmHybrid<cls_sve_smallK_hybrid_s8s32_dot_8x1VL, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010072},
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010073GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010074 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000075 "sve_hybrid_s8s32_dot_6x4VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +000076 [](const GemmArgs &args) { return args._ci->has_sve() && args._Ksize>=16; },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010077 [](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 +000078 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_s8s32_dot_6x4VL, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010079),
80GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000081 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000082 "sve_interleaved_s8s32_dot_8x3VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +000083 [](const GemmArgs &args) { return args._ci->has_sve() && (args._Ksize>4); },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010084 [](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 +000085 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_s8s32_dot_8x3VL, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010086),
87#endif // ARM_COMPUTE_ENABLE_SVE
88GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitas94672fb2020-01-22 18:36:27 +000089 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000090 "a64_interleaved_s8s32_mmla_8x12",
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010091 [](const GemmArgs &args) { return args._ci->has_i8mm() && (args._Ksize>8); },
92 [](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 +000093 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_interleaved_s8s32_mmla_8x12, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010094),
95GemmImplementation<int8_t, int32_t>::with_estimate(
96 GemmMethod::GEMM_HYBRID,
97 "a64_hybrid_s8s32_mmla_6x16",
98 [](const GemmArgs &args) { return args._ci->has_i8mm(); },
99 [](const GemmArgs &args) { return GemmHybridIndirect<cls_a64_hybrid_s8s32_mmla_6x16, int8_t, int32_t>::estimate_cycles<int32_t>(args); },
100 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_s8s32_mmla_6x16, int8_t, int32_t>(args); }
101),
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000102{
Georgios Pinitas1d480652019-01-23 11:24:50 +0000103 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000104 "a64_smallK_hybrid_s8s32_dot_8x4",
105 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize<=32) && !args._indirect_input; },
Gunes Bayire42a87f2021-09-13 13:24:38 +0100106 [](const GemmArgs &args) { return !(args._ci->has_svei8mm() || args._ci->has_i8mm()); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000107 [](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 +0100108},
109{
110 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000111 "a64_smallK_hybrid_s8s32_dot_6x4",
112 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize>32) && (args._Ksize<=64) && !args._indirect_input; },
Gunes Bayire42a87f2021-09-13 13:24:38 +0100113 [](const GemmArgs &args) { return !(args._ci->has_svei8mm() || args._ci->has_i8mm()); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000114 [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_s8s32_dot_6x4, int8_t, int32_t>(args); }
115},
116{
117 GemmMethod::GEMM_INTERLEAVED,
118 "a64_gemm_s16_8x12",
119 nullptr,
Georgios Pinitascd22cbf2020-12-02 16:06:01 +0000120 [](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 +0000121 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_s16_8x12, int8_t, int32_t>(args); },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100122},
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100123GemmImplementation<int8_t, int32_t>::with_estimate(
124
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100125 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000126 "a64_hybrid_s8s32_dot_6x16",
127 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100128 [](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 +0000129 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_s8s32_dot_6x16, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100130),
131GemmImplementation<int8_t, int32_t>::with_estimate(
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000132 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000133 "a64_gemm_s8_8x12",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100134 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100135 [](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 +0000136 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_s8_8x12, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100137),
138GemmImplementation<int8_t, int32_t>::with_estimate(
David Mansell9e698d52020-08-25 15:02:02 +0100139 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000140 "a64_gemm_s8_4x4",
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000141 nullptr,
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100142 [](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 +0000143 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_s8_4x4, int8_t, int32_t>(args); }
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100144),
145
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000146{
147 GemmMethod::DEFAULT,
148 "",
149 nullptr,
150 nullptr,
151 nullptr
152}
David Manselle39334c2018-07-06 17:53:35 +0100153};
154
155template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000156const GemmImplementation<int8_t, int32_t> *gemm_implementation_list<int8_t, int32_t>() {
David Manselle39334c2018-07-06 17:53:35 +0100157 return gemm_s8_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000158}
159
David Manselle39334c2018-07-06 17:53:35 +0100160/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100161template UniqueGemmCommon<int8_t, int32_t> gemm<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
Francesco Petrogalli553f6952022-06-30 10:22:01 +0000162template bool has_opt_gemm<int8_t, int32_t, Nothing>(WeightFormat &weight_format, const GemmArgs &args, const Nothing &);
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100163template std::vector<KernelDescription> get_compatible_kernels<int8_t, int32_t, Nothing> (const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100164
Pablo Telloeb82fd22018-02-23 13:43:50 +0000165} // namespace arm_gemm
166
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100167#endif // __aarch64__