blob: 7f171ec15a8ebae077ff397d0312dd2af40eb9dd [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 Pinitas421405b2018-10-26 19:05:32 +010047
Anthony Barbier5f707732018-07-03 16:22:02 +010048namespace arm_gemm {
49
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000050static const GemmImplementation<float, float> gemm_fp32_methods[] =
51{
52{
53 GemmMethod::GEMV_BATCHED,
54 "gemv_batched",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010055 [](const GemmArgs &args) { return (args._Msize==1) && (args._nbatches>1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000056 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010057 [](const GemmArgs &args) { return new GemvBatched<float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000058},
59#ifdef __aarch64__
60{
61 GemmMethod::GEMV_PRETRANSPOSED,
62 "sgemv_pretransposed",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010063 [](const GemmArgs &args) { return (args._Msize==1 && args._pretransposed_hint && args._nbatches==1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000064 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010065 [](const GemmArgs &args) { return new GemvPretransposed<sgemv_pretransposed, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000066},
67{
68 GemmMethod::GEMV_NATIVE_TRANSPOSED,
69 "sgemv_trans",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010070 [](const GemmArgs &args) { return (args._Msize==1 && !args._trA && !args._trB && args._nbatches==1); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000071 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010072 [](const GemmArgs &args) { return new GemvNativeTransposed<sgemv_trans, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000073},
David Manselle39334c2018-07-06 17:53:35 +010074
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000075#ifdef __ARM_FEATURE_SVE
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010076// SVE native / hybrid methods
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000077{
78 GemmMethod::GEMM_HYBRID,
79 "hybrid_fp32_mla_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010080 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
81 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
82 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000083},
84{
85 GemmMethod::GEMM_NATIVE,
86 "native_fp32_mla_4VLx4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010087 [](const GemmArgs &args) { return (args._Ksize>4 && !args._trA && !args._trB); },
88 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
89 [](const GemmArgs &args) { return new GemmNative<native_fp32_mla_4VLx4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000090},
91#endif // __ARM_FEATURE_SVE
Pablo Telloeb82fd22018-02-23 13:43:50 +000092
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000093// NEON native / hybrid methods
94{
95 GemmMethod::GEMM_HYBRID,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010096 "smallK_hybrid_fp32_mla_4x8",
97 [](const GemmArgs &args) { return (args._Ksize <= 8) && (args._Nsize % 4)==0 && !args._trA && args._pretransposed_hint; },
98 nullptr,
99 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x8, float, float>(args); }
100},
101{
102 GemmMethod::GEMM_HYBRID,
103 "smallK_hybrid_fp32_mla_4x6",
104 [](const GemmArgs &args) { return (args._Ksize > 8) && (args._Ksize <= 16) && (args._Nsize % 4)==0 && !args._trA && args._pretransposed_hint; },
105 nullptr,
106 [](const GemmArgs &args) { return new GemmHybrid<smallK_hybrid_fp32_mla_4x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000107},
108{
Georgios Pinitas14613832019-03-01 19:07:11 +0000109 GemmMethod::GEMM_HYBRID,
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000110 "hybrid_fp32_mla_4x8_normal",
111 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
112 [](const GemmArgs &args) { return (args._Nsize < 12); },
113 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_4x8, float, float>(args); }
114},
115{
116 GemmMethod::GEMM_HYBRID,
Georgios Pinitas14613832019-03-01 19:07:11 +0000117 "hybrid_fp32_mla_16x4",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100118 [](const GemmArgs &args) { return (args._Ksize >= 4) && !args._trA && args._pretransposed_hint; },
Michalis Spyrou71ac9032019-11-14 14:31:44 +0000119 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || (args._Msize < 16) || (args._nmulti > 1); },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100120 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp32_mla_16x4, float, float>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +0000121},
122{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000123 GemmMethod::GEMM_NATIVE,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100124 "native_fp32_mla_16x4",
125 [](const GemmArgs &args) { return (args._Ksize>4 && (args._Nsize % 16)==0 && !args._trA && !args._trB); },
126 [](const GemmArgs &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
127 [](const GemmArgs &args) { return new GemmNative<native_fp32_mla_16x4, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000128},
Pablo Telloeb82fd22018-02-23 13:43:50 +0000129
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000130#ifdef __ARM_FEATURE_SVE
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100131{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000132 GemmMethod::GEMM_INTERLEAVED,
133 "interleaved_fp32_mla_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100134 [](const GemmArgs &args) { return (args._Ksize>4); },
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000135 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100136 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp32_mla_3VLx8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000137},
138#endif // __ARM_FEATURE_SVE
139{
140 GemmMethod::GEMM_INTERLEAVED,
141 "sgemm_12x8",
142 nullptr,
143 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100144 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000145},
David Manselle39334c2018-07-06 17:53:35 +0100146#endif // __aarch64__
147
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000148#ifdef __arm__
Georgios Pinitascfa2bba2019-06-27 17:00:52 +0100149{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000150 GemmMethod::GEMM_INTERLEAVED,
151 "sgemm_8x6",
152 nullptr,
153 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100154 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, float, float>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000155},
156#endif // __arm__
157{
158 GemmMethod::DEFAULT,
159 "",
160 nullptr,
161 nullptr,
162 nullptr
163}
David Manselle39334c2018-07-06 17:53:35 +0100164};
165
166/* Templated function to return this list. */
167template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000168const GemmImplementation<float, float> *gemm_implementation_list<float, float>() {
169 return gemm_fp32_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000170}
171
David Manselle39334c2018-07-06 17:53:35 +0100172/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100173template UniqueGemmCommon<float, float> gemm<float, float, Nothing>(const GemmArgs &args, const Nothing &);
174template KernelDescription get_gemm_method<float, float, Nothing>(const GemmArgs &args, const Nothing &);
175template std::vector<KernelDescription> get_compatible_kernels<float, float, Nothing> (const GemmArgs &args, const Nothing &);
Pablo Telloeb82fd22018-02-23 13:43:50 +0000176
Georgios Pinitas14613832019-03-01 19:07:11 +0000177} // namespace arm_gemm