blob: b95ca8016b3782beb8a7f64ad1ff155e5039afa2 [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Georgios Pinitas1d480652019-01-23 11:24:50 +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#ifdef __aarch64__
25
26#include "arm_gemm.hpp"
27#include "gemm_common.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"
Georgios Pinitas1d480652019-01-23 11:24:50 +000030#include "gemm_hybrid.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000031#include "gemm_native.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000032
David Manselle39334c2018-07-06 17:53:35 +010033#include "kernels/a64_gemm_u16_12x8.hpp"
Anthony Barbier5f707732018-07-03 16:22:02 +010034#include "kernels/a64_gemm_u8_12x8.hpp"
David Manselle39334c2018-07-06 17:53:35 +010035#include "kernels/a64_gemm_u8_4x4.hpp"
Georgios Pinitas1d480652019-01-23 11:24:50 +000036#include "kernels/a64_hybrid_u8u32_dot_16x4.hpp"
Georgios Pinitas421405b2018-10-26 19:05:32 +010037#include "kernels/sve_interleaved_u8u32_dot_3VLx8.hpp"
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000038#include "kernels/sve_native_u8u32_dot_4VLx4.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000039
Anthony Barbier5f707732018-07-03 16:22:02 +010040namespace arm_gemm {
41
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000042static const GemmImplementation<uint8_t, uint32_t> gemm_u8_methods[] = {
Georgios Pinitas421405b2018-10-26 19:05:32 +010043#ifdef __ARM_FEATURE_SVE
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000044{
45 GemmMethod::GEMM_NATIVE,
46 "native_u8u32_dot_4VLx4",
47 [](const GemmArgs<uint32_t> &args) { return (args._Ksize>=16 && args._alpha==1 && !args._trA && !args._trB); },
48 [](const GemmArgs<uint32_t> &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)); },
49 [](const GemmArgs<uint32_t> &args) { return new GemmNative<native_u8u32_dot_4VLx4, uint8_t, uint32_t>(args); }
50},
51{
52 GemmMethod::GEMM_INTERLEAVED,
53 "interleaved_u8u32_dot_3VLx8",
54 [](const GemmArgs<uint32_t> &args) { return (args._Ksize>4); },
55 nullptr,
56 [](const GemmArgs<uint32_t> &args) { return new GemmInterleaved<interleaved_u8u32_dot_3VLx8, uint8_t, uint32_t>(args); }
57},
Georgios Pinitas421405b2018-10-26 19:05:32 +010058#endif
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000059{
Georgios Pinitas1d480652019-01-23 11:24:50 +000060 GemmMethod::GEMM_HYBRID,
61 "hybrid_u8u32_dot_16x4",
62 [](const GemmArgs<uint32_t> &args) { return args._ci->has_dotprod() && args._Ksize>=16 && (args._Ksize % 16 == 0) && (args._Nsize % 16 == 0) && !args._trA && !args._trB && args._pretransposed_hint; },
63 [](const GemmArgs<uint32_t> &args) { return args._Nsize<=256 && args._Ksize>128; },
64 [](const GemmArgs<uint32_t> &args) { return new GemmHybrid<hybrid_u8u32_dot_16x4, uint8_t, uint32_t>(args); }
65},
66{
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000067 GemmMethod::GEMM_INTERLEAVED,
68 "gemm_u8_12x8",
69 [](const GemmArgs<uint32_t> &args) { return args._ci->has_dotprod(); },
70 nullptr,
71 [](const GemmArgs<uint32_t> &args) { return new GemmInterleaved<gemm_u8_12x8, uint8_t, uint32_t>(args); }
72},
73{
74 GemmMethod::GEMM_INTERLEAVED,
75 "gemm_u8_4x4",
76 nullptr,
77 nullptr,
78 [](const GemmArgs<uint32_t> &args) { return new GemmInterleaved<gemm_u8_4x4, uint8_t, uint32_t>(args); }
79},
80{
81 GemmMethod::DEFAULT,
82 "",
83 nullptr,
84 nullptr,
85 nullptr
86}
David Manselle39334c2018-07-06 17:53:35 +010087};
88
89template<>
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000090const GemmImplementation<uint8_t, uint32_t> *gemm_implementation_list<uint8_t, uint32_t>() {
David Manselle39334c2018-07-06 17:53:35 +010091 return gemm_u8_methods;
Pablo Telloeb82fd22018-02-23 13:43:50 +000092}
93
David Manselle39334c2018-07-06 17:53:35 +010094/* Explicitly instantiate the external functions for these types. */
Georgios Pinitas7cd26d42019-01-09 18:35:17 +000095template UniqueGemmCommon<uint8_t, uint32_t> gemm<uint8_t, uint32_t>(const GemmArgs<uint32_t> &args);
96template KernelDescription get_gemm_method<uint8_t, uint32_t>(const GemmArgs<uint32_t> &args);
97template bool method_is_compatible<uint8_t, uint32_t>(GemmMethod method, const GemmArgs<uint32_t> &args);
98template std::vector<std::string> get_compatible_kernels<uint8_t, uint32_t> (const GemmArgs<uint32_t> &args);
David Manselle39334c2018-07-06 17:53:35 +010099
Pablo Telloeb82fd22018-02-23 13:43:50 +0000100} // namespace arm_gemm
101
David Manselle39334c2018-07-06 17:53:35 +0100102#endif // __aarch64__