blob: 75524fff97f5336b5cff1aa3229dc73de31cc5d0 [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"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000032#include "gemm_hybrid_indirect.hpp"
David Manselle39334c2018-07-06 17:53:35 +010033#include "gemm_implementation.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000034#include "gemm_interleaved.hpp"
cfRod534fdea2020-06-25 18:12:25 +010035#include "gemm_interleaved_pretransposed_2d.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000036
Georgios Pinitas14613832019-03-01 19:07:11 +000037#include "kernels/a32_sgemm_8x6.hpp"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000038#include "kernels/a64_hgemm_8x24.hpp"
39#include "kernels/a64_hybrid_fp16_mla_6x32.hpp"
40#include "kernels/a64_sgemm_8x12.hpp"
41#include "kernels/sve_hybrid_fp16_mla_6x4VL.hpp"
42#include "kernels/sve_interleaved_fp16_mla_8x3VL.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000043
Anthony Barbier5f707732018-07-03 16:22:02 +010044namespace arm_gemm {
45
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000046static const GemmImplementation<__fp16, __fp16> gemm_fp16_methods[] = {
47#if defined(__ARM_FEATURE_SVE)
48{
Georgios Pinitas14613832019-03-01 19:07:11 +000049 GemmMethod::GEMM_HYBRID,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000050 "sve_hybrid_fp16_mla_6x4VL",
51 nullptr,
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010052 [](const GemmArgs &args) { return ((args._Ksize <= 256) && (args._Nsize <= 256)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000053 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp16_mla_6x32, __fp16, __fp16>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +000054},
55{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000056 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000057 "sve_interleaved_fp16_mla_8x3VL",
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010058 [](const GemmArgs &args) { return (args._Ksize > 4); },
Georgios Pinitas14613832019-03-01 19:07:11 +000059 nullptr,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000060 [](const GemmArgs &args) { return new GemmInterleaved<cls_sve_interleaved_fp16_mla_8x3VL, __fp16, __fp16>(args); }
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000061},
62#endif
Georgios Pinitas14613832019-03-01 19:07:11 +000063
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000064#if defined(__aarch64__) && (defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) || defined(FP16_KERNELS))
Georgios Pinitas40943df2020-11-17 18:46:40 +000065GemmImplementation<__fp16, __fp16>::with_estimate(
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000066 GemmMethod::GEMM_HYBRID,
67 "a64_hybrid_fp16_mla_6x32",
cfRod534fdea2020-06-25 18:12:25 +010068#ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
69 [](const GemmArgs &args) { return args._ci->has_fp16(); },
70#else
71 nullptr,
72#endif
Georgios Pinitas40943df2020-11-17 18:46:40 +000073 [](const GemmArgs &args) { return GemmHybridIndirect<cls_a64_hybrid_fp16_mla_6x32, __fp16, __fp16>::estimate_cycles(args, cls_a64_hybrid_fp16_mla_6x32::get_performance_parameters(args._ci)); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000074 [](const GemmArgs &args) { return new GemmHybridIndirect<cls_a64_hybrid_fp16_mla_6x32, __fp16, __fp16>(args); }
Georgios Pinitas40943df2020-11-17 18:46:40 +000075),
76GemmImplementation<__fp16, __fp16>::with_estimate(
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000077 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000078 "a64_hgemm_8x24",
David Manselle39334c2018-07-06 17:53:35 +010079#ifndef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010080 [](const GemmArgs &args) { return args._ci->has_fp16(); },
David Manselle39334c2018-07-06 17:53:35 +010081#else
Georgios Pinitas14613832019-03-01 19:07:11 +000082 nullptr,
David Manselle39334c2018-07-06 17:53:35 +010083#endif
Georgios Pinitas40943df2020-11-17 18:46:40 +000084 [](const GemmArgs &args) { return GemmInterleaved<cls_a64_hgemm_8x24, __fp16, __fp16>::estimate_cycles(args, cls_a64_hgemm_8x24::get_performance_parameters(args._ci)); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000085 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_hgemm_8x24, __fp16, __fp16>(args); }
Georgios Pinitas40943df2020-11-17 18:46:40 +000086),
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010087#endif // aarch64 && FP16
Georgios Pinitas14613832019-03-01 19:07:11 +000088#ifdef __aarch64__
89{
90 GemmMethod::GEMM_INTERLEAVED,
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000091 "a64_sgemm_8x12",
Georgios Pinitas14613832019-03-01 19:07:11 +000092 nullptr,
Georgios Pinitas40943df2020-11-17 18:46:40 +000093 [](const GemmArgs &args) { return !args._ci->has_fp16(); },
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000094 [](const GemmArgs &args) { return new GemmInterleaved<cls_a64_sgemm_8x12, __fp16, __fp16>(args); }
Georgios Pinitas14613832019-03-01 19:07:11 +000095},
96#elif defined(__arm__)
Georgios Pinitasa41c54b2019-01-30 18:16:43 +000097{
98 GemmMethod::GEMM_INTERLEAVED,
99 "sgemm_8x6",
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_8x6, __fp16, __fp16>(args); }
Georgios Pinitasa41c54b2019-01-30 18:16:43 +0000103},
Georgios Pinitas14613832019-03-01 19:07:11 +0000104#else // not AArch64 or AArch32
105# error Unknown Architecture
Georgios Pinitasa41c54b2019-01-30 18:16:43 +0000106#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000107{
108 GemmMethod::DEFAULT,
109 "",
110 nullptr,
111 nullptr,
112 nullptr,
113}
David Manselle39334c2018-07-06 17:53:35 +0100114};
115
116template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +0000117const GemmImplementation<__fp16, __fp16> *gemm_implementation_list<__fp16, __fp16>() {
David Manselle39334c2018-07-06 17:53:35 +0100118 return gemm_fp16_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000119}
120
David Manselle39334c2018-07-06 17:53:35 +0100121/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100122template UniqueGemmCommon<__fp16, __fp16> gemm<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
123template KernelDescription get_gemm_method<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
124template std::vector<KernelDescription> get_compatible_kernels<__fp16, __fp16, Nothing>(const GemmArgs &args, const Nothing &);
David Manselle39334c2018-07-06 17:53:35 +0100125
Pablo Telloeb82fd22018-02-23 13:43:50 +0000126} // namespace arm_gemm
127
Georgios Pinitas14613832019-03-01 19:07:11 +0000128#endif // __ARM_FP16_ARGS