blob: 91012218e51ee7a5bee41d7c061257dc581a4bd9 [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 */
Pablo Tello99ef8402018-03-20 16:46:55 +000024
25// This can only be built if the target/compiler supports FP16 arguments.
26#ifdef __ARM_FP16_ARGS
Pablo Telloeb82fd22018-02-23 13:43:50 +000027
28#include "arm_gemm.hpp"
29
30#include "gemm_common.hpp"
Georgios Pinitas14613832019-03-01 19:07:11 +000031#include "gemm_hybrid.hpp"
David Manselle39334c2018-07-06 17:53:35 +010032#include "gemm_implementation.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000033#include "gemm_interleaved.hpp"
cfRod534fdea2020-06-25 18:12:25 +010034#include "gemm_interleaved_pretransposed_2d.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000035
Georgios Pinitas14613832019-03-01 19:07:11 +000036#include "kernels/a32_sgemm_8x6.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000037#include "kernels/a64_hgemm_24x8.hpp"
38#include "kernels/a64_sgemm_12x8.hpp"
Georgios Pinitas14613832019-03-01 19:07:11 +000039#include "kernels/sve_hybrid_fp16_mla_4VLx4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010040#include "kernels/sve_interleaved_fp16_mla_3VLx8.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000041
Anthony Barbier5f707732018-07-03 16:22:02 +010042namespace arm_gemm {
43
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000044static const GemmImplementation<__fp16, __fp16> gemm_fp16_methods[] = {
45#if defined(__ARM_FEATURE_SVE)
46{
Georgios Pinitas14613832019-03-01 19:07:11 +000047 GemmMethod::GEMM_HYBRID,
48 "hybrid_fp16_mla_4VLx4",
Georgios Pinitas0cc50ed2020-07-06 19:10:38 +010049 [](const GemmArgs &args) { return (args._Ksize >= 8); },
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010050 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
51 [](const GemmArgs &args) { return new GemmHybrid<hybrid_fp16_mla_4VLx4, __fp16, __fp16>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +000052},
53{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000054 GemmMethod::GEMM_INTERLEAVED,
55 "interleaved_fp16_mla_3VLx8",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010056 [](const GemmArgs &args) { return (args._Ksize > 4); },
Georgios Pinitas14613832019-03-01 19:07:11 +000057 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010058 [](const GemmArgs &args) { return new GemmInterleaved<interleaved_fp16_mla_3VLx8, __fp16, __fp16>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000059},
60#endif
Georgios Pinitas14613832019-03-01 19:07:11 +000061
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000062#if defined(__aarch64__) && (defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) || defined(FP16_KERNELS))
63{
cfRod534fdea2020-06-25 18:12:25 +010064 GemmMethod::GEMM_INTERLEAVED_2D,
65 "hgemm_24x8_2d",
66#ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
67 [](const GemmArgs &args) { return args._ci->has_fp16(); },
68#else
69 nullptr,
70#endif
71 [](const GemmArgs &args) { return args._maxthreads >= 8; },
72 [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<hgemm_24x8, __fp16, __fp16>(args); }
73},
74{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000075 GemmMethod::GEMM_INTERLEAVED,
cfRod534fdea2020-06-25 18:12:25 +010076 "hgemm_24x8_1d",
David Manselle39334c2018-07-06 17:53:35 +010077#ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010078 [](const GemmArgs &args) { return args._ci->has_fp16(); },
David Manselle39334c2018-07-06 17:53:35 +010079#else
Georgios Pinitas14613832019-03-01 19:07:11 +000080 nullptr,
David Manselle39334c2018-07-06 17:53:35 +010081#endif
Georgios Pinitas14613832019-03-01 19:07:11 +000082 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010083 [](const GemmArgs &args) { return new GemmInterleaved<hgemm_24x8, __fp16, __fp16>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000084},
cfRod534fdea2020-06-25 18:12:25 +010085
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010086#endif // aarch64 && FP16
Georgios Pinitas14613832019-03-01 19:07:11 +000087#ifdef __aarch64__
cfRod534fdea2020-06-25 18:12:25 +010088//Pretranpose, 2D split
89{
90 GemmMethod::GEMM_INTERLEAVED_2D,
91 "sgemm_12x8_2d",
92 nullptr,
93 [](const GemmArgs &args) { return args._maxthreads >= 8; },
94 [](const GemmArgs &args) { return new GemmInterleavedPretransposed2d<sgemm_12x8, __fp16, __fp16>(args); }
95},
96//Tranpose, 1D split, with blockmanager
Georgios Pinitas14613832019-03-01 19:07:11 +000097{
98 GemmMethod::GEMM_INTERLEAVED,
cfRod534fdea2020-06-25 18:12:25 +010099 "sgemm_12x8_1d",
Georgios Pinitas14613832019-03-01 19:07:11 +0000100 nullptr,
101 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100102 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_12x8, __fp16, __fp16>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +0000103},
104#elif defined(__arm__)
Georgios Pinitasa41c54b2019-01-30 18:16:43 +0000105{
106 GemmMethod::GEMM_INTERLEAVED,
107 "sgemm_8x6",
Georgios Pinitas14613832019-03-01 19:07:11 +0000108 nullptr,
109 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100110 [](const GemmArgs &args) { return new GemmInterleaved<sgemm_8x6, __fp16, __fp16>(args); }
Georgios Pinitasa41c54b2019-01-30 18:16:43 +0000111},
Georgios Pinitas14613832019-03-01 19:07:11 +0000112#else // not AArch64 or AArch32
113# error Unknown Architecture
Georgios Pinitasa41c54b2019-01-30 18:16:43 +0000114#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000115{
116 GemmMethod::DEFAULT,
117 "",
118 nullptr,
119 nullptr,
120 nullptr,
121}
David Manselle39334c2018-07-06 17:53:35 +0100122};
123
124template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000125const GemmImplementation<__fp16, __fp16> *gemm_implementation_list<__fp16, __fp16>() {
David Manselle39334c2018-07-06 17:53:35 +0100126 return gemm_fp16_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000127}
128
David Manselle39334c2018-07-06 17:53:35 +0100129/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100130template UniqueGemmCommon<__fp16, __fp16> gemm<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
131template KernelDescription get_gemm_method<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
132template std::vector<KernelDescription> get_compatible_kernels<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100133
Pablo Telloeb82fd22018-02-23 13:43:50 +0000134} // namespace arm_gemm
135
Georgios Pinitas14613832019-03-01 19:07:11 +0000136#endif // __ARM_FP16_ARGS