blob: f7d8f65aea9b73fdac1e0c50741f194b809edd3a [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Georgios Pinitas14613832019-03-01 19:07:11 +00002 * Copyright (c) 2017-2019 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"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000031#include "gemm_native.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000032
33#include "kernels/a64_gemm_s16_12x8.hpp"
34#include "kernels/a64_gemm_s8_12x8.hpp"
David Manselle39334c2018-07-06 17:53:35 +010035#include "kernels/a64_gemm_s8_4x4.hpp"
Georgios Pinitas1d480652019-01-23 11:24:50 +000036#include "kernels/a64_hybrid_s8s32_dot_16x4.hpp"
Georgios Pinitas94672fb2020-01-22 18:36:27 +000037#include "kernels/a64_interleaved_s8s32_mmla_12x8.hpp"
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010038#include "kernels/a64_smallK_hybrid_s8s32_dot_4x6.hpp"
39#include "kernels/a64_smallK_hybrid_s8s32_dot_4x8.hpp"
Georgios Pinitas14613832019-03-01 19:07:11 +000040#include "kernels/sve_hybrid_s8s32_dot_4VLx4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010041#include "kernels/sve_interleaved_s8s32_dot_3VLx8.hpp"
Georgios Pinitas94672fb2020-01-22 18:36:27 +000042#include "kernels/sve_interleaved_s8s32_mmla_3VLx8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000043#include "kernels/sve_native_s8s32_dot_4VLx4.hpp"
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010044#include "kernels/sve_smallK_hybrid_s8s32_dot_1VLx8.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000045
Anthony Barbier5f707732018-07-03 16:22:02 +010046namespace arm_gemm {
47
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000048static const GemmImplementation<int8_t, int32_t> gemm_s8_methods[] = {
Georgios Pinitas421405b2018-10-26 19:05:32 +010049#ifdef __ARM_FEATURE_SVE
Georgios Pinitas94672fb2020-01-22 18:36:27 +000050#ifdef V8P6
51{
52 GemmMethod::GEMM_INTERLEAVED,
53 "interleaved_s8s32_mmla_3VLx8",
54 [](const GemmArgs &args) { return (args._Ksize>8); },
55 nullptr,
56 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_s8s32_mmla_3VLx8, int8_t, int32_t>(args); }
57},
58#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000059{
Georgios Pinitas14613832019-03-01 19:07:11 +000060 GemmMethod::GEMM_HYBRID,
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010061 "smallK_hybrid_s8s32_dot_1VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010062 [](const GemmArgs &args) { return args._Ksize<=64 && !args._trA && args._pretransposed_hint; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010063 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010064 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_1VLx8, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010065},
66{
67 GemmMethod::GEMM_HYBRID,
Georgios Pinitas14613832019-03-01 19:07:11 +000068 "hybrid_s8s32_dot_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010069 [](const GemmArgs &args) { return args._Ksize>=16 && !args._trA && args._pretransposed_hint; },
70 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
71 [](const GemmArgs &args) { return new GemmHybrid<hybrid_s8s32_dot_4VLx4, int8_t, int32_t>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +000072},
73{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000074 GemmMethod::GEMM_NATIVE,
75 "native_s8s32_dot_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010076 [](const GemmArgs &args) { return (args._Ksize>=16 && !args._trA && !args._trB); },
77 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)); },
78 [](const GemmArgs &args) { return new GemmNative<native_s8s32_dot_4VLx4, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000079},
80{
81 GemmMethod::GEMM_INTERLEAVED,
82 "interleaved_s8s32_dot_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010083 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000084 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010085 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_s8s32_dot_3VLx8, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000086},
Georgios Pinitas421405b2018-10-26 19:05:32 +010087#endif
Georgios Pinitas94672fb2020-01-22 18:36:27 +000088#ifdef V8P6
89{
90 GemmMethod::GEMM_INTERLEAVED,
91 "interleaved_s8s32_mmla_12x8",
92 [](const GemmArgs &args) { return (args._Ksize>8); },
93 nullptr,
94 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_s8s32_mmla_12x8, int8_t, int32_t>(args); }
95},
96#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000097{
Georgios Pinitas1d480652019-01-23 11:24:50 +000098 GemmMethod::GEMM_HYBRID,
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010099 "smallK_hybrid_s8s32_dot_4x8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100100 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize<=32) && !args._trA && args._pretransposed_hint; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100101 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100102 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_4x8, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100103},
104{
105 GemmMethod::GEMM_HYBRID,
106 "smallK_hybrid_s8s32_dot_4x6",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100107 [](const GemmArgs &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize>32) && (args._Ksize<=64) && !args._trA && args._pretransposed_hint; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100108 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100109 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_4x6, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100110},
111{
112 GemmMethod::GEMM_HYBRID,
Georgios Pinitas1d480652019-01-23 11:24:50 +0000113 "hybrid_s8s32_dot_16x4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100114 [](const GemmArgs &args) { return args._ci->has_dotprod() && args._Ksize>=16 && !args._trA && !args._trB && args._pretransposed_hint; },
115 [](const GemmArgs &args) { return args._Nsize<=256 && args._Ksize>128; },
116 [](const GemmArgs &args) { return new GemmHybrid<hybrid_s8s32_dot_16x4, int8_t, int32_t>(args); }
Georgios Pinitas1d480652019-01-23 11:24:50 +0000117},
118{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000119 GemmMethod::GEMM_INTERLEAVED,
120 "gemm_s8_12x8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100121 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000122 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100123 [](const GemmArgs &args) { return new GemmInterleaved<gemm_s8_12x8, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000124},
125{
126 GemmMethod::GEMM_INTERLEAVED,
127 "gemm_s8_4x4",
128 nullptr,
129 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100130 [](const GemmArgs &args) { return new GemmInterleaved<gemm_s8_4x4, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000131},
132{
133 GemmMethod::DEFAULT,
134 "",
135 nullptr,
136 nullptr,
137 nullptr
138}
David Manselle39334c2018-07-06 17:53:35 +0100139};
140
141template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000142const GemmImplementation<int8_t, int32_t> *gemm_implementation_list<int8_t, int32_t>() {
David Manselle39334c2018-07-06 17:53:35 +0100143 return gemm_s8_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000144}
145
David Manselle39334c2018-07-06 17:53:35 +0100146/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100147template UniqueGemmCommon<int8_t, int32_t> gemm<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
148template KernelDescription get_gemm_method<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
149template std::vector<KernelDescription> get_compatible_kernels<int8_t, int32_t, Nothing> (const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100150
Pablo Telloeb82fd22018-02-23 13:43:50 +0000151} // namespace arm_gemm
152
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100153#endif // __aarch64__