blob: d94814fb4c6b690484943f5fe5bf832f76e68ec4 [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Michalis Spyrou778b95c2021-04-20 12:15:52 +01002 * Copyright (c) 2017-2021 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"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000027#include "gemm_hybrid_indirect.hpp"
David Manselle39334c2018-07-06 17:53:35 +010028#include "gemm_implementation.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000029#include "gemm_interleaved.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 Pinitasc0b6f762020-11-02 01:37:17 +000034#include "kernels/a64_gemv_fp32_mla_32.hpp"
35#include "kernels/a64_hybrid_fp32_mla_6x16.hpp"
36#include "kernels/a64_hybrid_fp32_mla_8x4.hpp"
37#include "kernels/a64_sgemm_8x12.hpp"
Michalis Spyrou778b95c2021-04-20 12:15:52 +010038#include "kernels/a64_sgemm_8x6.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000039#include "kernels/a64_smallK_hybrid_fp32_mla_6x4.hpp"
40#include "kernels/a64_smallK_hybrid_fp32_mla_8x4.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000041
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000042#include "kernels/sve_gemv_fp32_mla_8VL.hpp"
43#include "kernels/sve_hybrid_fp32_mla_6x4VL.hpp"
44#include "kernels/sve_hybrid_fp32_mla_8x1VL.hpp"
45#include "kernels/sve_interleaved_fp32_mla_8x3VL.hpp"
46#include "kernels/sve_interleaved_fp32_mmla_8x3VL.hpp"
47#include "kernels/sve_smallK_hybrid_fp32_mla_8x1VL.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{
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000053// GEMV cases - starting with 'gemv_batched' wrapper to turn batched GEMV into GEMM.
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000054{
55 GemmMethod::GEMV_BATCHED,
56 "gemv_batched",
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000057 [](const GemmArgs &args) { return args._Msize==1 && args._nbatches>1 && !args._indirect_input; },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000058 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010059 [](const GemmArgs &args) { return new GemvBatched<float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000060},
61#ifdef __aarch64__
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000062#ifdef __ARM_FEATURE_SVE
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010063{
64 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000065 "sve_gemv_fp32_mla_8VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +000066 [](const GemmArgs &args) { return args._ci->has_sve() && args._Msize==1 && args._nbatches==1 && !args._indirect_input; },
67 [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN; },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000068 [](const GemmArgs &args) { return new GemvPretransposed<cls_sve_gemv_fp32_mla_8VL, float, float>(args); }
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010069},
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000070#endif
71{
72 GemmMethod::GEMM_HYBRID,
73 "a64_gemv_fp32_mla_32",
74 [](const GemmArgs &args) { return args._Msize==1 && args._nbatches==1 && !args._indirect_input; },
75 nullptr,
76 [](const GemmArgs &args) { return new GemvPretransposed<cls_a64_gemv_fp32_mla_32, float, float>(args); }
77},
78
79// MMLA next due to higher throughput (SVE only)
80#if defined(__ARM_FEATURE_SVE) && defined(MMLA_FP32)
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010081{
82 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000083 "sve_interleaved_fp32_mmla_8x3VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +000084 [](const GemmArgs &args) { return args._ci->has_sve() && (args._Ksize>4); },
85 [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN; },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000086 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_fp32_mmla_8x3VL, float, float>(args); }
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010087},
88#endif // __ARM_FEATURE_SVE && MMLA_FP32
89
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000090#ifdef __ARM_FEATURE_SVE
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000091// SVE smallk / hybrid methods
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000092{
93 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000094 "sve_smallK_hybrid_fp32_mla_8x1VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +000095 [](const GemmArgs &args) { return args._ci->has_sve() && args._Ksize <= 24 && !args._indirect_input; },
96 [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN; },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000097 [](const GemmArgs &args) { return new GemmHybrid<cls_sve_smallK_hybrid_fp32_mla_8x1VL, float, float>(args); }
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000098},
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000099{
100 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000101 "sve_hybrid_fp32_mla_8x1VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000102 [](const GemmArgs &args) { return args._ci->has_sve(); },
103 [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN && (args._Nsize < 12); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000104 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_fp32_mla_8x1VL, float, float>(args); }
105},
106{
107 GemmMethod::GEMM_HYBRID,
108 "sve_hybrid_fp32_mla_6x4VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000109 [](const GemmArgs &args) { return args._ci->has_sve(); },
110 [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN && (((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8))); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000111 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_sve_hybrid_fp32_mla_6x4VL, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000112},
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000113#endif // __ARM_FEATURE_SVE
Michalis Spyrou778b95c2021-04-20 12:15:52 +0100114// Cortex-A35 specific kernel - use for any problem on A35, and never in any other cases.
115{
116 GemmMethod::GEMM_INTERLEAVED,
117 "a64_sgemm_8x6",
118 nullptr,
119 [](const GemmArgs &args) { return args._ci->get_cpu_model() == CPUModel::A35; },
120 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_sgemm_8x6, float, float>(args); }
121},
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000122// Arm® Neon™ hybrid methods
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000123{
124 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000125 "a64_smallK_hybrid_fp32_mla_8x4",
126 [](const GemmArgs &args) { return args._Ksize <= 8 && (args._Nsize % 4)==0 && !args._indirect_input; },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100127 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000128 [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_fp32_mla_8x4, float, float>(args); }
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100129},
130{
131 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000132 "a64_smallK_hybrid_fp32_mla_6x4",
133 [](const GemmArgs &args) { return (args._Ksize > 8 && args._Ksize <= 16) && (args._Nsize % 4)==0 && !args._indirect_input; },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100134 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000135 [](const GemmArgs &args) { return new GemmHybrid<cls_a64_smallK_hybrid_fp32_mla_6x4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000136},
137{
Georgios Pinitas14613832019-03-01 19:07:11 +0000138 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000139 "a64_hybrid_fp32_mla_8x4",
140 nullptr,
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000141 [](const GemmArgs &args) { return (args._Nsize < 12); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000142 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp32_mla_8x4, float, float>(args); }
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000143},
David Mansell318c9f42020-07-08 13:28:45 +0100144GemmImplementation<float, float>::with_estimate(
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000145 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000146 "a64_hybrid_fp32_mla_6x16",
147 nullptr,
148 [](const GemmArgs &args) { return GemmHybridIndirect<cls_a64_hybrid_fp32_mla_6x16, float, float>::estimate_cycles(args, cls_a64_hybrid_fp32_mla_6x16::get_performance_parameters(args._ci)); },
149 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp32_mla_6x16, float, float>(args); }
David Mansell318c9f42020-07-08 13:28:45 +0100150),
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000151#ifdef __ARM_FEATURE_SVE
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100152{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000153 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000154 "sve_interleaved_fp32_mla_8x3VL",
Pablo Marquez Telloa50f1932021-03-08 17:27:05 +0000155 [](const GemmArgs &args) { return args._ci->has_sve() && (args._Ksize>4); },
156 [](const GemmArgs &args) { return args._ci->get_cpu_model() != CPUModel::KLEIN; },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000157 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_fp32_mla_8x3VL, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000158},
159#endif // __ARM_FEATURE_SVE
David Mansell318c9f42020-07-08 13:28:45 +0100160GemmImplementation<float, float>::with_estimate(
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000161 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000162 "a64_sgemm_8x12",
Gian Marco Iodice463f9762020-05-19 14:12:27 +0100163 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000164 [](const GemmArgs &args) { return GemmInterleaved<cls_a64_sgemm_8x12, float, float>::estimate_cycles(args, cls_a64_sgemm_8x12::get_performance_parameters(args._ci)); },
165 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_sgemm_8x12, float, float>(args); }
David Mansell318c9f42020-07-08 13:28:45 +0100166),
David Manselle39334c2018-07-06 17:53:35 +0100167#endif // __aarch64__
168
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000169#ifdef __arm__
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100170{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000171 GemmMethod::GEMM_INTERLEAVED,
172 "sgemm_8x6",
173 nullptr,
174 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100175 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000176},
177#endif // __arm__
178{
179 GemmMethod::DEFAULT,
180 "",
181 nullptr,
182 nullptr,
183 nullptr
184}
David Manselle39334c2018-07-06 17:53:35 +0100185};
186
187/* Templated function to return this list. */
188template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000189const GemmImplementation<float, float> *gemm_implementation_list<float, float>() {
190 return gemm_fp32_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000191}
192
David Manselle39334c2018-07-06 17:53:35 +0100193/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100194template UniqueGemmCommon<float, float> gemm<float, float, Nothing>(const GemmArgs &args, const Nothing &);
195template KernelDescription get_gemm_method<float, float, Nothing>(const GemmArgs &args, const Nothing &);
196template std::vector<KernelDescription> get_compatible_kernels<float, float, Nothing> (const GemmArgs &args, const Nothing &);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000197
Georgios Pinitas14613832019-03-01 19:07:11 +0000198} // namespace arm_gemm