blob: 96e3ce832cea4ac970e4ce414e04250457b4ddc7 [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"
29#include "gemm_native.hpp"
David Mansellce8f6052018-05-17 18:51:26 +010030#include "gemv_batched.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000031#include "gemv_native_transposed.hpp"
32#include "gemv_pretransposed.hpp"
33
Anthony Barbier5f707732018-07-03 16:22:02 +010034#include "kernels/a32_sgemm_8x6.hpp"
Georgios Pinitas14613832019-03-01 19:07:11 +000035#include "kernels/a64_hybrid_fp32_mla_16x4.hpp"
Michalis Spyrou71ac9032019-11-14 14:31:44 +000036#include "kernels/a64_hybrid_fp32_mla_4x8.hpp"
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010037#include "kernels/a64_native_fp32_mla_16x4.hpp"
38#include "kernels/a64_smallK_hybrid_fp32_mla_4x6.hpp"
39#include "kernels/a64_smallK_hybrid_fp32_mla_4x8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000040#include "kernels/a64_sgemm_12x8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000041#include "kernels/a64_sgemv_pretransposed.hpp"
42#include "kernels/a64_sgemv_trans.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000043
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000044#include "kernels/sve_hybrid_fp32_mla_4VLx4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010045#include "kernels/sve_interleaved_fp32_mla_3VLx8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000046#include "kernels/sve_native_fp32_mla_4VLx4.hpp"
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000047#include "kernels/sve_smallK_hybrid_fp32_mla_1VLx8.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010048
Anthony Barbier5f707732018-07-03 16:22:02 +010049namespace arm_gemm {
50
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000051static const GemmImplementation<float, float> gemm_fp32_methods[] =
52{
53{
54 GemmMethod::GEMV_BATCHED,
55 "gemv_batched",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010056 [](const GemmArgs &args) { return (args._Msize==1) && (args._nbatches>1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000057 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010058 [](const GemmArgs &args) { return new GemvBatched<float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000059},
60#ifdef __aarch64__
61{
62 GemmMethod::GEMV_PRETRANSPOSED,
63 "sgemv_pretransposed",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010064 [](const GemmArgs &args) { return (args._Msize==1 && args._pretransposed_hint && args._nbatches==1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000065 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010066 [](const GemmArgs &args) { return new GemvPretransposed<sgemv_pretransposed, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000067},
68{
69 GemmMethod::GEMV_NATIVE_TRANSPOSED,
70 "sgemv_trans",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010071 [](const GemmArgs &args) { return (args._Msize==1 && !args._trA && !args._trB && args._nbatches==1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000072 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010073 [](const GemmArgs &args) { return new GemvNativeTransposed<sgemv_trans, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000074},
David Manselle39334c2018-07-06 17:53:35 +010075
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000076#ifdef __ARM_FEATURE_SVE
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000077// SVE smallk / native / hybrid methods
78{
79 GemmMethod::GEMM_HYBRID,
80 "smallK_hybrid_fp32_mla_1VLx8",
81 [](const GemmArgs &args) { return (args._Ksize <= 24) && !args._trA && args._pretransposed_hint; },
82 nullptr,
83 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_1VLx8, float, float>(args); }
84},
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000085{
86 GemmMethod::GEMM_HYBRID,
87 "hybrid_fp32_mla_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010088 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
89 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
90 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000091},
92{
93 GemmMethod::GEMM_NATIVE,
94 "native_fp32_mla_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010095 [](const GemmArgs &args) { return (args._Ksize>4 && !args._trA && !args._trB); },
96 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
97 [](const GemmArgs &args) { return new GemmNative<native_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000098},
99#endif // __ARM_FEATURE_SVE
Pablo Telloeb82fd22018-02-23 13:43:50 +0000100
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000101// NEON native / hybrid methods
102{
103 GemmMethod::GEMM_HYBRID,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100104 "smallK_hybrid_fp32_mla_4x8",
105 [](const GemmArgs &args) { return (args._Ksize <= 8) && (args._Nsize % 4)==0 && !args._trA && args._pretransposed_hint; },
106 nullptr,
107 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x8, float, float>(args); }
108},
109{
110 GemmMethod::GEMM_HYBRID,
111 "smallK_hybrid_fp32_mla_4x6",
112 [](const GemmArgs &args) { return (args._Ksize > 8) && (args._Ksize <= 16) && (args._Nsize % 4)==0 && !args._trA && args._pretransposed_hint; },
113 nullptr,
114 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000115},
116{
Georgios Pinitas14613832019-03-01 19:07:11 +0000117 GemmMethod::GEMM_HYBRID,
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000118 "hybrid_fp32_mla_4x8_normal",
119 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
120 [](const GemmArgs &args) { return (args._Nsize < 12); },
121 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4x8, float, float>(args); }
122},
123{
124 GemmMethod::GEMM_HYBRID,
Georgios Pinitas94672fb2020-01-22 18:36:27 +0000125 "hybrid_fp32_mla_16x4_normal",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100126 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000127 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || (args._Msize < 16) || (args._nmulti > 1); },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100128 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_16x4, float, float>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +0000129},
130{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000131 GemmMethod::GEMM_NATIVE,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100132 "native_fp32_mla_16x4",
133 [](const GemmArgs &args) { return (args._Ksize>4 && (args._Nsize % 16)==0 && !args._trA && !args._trB); },
134 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
135 [](const GemmArgs &args) { return new GemmNative<native_fp32_mla_16x4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000136},
Pablo Telloeb82fd22018-02-23 13:43:50 +0000137
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000138#ifdef __ARM_FEATURE_SVE
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100139{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000140 GemmMethod::GEMM_INTERLEAVED,
141 "interleaved_fp32_mla_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100142 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000143 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100144 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp32_mla_3VLx8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000145},
146#endif // __ARM_FEATURE_SVE
147{
148 GemmMethod::GEMM_INTERLEAVED,
149 "sgemm_12x8",
150 nullptr,
151 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100152 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000153},
David Manselle39334c2018-07-06 17:53:35 +0100154#endif // __aarch64__
155
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000156#ifdef __arm__
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100157{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000158 GemmMethod::GEMM_INTERLEAVED,
159 "sgemm_8x6",
160 nullptr,
161 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100162 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000163},
164#endif // __arm__
165{
166 GemmMethod::DEFAULT,
167 "",
168 nullptr,
169 nullptr,
170 nullptr
171}
David Manselle39334c2018-07-06 17:53:35 +0100172};
173
174/* Templated function to return this list. */
175template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000176const GemmImplementation<float, float> *gemm_implementation_list<float, float>() {
177 return gemm_fp32_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000178}
179
David Manselle39334c2018-07-06 17:53:35 +0100180/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100181template UniqueGemmCommon<float, float> gemm<float, float, Nothing>(const GemmArgs &args, const Nothing &);
182template KernelDescription get_gemm_method<float, float, Nothing>(const GemmArgs &args, const Nothing &);
183template std::vector<KernelDescription> get_compatible_kernels<float, float, Nothing> (const GemmArgs &args, const Nothing &);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000184
Georgios Pinitas14613832019-03-01 19:07:11 +0000185} // namespace arm_gemm