blob: 7d24ea68d60a7c47a10d38fa2b613fb006f8bbf2 [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"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000032#include "gemm_hybrid_indirect.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000033
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000034#include "kernels/a64_gemm_u16_8x12.hpp"
David Manselle39334c2018-07-06 17:53:35 +010035#include "kernels/a64_gemm_u8_4x4.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000036#include "kernels/a64_gemm_u8_8x12.hpp"
37#include "kernels/a64_hybrid_u8u32_dot_6x16.hpp"
38#include "kernels/a64_interleaved_u8u32_mmla_8x12.hpp"
39#include "kernels/a64_smallK_hybrid_u8u32_dot_6x4.hpp"
40#include "kernels/a64_smallK_hybrid_u8u32_dot_8x4.hpp"
41
42#include "kernels/sve_hybrid_u8u32_dot_6x4VL.hpp"
43#include "kernels/sve_interleaved_u8u32_dot_8x3VL.hpp"
44#include "kernels/sve_interleaved_u8u32_mmla_8x3VL.hpp"
45#include "kernels/sve_smallK_hybrid_u8u32_dot_8x1VL.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000046
Anthony Barbier5f707732018-07-03 16:22:02 +010047namespace arm_gemm {
48
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000049static const GemmImplementation<uint8_t, uint32_t> gemm_u8_methods[] = {
Georgios Pinitas421405b2018-10-26 19:05:32 +010050#ifdef __ARM_FEATURE_SVE
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010051#ifdef MMLA_INT8
Georgios Pinitas94672fb2020-01-22 18:36:27 +000052{
53 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000054 "sve_interleaved_u8u32_mmla_8x3VL",
Georgios Pinitas94672fb2020-01-22 18:36:27 +000055 [](const GemmArgs &args) { return (args._Ksize>8); },
56 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000057 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_u8u32_mmla_8x3VL, uint8_t, uint32_t>(args); }
Georgios Pinitas94672fb2020-01-22 18:36:27 +000058},
59#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000060{
Georgios Pinitas14613832019-03-01 19:07:11 +000061 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000062 "smallK_hybrid_u8u32_dot_8x1VL",
63 [](const GemmArgs &args) { return args._Ksize<=64 && !args._indirect_input; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010064 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000065 [](const GemmArgs &args) { return new GemmHybrid<cls_sve_smallK_hybrid_u8u32_dot_8x1VL, uint8_t, uint32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010066},
67{
68 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000069 "sve_hybrid_u8u32_dot_6x4VL",
70 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010071 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000072 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_u8u32_dot_6x4VL, uint8_t, uint32_t>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +000073},
74{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000075 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000076 "sve_interleaved_u8u32_dot_8x3VL",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010077 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000078 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000079 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_u8u32_dot_8x3VL, uint8_t, uint32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000080},
Georgios Pinitas421405b2018-10-26 19:05:32 +010081#endif
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010082#ifdef MMLA_INT8
Georgios Pinitas94672fb2020-01-22 18:36:27 +000083{
84 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000085 "a64_interleaved_u8u32_mmla_8x12",
Georgios Pinitas94672fb2020-01-22 18:36:27 +000086 [](const GemmArgs &args) { return (args._Ksize>8); },
87 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000088 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_interleaved_u8u32_mmla_8x12, uint8_t, uint32_t>(args); }
Georgios Pinitas94672fb2020-01-22 18:36:27 +000089},
90#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000091{
Georgios Pinitas1d480652019-01-23 11:24:50 +000092 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000093 "a64_smallK_hybrid_u8u32_dot_8x4",
94 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize<=32) && !args._indirect_input; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010095 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000096 [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_u8u32_dot_8x4, uint8_t, uint32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010097},
98{
99 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000100 "a64_smallK_hybrid_u8u32_dot_6x4",
101 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize>32) && (args._Ksize<=64) && !args._indirect_input; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100102 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000103 [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_u8u32_dot_6x4, uint8_t, uint32_t>(args); }
104},
105{
106 GemmMethod::GEMM_INTERLEAVED,
107 "a64_gemm_u16_8x12",
108 nullptr,
Georgios Pinitascd22cbf2020-12-02 16:06:01 +0000109 [](const GemmArgs &args) { return args._ci->get_cpu_model() == CPUModel::A53 && args._Msize > 4; },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000110 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_u16_8x12, uint8_t, uint32_t>(args); },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100111},
112{
113 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000114 "a64_hybrid_u8u32_dot_6x16",
115 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100116 [](const GemmArgs &args) { return args._Nsize<=256 && args._Ksize>128; },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000117 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_u8u32_dot_6x16, uint8_t, uint32_t>(args); }
Aleksandr Nikolaeva084b462020-06-25 12:25:52 +0100118},
119{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000120 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000121 "a64_gemm_u8_8x12",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100122 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000123 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000124 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_u8_8x12, uint8_t, uint32_t>(args); }
David Mansell9e698d52020-08-25 15:02:02 +0100125},
126{
127 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000128 "a64_gemm_u8_4x4",
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000129 nullptr,
130 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000131 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_gemm_u8_4x4, uint8_t, uint32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000132},
133{
134 GemmMethod::DEFAULT,
135 "",
136 nullptr,
137 nullptr,
138 nullptr
139}
David Manselle39334c2018-07-06 17:53:35 +0100140};
141
142template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000143const GemmImplementation<uint8_t, uint32_t> *gemm_implementation_list<uint8_t, uint32_t>() {
David Manselle39334c2018-07-06 17:53:35 +0100144 return gemm_u8_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000145}
146
David Manselle39334c2018-07-06 17:53:35 +0100147/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100148template UniqueGemmCommon<uint8_t, uint32_t> gemm<uint8_t, uint32_t, Nothing>(const GemmArgs &args, const Nothing &);
149template KernelDescription get_gemm_method<uint8_t, uint32_t, Nothing>(const GemmArgs &args, const Nothing &);
150template std::vector<KernelDescription> get_compatible_kernels<uint8_t, uint32_t, Nothing> (const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100151
Pablo Telloeb82fd22018-02-23 13:43:50 +0000152} // namespace arm_gemm
153
David Manselle39334c2018-07-06 17:53:35 +0100154#endif // __aarch64__