blob: 8bef2b7bae34ed8ad8a58f290519d188a073231d [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Michalis Spyrou71ac9032019-11-14 14:31:44 +00002 * 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#include "arm_gemm.hpp"
25#include "gemm_common.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000026#include "gemm_hybrid.hpp"
David Manselle39334c2018-07-06 17:53:35 +010027#include "gemm_implementation.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000028#include "gemm_interleaved.hpp"
Joseph Dobson6f8b17d2020-02-11 19:32:11 +000029#include "gemm_interleaved_2d.hpp"
30#include "gemm_interleaved_pretransposed_2d.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000031#include "gemm_native.hpp"
David Mansellce8f6052018-05-17 18:51:26 +010032#include "gemv_batched.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000033#include "gemv_native_transposed.hpp"
34#include "gemv_pretransposed.hpp"
35
Anthony Barbier5f707732018-07-03 16:22:02 +010036#include "kernels/a32_sgemm_8x6.hpp"
Georgios Pinitas14613832019-03-01 19:07:11 +000037#include "kernels/a64_hybrid_fp32_mla_16x4.hpp"
Michalis Spyrou71ac9032019-11-14 14:31:44 +000038#include "kernels/a64_hybrid_fp32_mla_4x8.hpp"
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010039#include "kernels/a64_native_fp32_mla_16x4.hpp"
40#include "kernels/a64_smallK_hybrid_fp32_mla_4x6.hpp"
41#include "kernels/a64_smallK_hybrid_fp32_mla_4x8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000042#include "kernels/a64_sgemm_12x8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000043#include "kernels/a64_sgemv_pretransposed.hpp"
44#include "kernels/a64_sgemv_trans.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000045
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000046#include "kernels/sve_hybrid_fp32_mla_4VLx4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010047#include "kernels/sve_interleaved_fp32_mla_3VLx8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000048#include "kernels/sve_native_fp32_mla_4VLx4.hpp"
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000049#include "kernels/sve_smallK_hybrid_fp32_mla_1VLx8.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010050
Anthony Barbier5f707732018-07-03 16:22:02 +010051namespace arm_gemm {
52
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000053static const GemmImplementation<float, float> gemm_fp32_methods[] =
54{
55{
56 GemmMethod::GEMV_BATCHED,
57 "gemv_batched",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010058 [](const GemmArgs &args) { return (args._Msize==1) && (args._nbatches>1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000059 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010060 [](const GemmArgs &args) { return new GemvBatched<float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000061},
62#ifdef __aarch64__
63{
64 GemmMethod::GEMV_PRETRANSPOSED,
65 "sgemv_pretransposed",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010066 [](const GemmArgs &args) { return (args._Msize==1 && args._pretransposed_hint && args._nbatches==1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000067 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010068 [](const GemmArgs &args) { return new GemvPretransposed<sgemv_pretransposed, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000069},
70{
71 GemmMethod::GEMV_NATIVE_TRANSPOSED,
72 "sgemv_trans",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010073 [](const GemmArgs &args) { return (args._Msize==1 && !args._trA && !args._trB && args._nbatches==1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000074 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010075 [](const GemmArgs &args) { return new GemvNativeTransposed<sgemv_trans, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000076},
David Manselle39334c2018-07-06 17:53:35 +010077
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000078#ifdef __ARM_FEATURE_SVE
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000079// SVE smallk / native / hybrid methods
80{
81 GemmMethod::GEMM_HYBRID,
82 "smallK_hybrid_fp32_mla_1VLx8",
83 [](const GemmArgs &args) { return (args._Ksize <= 24) && !args._trA && args._pretransposed_hint; },
84 nullptr,
85 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_1VLx8, float, float>(args); }
86},
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000087{
88 GemmMethod::GEMM_HYBRID,
89 "hybrid_fp32_mla_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010090 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
91 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
92 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000093},
94{
95 GemmMethod::GEMM_NATIVE,
96 "native_fp32_mla_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010097 [](const GemmArgs &args) { return (args._Ksize>4 && !args._trA && !args._trB); },
98 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
99 [](const GemmArgs &args) { return new GemmNative<native_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000100},
101#endif // __ARM_FEATURE_SVE
Pablo Telloeb82fd22018-02-23 13:43:50 +0000102
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000103// NEON native / hybrid methods
104{
105 GemmMethod::GEMM_HYBRID,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100106 "smallK_hybrid_fp32_mla_4x8",
107 [](const GemmArgs &args) { return (args._Ksize <= 8) && (args._Nsize % 4)==0 && !args._trA && args._pretransposed_hint; },
108 nullptr,
109 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x8, float, float>(args); }
110},
111{
112 GemmMethod::GEMM_HYBRID,
113 "smallK_hybrid_fp32_mla_4x6",
114 [](const GemmArgs &args) { return (args._Ksize > 8) && (args._Ksize <= 16) && (args._Nsize % 4)==0 && !args._trA && args._pretransposed_hint; },
115 nullptr,
116 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000117},
118{
Georgios Pinitas14613832019-03-01 19:07:11 +0000119 GemmMethod::GEMM_HYBRID,
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000120 "hybrid_fp32_mla_4x8_normal",
121 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
122 [](const GemmArgs &args) { return (args._Nsize < 12); },
123 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4x8, float, float>(args); }
124},
125{
126 GemmMethod::GEMM_HYBRID,
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000127 "hybrid_fp32_mla_16x4_normal",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100128 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000129 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || (args._Msize < 16) || (args._nmulti > 1); },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100130 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_16x4, float, float>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +0000131},
132{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000133 GemmMethod::GEMM_NATIVE,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100134 "native_fp32_mla_16x4",
135 [](const GemmArgs &args) { return (args._Ksize>4 && (args._Nsize % 16)==0 && !args._trA && !args._trB); },
136 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
137 [](const GemmArgs &args) { return new GemmNative<native_fp32_mla_16x4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000138},
Pablo Telloeb82fd22018-02-23 13:43:50 +0000139
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000140#ifdef __ARM_FEATURE_SVE
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100141{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000142 GemmMethod::GEMM_INTERLEAVED,
143 "interleaved_fp32_mla_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100144 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000145 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100146 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp32_mla_3VLx8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000147},
148#endif // __ARM_FEATURE_SVE
Joseph Dobson6f8b17d2020-02-11 19:32:11 +0000149//Pretranpose, 2D split
150{
151 GemmMethod::GEMM_INTERLEAVED_2D,
Gian Marco Iodice463f9762020-05-19 14:12:27 +0100152 "sgemm_12x8_pretranspose_2d",
Joseph Dobson6f8b17d2020-02-11 19:32:11 +0000153 [](const GemmArgs &args) { return args._pretransposed_hint; },
Gian Marco Iodice463f9762020-05-19 14:12:27 +0100154 [](const GemmArgs &args) { return args._maxthreads >= 8; },
Joseph Dobson6f8b17d2020-02-11 19:32:11 +0000155 [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<sgemm_12x8, float, float>(args); }
156},
157//Tranpose, 2D split, no blockmanager
158{
159 GemmMethod::GEMM_INTERLEAVED_2D,
Gian Marco Iodice463f9762020-05-19 14:12:27 +0100160 "sgemm_12x8_2d",
161 nullptr,
162 [](const GemmArgs &args) { return (!args._pretransposed_hint) && (args._maxthreads >= 8); },
Joseph Dobson6f8b17d2020-02-11 19:32:11 +0000163 [](const GemmArgs &args) { return new GemmInterleaved2d<sgemm_12x8, float, float>(args); }
164},
165//Tranpose, 1D split, with blockmanager
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000166{
167 GemmMethod::GEMM_INTERLEAVED,
Gian Marco Iodice463f9762020-05-19 14:12:27 +0100168 "sgemm_12x8_1d",
169 nullptr,
170 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100171 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000172},
Joseph Dobson6f8b17d2020-02-11 19:32:11 +0000173
David Manselle39334c2018-07-06 17:53:35 +0100174#endif // __aarch64__
175
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000176#ifdef __arm__
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100177{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000178 GemmMethod::GEMM_INTERLEAVED,
179 "sgemm_8x6",
180 nullptr,
181 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100182 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000183},
184#endif // __arm__
185{
186 GemmMethod::DEFAULT,
187 "",
188 nullptr,
189 nullptr,
190 nullptr
191}
David Manselle39334c2018-07-06 17:53:35 +0100192};
193
194/* Templated function to return this list. */
195template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000196const GemmImplementation<float, float> *gemm_implementation_list<float, float>() {
197 return gemm_fp32_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000198}
199
David Manselle39334c2018-07-06 17:53:35 +0100200/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100201template UniqueGemmCommon<float, float> gemm<float, float, Nothing>(const GemmArgs &args, const Nothing &);
202template KernelDescription get_gemm_method<float, float, Nothing>(const GemmArgs &args, const Nothing &);
203template std::vector<KernelDescription> get_compatible_kernels<float, float, Nothing> (const GemmArgs &args, const Nothing &);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000204
Georgios Pinitas14613832019-03-01 19:07:11 +0000205} // namespace arm_gemm