Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 3 | * |
| 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" |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 28 | #include "gemm_hybrid.hpp" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 29 | #include "gemm_implementation.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 30 | #include "gemm_interleaved.hpp" |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 31 | #include "gemm_native.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 32 | |
| 33 | #include "kernels/a64_gemm_s16_12x8.hpp" |
| 34 | #include "kernels/a64_gemm_s8_12x8.hpp" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 35 | #include "kernels/a64_gemm_s8_4x4.hpp" |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 36 | #include "kernels/a64_hybrid_s8s32_dot_16x4.hpp" |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 37 | #include "kernels/a64_smallK_hybrid_s8s32_dot_4x6.hpp" |
| 38 | #include "kernels/a64_smallK_hybrid_s8s32_dot_4x8.hpp" |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 39 | #include "kernels/sve_hybrid_s8s32_dot_4VLx4.hpp" |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 40 | #include "kernels/sve_interleaved_s8s32_dot_3VLx8.hpp" |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 41 | #include "kernels/sve_native_s8s32_dot_4VLx4.hpp" |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 42 | #include "kernels/sve_smallK_hybrid_s8s32_dot_1VLx8.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 43 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 44 | namespace arm_gemm { |
| 45 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 46 | static const GemmImplementation<int8_t, int32_t> gemm_s8_methods[] = { |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 47 | #ifdef __ARM_FEATURE_SVE |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 48 | { |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 49 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 50 | "smallK_hybrid_s8s32_dot_1VLx8", |
| 51 | [](const GemmArgs<int32_t> &args) { return args._Ksize<=64 && args._alpha==1 && args._beta==0 && !args._trA && args._pretransposed_hint; }, |
| 52 | nullptr, |
| 53 | [](const GemmArgs<int32_t> &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_1VLx8, int8_t, int32_t>(args); } |
| 54 | }, |
| 55 | { |
| 56 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 57 | "hybrid_s8s32_dot_4VLx4", |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 58 | [](const GemmArgs<int32_t> &args) { return args._Ksize>=16 && args._alpha==1 && !args._trA && args._pretransposed_hint; }, |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame] | 59 | [](const GemmArgs<int32_t> &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); }, |
| 60 | [](const GemmArgs<int32_t> &args) { return new GemmHybrid<hybrid_s8s32_dot_4VLx4, int8_t, int32_t>(args); } |
| 61 | }, |
| 62 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 63 | GemmMethod::GEMM_NATIVE, |
| 64 | "native_s8s32_dot_4VLx4", |
| 65 | [](const GemmArgs<int32_t> &args) { return (args._Ksize>=16 && args._alpha==1 && !args._trA && !args._trB); }, |
| 66 | [](const GemmArgs<int32_t> &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)); }, |
| 67 | [](const GemmArgs<int32_t> &args) { return new GemmNative<native_s8s32_dot_4VLx4, int8_t, int32_t>(args); } |
| 68 | }, |
| 69 | { |
| 70 | GemmMethod::GEMM_INTERLEAVED, |
| 71 | "interleaved_s8s32_dot_3VLx8", |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 72 | [](const GemmArgs<int32_t> &args) { return (args._Ksize>4) && args._alpha==1 && (args._beta == 0 || args._beta==1); }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 73 | nullptr, |
| 74 | [](const GemmArgs<int32_t> &args) { return new GemmInterleaved<interleaved_s8s32_dot_3VLx8, int8_t, int32_t>(args); } |
| 75 | }, |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 76 | #endif |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 77 | { |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 78 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 79 | "smallK_hybrid_s8s32_dot_4x8", |
| 80 | [](const GemmArgs<int32_t> &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize<=32) && args._alpha==1 && args._beta==0 && !args._trA && args._pretransposed_hint; }, |
| 81 | nullptr, |
| 82 | [](const GemmArgs<int32_t> &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_4x8, int8_t, int32_t>(args); } |
| 83 | }, |
| 84 | { |
| 85 | GemmMethod::GEMM_HYBRID, |
| 86 | "smallK_hybrid_s8s32_dot_4x6", |
| 87 | [](const GemmArgs<int32_t> &args) { return args._ci->has_dotprod() && (args._Nsize % 4 == 0) && (args._Ksize>32) && (args._Ksize<=64) && args._alpha==1 && args._beta==0 && !args._trA && args._pretransposed_hint; }, |
| 88 | nullptr, |
| 89 | [](const GemmArgs<int32_t> &args) { return new GemmHybrid<smallK_hybrid_s8s32_dot_4x6, int8_t, int32_t>(args); } |
| 90 | }, |
| 91 | { |
| 92 | GemmMethod::GEMM_HYBRID, |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 93 | "hybrid_s8s32_dot_16x4", |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 94 | [](const GemmArgs<int32_t> &args) { return args._ci->has_dotprod() && args._Ksize>=16 && args._alpha==1 && !args._trA && !args._trB && args._pretransposed_hint; }, |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 95 | [](const GemmArgs<int32_t> &args) { return args._Nsize<=256 && args._Ksize>128; }, |
| 96 | [](const GemmArgs<int32_t> &args) { return new GemmHybrid<hybrid_s8s32_dot_16x4, int8_t, int32_t>(args); } |
| 97 | }, |
| 98 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 99 | GemmMethod::GEMM_INTERLEAVED, |
| 100 | "gemm_s8_12x8", |
Georgios Pinitas | ae0fc86 | 2019-09-30 12:39:40 +0100 | [diff] [blame] | 101 | [](const GemmArgs<int32_t> &args) { return args._ci->has_dotprod() && args._alpha==1 && (args._beta==0 || args._beta==1); }, |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 102 | nullptr, |
| 103 | [](const GemmArgs<int32_t> &args) { return new GemmInterleaved<gemm_s8_12x8, int8_t, int32_t>(args); } |
| 104 | }, |
| 105 | { |
| 106 | GemmMethod::GEMM_INTERLEAVED, |
| 107 | "gemm_s8_4x4", |
| 108 | nullptr, |
| 109 | nullptr, |
| 110 | [](const GemmArgs<int32_t> &args) { return new GemmInterleaved<gemm_s8_4x4, int8_t, int32_t>(args); } |
| 111 | }, |
| 112 | { |
| 113 | GemmMethod::DEFAULT, |
| 114 | "", |
| 115 | nullptr, |
| 116 | nullptr, |
| 117 | nullptr |
| 118 | } |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | template<> |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 122 | const GemmImplementation<int8_t, int32_t> *gemm_implementation_list<int8_t, int32_t>() { |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 123 | return gemm_s8_methods; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 124 | } |
| 125 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 126 | /* Explicitly instantiate the external functions for these types. */ |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 127 | template UniqueGemmCommon<int8_t, int32_t> gemm<int8_t, int32_t, Nothing>(const GemmArgs<int32_t> &args, const Nothing &); |
| 128 | template KernelDescription get_gemm_method<int8_t, int32_t, Nothing>(const GemmArgs<int32_t> &args, const Nothing &); |
| 129 | template std::vector<KernelDescription> get_compatible_kernels<int8_t, int32_t, Nothing> (const GemmArgs<int32_t> &args, const Nothing &); |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 130 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 131 | } // namespace arm_gemm |
| 132 | |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 133 | #endif // __aarch64__ |