blob: 88726b14480a519dd5941de10cd7bd4a5183ad5b [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"
David Manselle39334c2018-07-06 17:53:35 +010028#include "gemm_implementation.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000029#include "gemm_interleaved.hpp"
Aleksandr Nikolaeva084b462020-06-25 12:25:52 +010030#include "gemm_interleaved_pretransposed_2d.hpp"
Georgios Pinitas1d480652019-01-23 11:24:50 +000031#include "gemm_hybrid.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000032
David Manselle39334c2018-07-06 17:53:35 +010033#include "kernels/a64_gemm_u16_12x8.hpp"
Anthony Barbier5f707732018-07-03 16:22:02 +010034#include "kernels/a64_gemm_u8_12x8.hpp"
David Manselle39334c2018-07-06 17:53:35 +010035#include "kernels/a64_gemm_u8_4x4.hpp"
Georgios Pinitas1d480652019-01-23 11:24:50 +000036#include "kernels/a64_hybrid_u8u32_dot_16x4.hpp"
Georgios Pinitas94672fb2020-01-22 18:36:27 +000037#include "kernels/a64_interleaved_u8u32_mmla_12x8.hpp"
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010038#include "kernels/a64_smallK_hybrid_u8u32_dot_4x6.hpp"
39#include "kernels/a64_smallK_hybrid_u8u32_dot_4x8.hpp"
Georgios Pinitas14613832019-03-01 19:07:11 +000040#include "kernels/sve_hybrid_u8u32_dot_4VLx4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010041#include "kernels/sve_interleaved_u8u32_dot_3VLx8.hpp"
Georgios Pinitas94672fb2020-01-22 18:36:27 +000042#include "kernels/sve_interleaved_u8u32_mmla_3VLx8.hpp"
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010043#include "kernels/sve_smallK_hybrid_u8u32_dot_1VLx8.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000044
Anthony Barbier5f707732018-07-03 16:22:02 +010045namespace arm_gemm {
46
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000047static const GemmImplementation<uint8_t, uint32_t> gemm_u8_methods[] = {
Georgios Pinitas421405b2018-10-26 19:05:32 +010048#ifdef __ARM_FEATURE_SVE
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010049#ifdef MMLA_INT8
Georgios Pinitas94672fb2020-01-22 18:36:27 +000050{
51 GemmMethod::GEMM_INTERLEAVED,
52 "interleaved_u8u32_mmla_3VLx8",
53 [](const GemmArgs &args) { return (args._Ksize>8); },
54 nullptr,
55 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_u8u32_mmla_3VLx8, uint8_t, uint32_t>(args); }
56},
57#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000058{
Georgios Pinitas14613832019-03-01 19:07:11 +000059 GemmMethod::GEMM_HYBRID,
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010060 "smallK_hybrid_u8u32_dot_1VLx8",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010061 [](const GemmArgs &args) { return args._Ksize<=64; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010062 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010063 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_u8u32_dot_1VLx8, uint8_t, uint32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010064},
65{
66 GemmMethod::GEMM_HYBRID,
Georgios Pinitas14613832019-03-01 19:07:11 +000067 "hybrid_u8u32_dot_4VLx4",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010068 [](const GemmArgs &args) { return args._Ksize>=16; },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010069 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
70 [](const GemmArgs &args) { return new GemmHybrid<hybrid_u8u32_dot_4VLx4, uint8_t, uint32_t>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +000071},
72{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000073 GemmMethod::GEMM_INTERLEAVED,
74 "interleaved_u8u32_dot_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010075 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000076 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010077 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_u8u32_dot_3VLx8, uint8_t, uint32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000078},
Georgios Pinitas421405b2018-10-26 19:05:32 +010079#endif
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010080#ifdef MMLA_INT8
Georgios Pinitas94672fb2020-01-22 18:36:27 +000081{
82 GemmMethod::GEMM_INTERLEAVED,
83 "interleaved_u8u32_mmla_12x8",
84 [](const GemmArgs &args) { return (args._Ksize>8); },
85 nullptr,
86 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_u8u32_mmla_12x8, uint8_t, uint32_t>(args); }
87},
88#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000089{
Georgios Pinitas1d480652019-01-23 11:24:50 +000090 GemmMethod::GEMM_HYBRID,
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010091 "smallK_hybrid_u8u32_dot_4x8",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010092 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize<=32); },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010093 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010094 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_u8u32_dot_4x8, uint8_t, uint32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010095},
96{
97 GemmMethod::GEMM_HYBRID,
98 "smallK_hybrid_u8u32_dot_4x6",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010099 [](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 +0100100 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100101 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_u8u32_dot_4x6, uint8_t, uint32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100102},
103{
David Mansell318c9f42020-07-08 13:28:45 +0100104 GemmMethod::GEMM_INTERLEAVED,
105 "gemm_u16_12x8",
106 nullptr,
107 [](const GemmArgs &args) { return args._ci->get_cpu_model() == CPUModel::A53; },
108 [](const GemmArgs &args) { return new GemmInterleaved<gemm_u16_12x8, uint8_t, uint32_t>(args); },
109},
110{
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100111 GemmMethod::GEMM_HYBRID,
Georgios Pinitas1d480652019-01-23 11:24:50 +0000112 "hybrid_u8u32_dot_16x4",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +0100113 [](const GemmArgs &args) { return args._ci->has_dotprod() && args._Ksize>=16; },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100114 [](const GemmArgs &args) { return args._Nsize<=256 && args._Ksize>128; },
115 [](const GemmArgs &args) { return new GemmHybrid<hybrid_u8u32_dot_16x4, uint8_t, uint32_t>(args); }
Georgios Pinitas1d480652019-01-23 11:24:50 +0000116},
117{
Aleksandr Nikolaeva084b462020-06-25 12:25:52 +0100118 GemmMethod::GEMM_INTERLEAVED_2D,
119 "gemm_u8_12x8_2d",
120 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
121 [](const GemmArgs &args) { return (args._maxthreads >= 8) && (args._Msize >= 8) && (args._Nsize >= 8) ; },
122 [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<gemm_u8_12x8, uint8_t, uint32_t>(args); }
123},
124{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000125 GemmMethod::GEMM_INTERLEAVED,
Aleksandr Nikolaeva084b462020-06-25 12:25:52 +0100126 "gemm_u8_12x8_1d",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100127 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000128 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100129 [](const GemmArgs &args) { return new GemmInterleaved<gemm_u8_12x8, uint8_t, uint32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000130},
131{
Aleksandr Nikolaeva084b462020-06-25 12:25:52 +0100132 GemmMethod::GEMM_INTERLEAVED_2D,
133 "gemm_u8_4x4_2d",
134 nullptr,
135 [](const GemmArgs &args) { return (args._maxthreads >= 8) && (args._Msize >= 8) && (args._Nsize >= 8); },
136 [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<gemm_u8_4x4, uint8_t, uint32_t>(args); }
137},
138{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000139 GemmMethod::GEMM_INTERLEAVED,
Aleksandr Nikolaeva084b462020-06-25 12:25:52 +0100140 "gemm_u8_4x4_1d",
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000141 nullptr,
142 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100143 [](const GemmArgs &args) { return new GemmInterleaved<gemm_u8_4x4, uint8_t, uint32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000144},
145{
146 GemmMethod::DEFAULT,
147 "",
148 nullptr,
149 nullptr,
150 nullptr
151}
David Manselle39334c2018-07-06 17:53:35 +0100152};
153
154template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000155const GemmImplementation<uint8_t, uint32_t> *gemm_implementation_list<uint8_t, uint32_t>() {
David Manselle39334c2018-07-06 17:53:35 +0100156 return gemm_u8_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000157}
158
David Manselle39334c2018-07-06 17:53:35 +0100159/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100160template UniqueGemmCommon<uint8_t, uint32_t> gemm<uint8_t, uint32_t, Nothing>(const GemmArgs &args, const Nothing &);
161template KernelDescription get_gemm_method<uint8_t, uint32_t, Nothing>(const GemmArgs &args, const Nothing &);
162template std::vector<KernelDescription> get_compatible_kernels<uint8_t, uint32_t, Nothing> (const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100163
Pablo Telloeb82fd22018-02-23 13:43:50 +0000164} // namespace arm_gemm
165
David Manselle39334c2018-07-06 17:53:35 +0100166#endif // __aarch64__