blob: ddb438f06c2a2bd2a85a5f6458ad1a9fffe03bde [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#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_pretransposed_2d.hpp"
David Mansellce8f6052018-05-17 18:51:26 +010030#include "gemv_batched.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000031#include "gemv_pretransposed.hpp"
32
Anthony Barbier5f707732018-07-03 16:22:02 +010033#include "kernels/a32_sgemm_8x6.hpp"
Georgios Pinitas14613832019-03-01 19:07:11 +000034#include "kernels/a64_hybrid_fp32_mla_16x4.hpp"
Michalis Spyrou71ac9032019-11-14 14:31:44 +000035#include "kernels/a64_hybrid_fp32_mla_4x8.hpp"
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010036#include "kernels/a64_smallK_hybrid_fp32_mla_4x6.hpp"
37#include "kernels/a64_smallK_hybrid_fp32_mla_4x8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000038#include "kernels/a64_sgemm_12x8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000039#include "kernels/a64_sgemv_pretransposed.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000040
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000041#include "kernels/sve_hybrid_fp32_mla_4VLx4.hpp"
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010042#include "kernels/sve_hybrid_fp32_mmla_4VLx4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010043#include "kernels/sve_interleaved_fp32_mla_3VLx8.hpp"
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010044#include "kernels/sve_interleaved_fp32_mmla_3VLx8.hpp"
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000045#include "kernels/sve_smallK_hybrid_fp32_mla_1VLx8.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010046
Anthony Barbier5f707732018-07-03 16:22:02 +010047namespace arm_gemm {
48
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000049static const GemmImplementation<float, float> gemm_fp32_methods[] =
50{
51{
52 GemmMethod::GEMV_BATCHED,
53 "gemv_batched",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010054 [](const GemmArgs &args) { return (args._Msize==1) && (args._nbatches>1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000055 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010056 [](const GemmArgs &args) { return new GemvBatched<float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000057},
58#ifdef __aarch64__
59{
60 GemmMethod::GEMV_PRETRANSPOSED,
61 "sgemv_pretransposed",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010062 [](const GemmArgs &args) { return (args._Msize==1 && args._nbatches==1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000063 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010064 [](const GemmArgs &args) { return new GemvPretransposed<sgemv_pretransposed, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000065},
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010066#if defined(__ARM_FEATURE_SVE) && defined(MMLA_FP32)
67{
68 GemmMethod::GEMM_HYBRID,
69 "hybrid_fp32_mmla_4VLx4",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010070 [](const GemmArgs &args) { return (args._Ksize >= 4); },
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010071 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
72 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mmla_4VLx4, float, float>(args); }
73},
74{
75 GemmMethod::GEMM_INTERLEAVED,
76 "interleaved_fp32_mmla_3VLx8",
77 [](const GemmArgs &args) { return (args._Ksize>4); },
78 nullptr,
79 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp32_mmla_3VLx8, float, float>(args); }
80},
81#endif // __ARM_FEATURE_SVE && MMLA_FP32
82
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000083#ifdef __ARM_FEATURE_SVE
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010084// SVE smallk / hybrid methods
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000085{
86 GemmMethod::GEMM_HYBRID,
87 "smallK_hybrid_fp32_mla_1VLx8",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010088 [](const GemmArgs &args) { return (args._Ksize <= 24); },
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000089 nullptr,
90 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_1VLx8, float, float>(args); }
91},
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000092{
93 GemmMethod::GEMM_HYBRID,
94 "hybrid_fp32_mla_4VLx4",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010095 [](const GemmArgs &args) { return (args._Ksize >= 4); },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010096 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
97 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000098},
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000099#endif // __ARM_FEATURE_SVE
Pablo Telloeb82fd22018-02-23 13:43:50 +0000100
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +0100101// NEON hybrid methods
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000102{
103 GemmMethod::GEMM_HYBRID,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100104 "smallK_hybrid_fp32_mla_4x8",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +0100105 [](const GemmArgs &args) { return (args._Ksize <= 8) && (args._Nsize % 4)==0; },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100106 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",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +0100112 [](const GemmArgs &args) { return (args._Ksize > 8) && (args._Ksize <= 16) && (args._Nsize % 4)==0; },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100113 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",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +0100119 [](const GemmArgs &args) { return (args._Ksize >= 4); },
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000120 [](const GemmArgs &args) { return (args._Nsize < 12); },
121 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4x8, float, float>(args); }
122},
David Mansell318c9f42020-07-08 13:28:45 +0100123GemmImplementation<float, float>::with_estimate(
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000124 GemmMethod::GEMM_HYBRID,
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +0100125 "hybrid_fp32_mla_16x4",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +0100126 [](const GemmArgs &args) { return (args._Ksize >= 4); },
David Mansell318c9f42020-07-08 13:28:45 +0100127 [](const GemmArgs &args) { return GemmHybrid<hybrid_fp32_mla_16x4, float, float>::estimate_cycles(args, hybrid_fp32_mla_16x4::get_performance_parameters(args._ci)); },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100128 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_16x4, float, float>(args); }
David Mansell318c9f42020-07-08 13:28:45 +0100129),
Pablo Telloeb82fd22018-02-23 13:43:50 +0000130
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000131#ifdef __ARM_FEATURE_SVE
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100132{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000133 GemmMethod::GEMM_INTERLEAVED,
134 "interleaved_fp32_mla_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100135 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000136 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100137 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp32_mla_3VLx8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000138},
139#endif // __ARM_FEATURE_SVE
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +0100140// Pretranposed, 2D split
David Mansell318c9f42020-07-08 13:28:45 +0100141GemmImplementation<float, float>::with_estimate(
Joseph Dobson6f8b17d2020-02-11 19:32:11 +0000142 GemmMethod::GEMM_INTERLEAVED_2D,
Gian Marco Iodice463f9762020-05-19 14:12:27 +0100143 "sgemm_12x8_2d",
144 nullptr,
David Mansell318c9f42020-07-08 13:28:45 +0100145 [](const GemmArgs &args) { return GemmInterleavedPretransposed2d<sgemm_12x8, float, float>::estimate_cycles(args, sgemm_12x8::get_performance_parameters(args._ci)); },
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +0100146 [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<sgemm_12x8, float, float>(args); }
David Mansell318c9f42020-07-08 13:28:45 +0100147),
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +0100148// 1D split (with pretransposed or not)
David Mansell318c9f42020-07-08 13:28:45 +0100149GemmImplementation<float, float>::with_estimate(
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000150 GemmMethod::GEMM_INTERLEAVED,
Gian Marco Iodice463f9762020-05-19 14:12:27 +0100151 "sgemm_12x8_1d",
152 nullptr,
David Mansell318c9f42020-07-08 13:28:45 +0100153 [](const GemmArgs &args) { return GemmInterleaved<sgemm_12x8, float, float>::estimate_cycles(args, sgemm_12x8::get_performance_parameters(args._ci)); },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100154 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, float, float>(args); }
David Mansell318c9f42020-07-08 13:28:45 +0100155),
David Manselle39334c2018-07-06 17:53:35 +0100156#endif // __aarch64__
157
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000158#ifdef __arm__
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100159{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000160 GemmMethod::GEMM_INTERLEAVED,
161 "sgemm_8x6",
162 nullptr,
163 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100164 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000165},
166#endif // __arm__
167{
168 GemmMethod::DEFAULT,
169 "",
170 nullptr,
171 nullptr,
172 nullptr
173}
David Manselle39334c2018-07-06 17:53:35 +0100174};
175
176/* Templated function to return this list. */
177template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000178const GemmImplementation<float, float> *gemm_implementation_list<float, float>() {
179 return gemm_fp32_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000180}
181
David Manselle39334c2018-07-06 17:53:35 +0100182/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100183template UniqueGemmCommon<float, float> gemm<float, float, Nothing>(const GemmArgs &args, const Nothing &);
184template KernelDescription get_gemm_method<float, float, Nothing>(const GemmArgs &args, const Nothing &);
185template std::vector<KernelDescription> get_compatible_kernels<float, float, Nothing> (const GemmArgs &args, const Nothing &);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000186
Georgios Pinitas14613832019-03-01 19:07:11 +0000187} // namespace arm_gemm