blob: d1d137e090195230be629550ef0855c05123a2fd [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +01002 * Copyright (c) 2017-2020 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"
David Manselle39334c2018-07-06 17:53:35 +010029#include "gemm_implementation.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000030#include "gemm_interleaved.hpp"
31
32#include "kernels/a64_gemm_s16_12x8.hpp"
33#include "kernels/a64_gemm_s8_12x8.hpp"
David Manselle39334c2018-07-06 17:53:35 +010034#include "kernels/a64_gemm_s8_4x4.hpp"
Georgios Pinitas1d480652019-01-23 11:24:50 +000035#include "kernels/a64_hybrid_s8s32_dot_16x4.hpp"
Georgios Pinitas94672fb2020-01-22 18:36:27 +000036#include "kernels/a64_interleaved_s8s32_mmla_12x8.hpp"
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010037#include "kernels/a64_smallK_hybrid_s8s32_dot_4x6.hpp"
38#include "kernels/a64_smallK_hybrid_s8s32_dot_4x8.hpp"
Georgios Pinitas14613832019-03-01 19:07:11 +000039#include "kernels/sve_hybrid_s8s32_dot_4VLx4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010040#include "kernels/sve_interleaved_s8s32_dot_3VLx8.hpp"
Georgios Pinitas94672fb2020-01-22 18:36:27 +000041#include "kernels/sve_interleaved_s8s32_mmla_3VLx8.hpp"
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010042#include "kernels/sve_smallK_hybrid_s8s32_dot_1VLx8.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000043
Anthony Barbier5f707732018-07-03 16:22:02 +010044namespace arm_gemm {
45
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000046static const GemmImplementation<int8_t, int32_t> gemm_s8_methods[] = {
Georgios Pinitas421405b2018-10-26 19:05:32 +010047#ifdef __ARM_FEATURE_SVE
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010048#ifdef MMLA_INT8
Georgios Pinitas94672fb2020-01-22 18:36:27 +000049{
50 GemmMethod::GEMM_INTERLEAVED,
51 "interleaved_s8s32_mmla_3VLx8",
52 [](const GemmArgs &args) { return (args._Ksize>8); },
53 nullptr,
54 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_s8s32_mmla_3VLx8, int8_t, int32_t>(args); }
55},
56#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000057{
Georgios Pinitas14613832019-03-01 19:07:11 +000058 GemmMethod::GEMM_HYBRID,
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010059 "smallK_hybrid_s8s32_dot_1VLx8",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010060 [](const GemmArgs &args) { return args._Ksize<=64; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010061 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010062 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_1VLx8, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010063},
64{
65 GemmMethod::GEMM_HYBRID,
Georgios Pinitas14613832019-03-01 19:07:11 +000066 "hybrid_s8s32_dot_4VLx4",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010067 [](const GemmArgs &args) { return args._Ksize>=16; },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010068 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
69 [](const GemmArgs &args) { return new GemmHybrid<hybrid_s8s32_dot_4VLx4, int8_t, int32_t>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +000070},
71{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000072 GemmMethod::GEMM_INTERLEAVED,
73 "interleaved_s8s32_dot_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010074 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000075 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010076 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_s8s32_dot_3VLx8, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000077},
Georgios Pinitas421405b2018-10-26 19:05:32 +010078#endif
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010079#ifdef MMLA_INT8
Georgios Pinitas94672fb2020-01-22 18:36:27 +000080{
81 GemmMethod::GEMM_INTERLEAVED,
82 "interleaved_s8s32_mmla_12x8",
83 [](const GemmArgs &args) { return (args._Ksize>8); },
84 nullptr,
85 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_s8s32_mmla_12x8, int8_t, int32_t>(args); }
86},
87#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000088{
Georgios Pinitas1d480652019-01-23 11:24:50 +000089 GemmMethod::GEMM_HYBRID,
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010090 "smallK_hybrid_s8s32_dot_4x8",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010091 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize<=32); },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010092 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010093 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_4x8, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010094},
95{
96 GemmMethod::GEMM_HYBRID,
97 "smallK_hybrid_s8s32_dot_4x6",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010098 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize>32) && (args._Ksize<=64); },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010099 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100100 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_4x6, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100101},
102{
103 GemmMethod::GEMM_HYBRID,
Georgios Pinitas1d480652019-01-23 11:24:50 +0000104 "hybrid_s8s32_dot_16x4",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +0100105 [](const GemmArgs &args) { return args._ci->has_dotprod() && args._Ksize>=16; },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100106 [](const GemmArgs &args) { return args._Nsize<=256 && args._Ksize>128; },
107 [](const GemmArgs &args) { return new GemmHybrid<hybrid_s8s32_dot_16x4, int8_t, int32_t>(args); }
Georgios Pinitas1d480652019-01-23 11:24:50 +0000108},
109{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000110 GemmMethod::GEMM_INTERLEAVED,
111 "gemm_s8_12x8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100112 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000113 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100114 [](const GemmArgs &args) { return new GemmInterleaved<gemm_s8_12x8, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000115},
116{
117 GemmMethod::GEMM_INTERLEAVED,
118 "gemm_s8_4x4",
119 nullptr,
120 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100121 [](const GemmArgs &args) { return new GemmInterleaved<gemm_s8_4x4, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000122},
123{
124 GemmMethod::DEFAULT,
125 "",
126 nullptr,
127 nullptr,
128 nullptr
129}
David Manselle39334c2018-07-06 17:53:35 +0100130};
131
132template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000133const GemmImplementation<int8_t, int32_t> *gemm_implementation_list<int8_t, int32_t>() {
David Manselle39334c2018-07-06 17:53:35 +0100134 return gemm_s8_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000135}
136
David Manselle39334c2018-07-06 17:53:35 +0100137/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100138template UniqueGemmCommon<int8_t, int32_t> gemm<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
139template KernelDescription get_gemm_method<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
140template std::vector<KernelDescription> get_compatible_kernels<int8_t, int32_t, Nothing> (const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100141
Pablo Telloeb82fd22018-02-23 13:43:50 +0000142} // namespace arm_gemm
143
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100144#endif // __aarch64__