blob: cf91ee0652def216fdb9fd368b138e529bb214d6 [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Georgios Pinitas7cd26d42019-01-09 18:35:17 +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#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"
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010036#include "kernels/a64_native_fp32_mla_16x4.hpp"
37#include "kernels/a64_smallK_hybrid_fp32_mla_4x6.hpp"
38#include "kernels/a64_smallK_hybrid_fp32_mla_4x8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000039#include "kernels/a64_sgemm_12x8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000040#include "kernels/a64_sgemv_pretransposed.hpp"
41#include "kernels/a64_sgemv_trans.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000042
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000043#include "kernels/sve_hybrid_fp32_mla_4VLx4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010044#include "kernels/sve_interleaved_fp32_mla_3VLx8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000045#include "kernels/sve_native_fp32_mla_4VLx4.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 Pinitas48b3ef82019-10-14 19:03:09 +010062 [](const GemmArgs &args) { return (args._Msize==1 && args._pretransposed_hint && 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},
66{
67 GemmMethod::GEMV_NATIVE_TRANSPOSED,
68 "sgemv_trans",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010069 [](const GemmArgs &args) { return (args._Msize==1 && !args._trA && !args._trB && args._nbatches==1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000070 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010071 [](const GemmArgs &args) { return new GemvNativeTransposed<sgemv_trans, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000072},
David Manselle39334c2018-07-06 17:53:35 +010073
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000074#ifdef __ARM_FEATURE_SVE
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010075// SVE native / hybrid methods
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000076{
77 GemmMethod::GEMM_HYBRID,
78 "hybrid_fp32_mla_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010079 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
80 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
81 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000082},
83{
84 GemmMethod::GEMM_NATIVE,
85 "native_fp32_mla_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010086 [](const GemmArgs &args) { return (args._Ksize>4 && !args._trA && !args._trB); },
87 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
88 [](const GemmArgs &args) { return new GemmNative<native_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000089},
90#endif // __ARM_FEATURE_SVE
Pablo Telloeb82fd22018-02-23 13:43:50 +000091
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000092// NEON native / hybrid methods
93{
94 GemmMethod::GEMM_HYBRID,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010095 "smallK_hybrid_fp32_mla_4x8",
96 [](const GemmArgs &args) { return (args._Ksize <= 8) && (args._Nsize % 4)==0 && !args._trA && args._pretransposed_hint; },
97 nullptr,
98 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x8, float, float>(args); }
99},
100{
101 GemmMethod::GEMM_HYBRID,
102 "smallK_hybrid_fp32_mla_4x6",
103 [](const GemmArgs &args) { return (args._Ksize > 8) && (args._Ksize <= 16) && (args._Nsize % 4)==0 && !args._trA && args._pretransposed_hint; },
104 nullptr,
105 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000106},
107{
Georgios Pinitas14613832019-03-01 19:07:11 +0000108 GemmMethod::GEMM_HYBRID,
109 "hybrid_fp32_mla_16x4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100110 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
111 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
112 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_16x4, float, float>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +0000113},
114{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000115 GemmMethod::GEMM_NATIVE,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100116 "native_fp32_mla_16x4",
117 [](const GemmArgs &args) { return (args._Ksize>4 && (args._Nsize % 16)==0 && !args._trA && !args._trB); },
118 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
119 [](const GemmArgs &args) { return new GemmNative<native_fp32_mla_16x4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000120},
Pablo Telloeb82fd22018-02-23 13:43:50 +0000121
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000122#ifdef __ARM_FEATURE_SVE
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100123{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000124 GemmMethod::GEMM_INTERLEAVED,
125 "interleaved_fp32_mla_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100126 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000127 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100128 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp32_mla_3VLx8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000129},
130#endif // __ARM_FEATURE_SVE
131{
132 GemmMethod::GEMM_INTERLEAVED,
133 "sgemm_12x8",
134 nullptr,
135 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100136 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000137},
David Manselle39334c2018-07-06 17:53:35 +0100138#endif // __aarch64__
139
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000140#ifdef __arm__
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100141{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000142 GemmMethod::GEMM_INTERLEAVED,
143 "sgemm_8x6",
144 nullptr,
145 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100146 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000147},
148#endif // __arm__
149{
150 GemmMethod::DEFAULT,
151 "",
152 nullptr,
153 nullptr,
154 nullptr
155}
David Manselle39334c2018-07-06 17:53:35 +0100156};
157
158/* Templated function to return this list. */
159template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000160const GemmImplementation<float, float> *gemm_implementation_list<float, float>() {
161 return gemm_fp32_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000162}
163
David Manselle39334c2018-07-06 17:53:35 +0100164/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100165template UniqueGemmCommon<float, float> gemm<float, float, Nothing>(const GemmArgs &args, const Nothing &);
166template KernelDescription get_gemm_method<float, float, Nothing>(const GemmArgs &args, const Nothing &);
167template std::vector<KernelDescription> get_compatible_kernels<float, float, Nothing> (const GemmArgs &args, const Nothing &);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000168
Georgios Pinitas14613832019-03-01 19:07:11 +0000169} // namespace arm_gemm