blob: a3446b9ddcd18cd280cc4f0d859c4879358835c8 [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 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 Pinitas7cd26d42019-01-09 18:35:17 +000041#include "kernels/sve_native_s8s32_dot_4VLx4.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 Pinitas7cd26d42019-01-09 18:35:17 +000048{
Georgios Pinitas14613832019-03-01 19:07:11 +000049 GemmMethod::GEMM_HYBRID,
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010050 "smallK_hybrid_s8s32_dot_1VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010051 [](const GemmArgs &args) { return args._Ksize<=64 && !args._trA && args._pretransposed_hint; },
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010052 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010053 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_1VLx8, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010054},
55{
56 GemmMethod::GEMM_HYBRID,
Georgios Pinitas14613832019-03-01 19:07:11 +000057 "hybrid_s8s32_dot_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010058 [](const GemmArgs &args) { return args._Ksize>=16 && !args._trA && args._pretransposed_hint; },
59 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
60 [](const GemmArgs &args) { return new GemmHybrid<hybrid_s8s32_dot_4VLx4, int8_t, int32_t>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +000061},
62{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000063 GemmMethod::GEMM_NATIVE,
64 "native_s8s32_dot_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010065 [](const GemmArgs &args) { return (args._Ksize>=16 && !args._trA && !args._trB); },
66 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)); },
67 [](const GemmArgs &args) { return new GemmNative<native_s8s32_dot_4VLx4, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000068},
69{
70 GemmMethod::GEMM_INTERLEAVED,
71 "interleaved_s8s32_dot_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010072 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000073 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010074 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_s8s32_dot_3VLx8, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000075},
Georgios Pinitas421405b2018-10-26 19:05:32 +010076#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000077{
Georgios Pinitas1d480652019-01-23 11:24:50 +000078 GemmMethod::GEMM_HYBRID,
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010079 "smallK_hybrid_s8s32_dot_4x8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010080 [](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 +010081 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010082 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_4x8, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010083},
84{
85 GemmMethod::GEMM_HYBRID,
86 "smallK_hybrid_s8s32_dot_4x6",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010087 [](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 +010088 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010089 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_4x6, int8_t, int32_t>(args); }
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010090},
91{
92 GemmMethod::GEMM_HYBRID,
Georgios Pinitas1d480652019-01-23 11:24:50 +000093 "hybrid_s8s32_dot_16x4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010094 [](const GemmArgs &args) { return args._ci->has_dotprod() && args._Ksize>=16 && !args._trA && !args._trB && args._pretransposed_hint; },
95 [](const GemmArgs &args) { return args._Nsize<=256 && args._Ksize>128; },
96 [](const GemmArgs &args) { return new GemmHybrid<hybrid_s8s32_dot_16x4, int8_t, int32_t>(args); }
Georgios Pinitas1d480652019-01-23 11:24:50 +000097},
98{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000099 GemmMethod::GEMM_INTERLEAVED,
100 "gemm_s8_12x8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100101 [](const GemmArgs &args) { return args._ci->has_dotprod(); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000102 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100103 [](const GemmArgs &args) { return new GemmInterleaved<gemm_s8_12x8, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000104},
105{
106 GemmMethod::GEMM_INTERLEAVED,
107 "gemm_s8_4x4",
108 nullptr,
109 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100110 [](const GemmArgs &args) { return new GemmInterleaved<gemm_s8_4x4, int8_t, int32_t>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000111},
112{
113 GemmMethod::DEFAULT,
114 "",
115 nullptr,
116 nullptr,
117 nullptr
118}
David Manselle39334c2018-07-06 17:53:35 +0100119};
120
121template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000122const GemmImplementation<int8_t, int32_t> *gemm_implementation_list<int8_t, int32_t>() {
David Manselle39334c2018-07-06 17:53:35 +0100123 return gemm_s8_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000124}
125
David Manselle39334c2018-07-06 17:53:35 +0100126/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100127template UniqueGemmCommon<int8_t, int32_t> gemm<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
128template KernelDescription get_gemm_method<int8_t, int32_t, Nothing>(const GemmArgs &args, const Nothing &);
129template std::vector<KernelDescription> get_compatible_kernels<int8_t, int32_t, Nothing> (const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100130
Pablo Telloeb82fd22018-02-23 13:43:50 +0000131} // namespace arm_gemm
132
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100133#endif // __aarch64__