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" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 28 | #include "gemm_implementation.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 29 | #include "gemm_interleaved.hpp" |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 30 | #include "gemm_hybrid.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 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 33 | #include "kernels/a64_gemm_u16_12x8.hpp" |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 34 | #include "kernels/a64_gemm_u8_12x8.hpp" |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 35 | #include "kernels/a64_gemm_u8_4x4.hpp" |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 36 | #include "kernels/a64_hybrid_u8u32_dot_16x4.hpp" |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame^] | 37 | #include "kernels/sve_hybrid_u8u32_dot_4VLx4.hpp" |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 38 | #include "kernels/sve_interleaved_u8u32_dot_3VLx8.hpp" |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 39 | #include "kernels/sve_native_u8u32_dot_4VLx4.hpp" |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 40 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 41 | namespace arm_gemm { |
| 42 | |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 43 | static const GemmImplementation<uint8_t, uint32_t> gemm_u8_methods[] = { |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 44 | #ifdef __ARM_FEATURE_SVE |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 45 | { |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame^] | 46 | GemmMethod::GEMM_HYBRID, |
| 47 | "hybrid_u8u32_dot_4VLx4", |
| 48 | [](const GemmArgs<uint32_t> &args) { return args._Ksize>=16 && args._alpha==1 && !args._trA && !args._trB && args._pretransposed_hint; }, |
| 49 | [](const GemmArgs<uint32_t> &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)) || ((args._nmulti > 1) && ((args._Msize / args._maxthreads) < 8)); }, |
| 50 | [](const GemmArgs<uint32_t> &args) { return new GemmHybrid<hybrid_u8u32_dot_4VLx4, uint8_t, uint32_t>(args); } |
| 51 | }, |
| 52 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 53 | GemmMethod::GEMM_NATIVE, |
| 54 | "native_u8u32_dot_4VLx4", |
| 55 | [](const GemmArgs<uint32_t> &args) { return (args._Ksize>=16 && args._alpha==1 && !args._trA && !args._trB); }, |
| 56 | [](const GemmArgs<uint32_t> &args) { return ((args._Ksize <= 128) && (args._Nsize <= 128)); }, |
| 57 | [](const GemmArgs<uint32_t> &args) { return new GemmNative<native_u8u32_dot_4VLx4, uint8_t, uint32_t>(args); } |
| 58 | }, |
| 59 | { |
| 60 | GemmMethod::GEMM_INTERLEAVED, |
| 61 | "interleaved_u8u32_dot_3VLx8", |
| 62 | [](const GemmArgs<uint32_t> &args) { return (args._Ksize>4); }, |
| 63 | nullptr, |
| 64 | [](const GemmArgs<uint32_t> &args) { return new GemmInterleaved<interleaved_u8u32_dot_3VLx8, uint8_t, uint32_t>(args); } |
| 65 | }, |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 66 | #endif |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 67 | { |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 68 | GemmMethod::GEMM_HYBRID, |
| 69 | "hybrid_u8u32_dot_16x4", |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame^] | 70 | [](const GemmArgs<uint32_t> &args) { return args._ci->has_dotprod() && args._Ksize>=16 && !args._trA && !args._trB && args._pretransposed_hint; }, |
Georgios Pinitas | 1d48065 | 2019-01-23 11:24:50 +0000 | [diff] [blame] | 71 | [](const GemmArgs<uint32_t> &args) { return args._Nsize<=256 && args._Ksize>128; }, |
| 72 | [](const GemmArgs<uint32_t> &args) { return new GemmHybrid<hybrid_u8u32_dot_16x4, uint8_t, uint32_t>(args); } |
| 73 | }, |
| 74 | { |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 75 | GemmMethod::GEMM_INTERLEAVED, |
| 76 | "gemm_u8_12x8", |
| 77 | [](const GemmArgs<uint32_t> &args) { return args._ci->has_dotprod(); }, |
| 78 | nullptr, |
| 79 | [](const GemmArgs<uint32_t> &args) { return new GemmInterleaved<gemm_u8_12x8, uint8_t, uint32_t>(args); } |
| 80 | }, |
| 81 | { |
| 82 | GemmMethod::GEMM_INTERLEAVED, |
| 83 | "gemm_u8_4x4", |
| 84 | nullptr, |
| 85 | nullptr, |
| 86 | [](const GemmArgs<uint32_t> &args) { return new GemmInterleaved<gemm_u8_4x4, uint8_t, uint32_t>(args); } |
| 87 | }, |
| 88 | { |
| 89 | GemmMethod::DEFAULT, |
| 90 | "", |
| 91 | nullptr, |
| 92 | nullptr, |
| 93 | nullptr |
| 94 | } |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | template<> |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 98 | const GemmImplementation<uint8_t, uint32_t> *gemm_implementation_list<uint8_t, uint32_t>() { |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 99 | return gemm_u8_methods; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 100 | } |
| 101 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 102 | /* Explicitly instantiate the external functions for these types. */ |
Georgios Pinitas | 7cd26d4 | 2019-01-09 18:35:17 +0000 | [diff] [blame] | 103 | template UniqueGemmCommon<uint8_t, uint32_t> gemm<uint8_t, uint32_t>(const GemmArgs<uint32_t> &args); |
| 104 | template KernelDescription get_gemm_method<uint8_t, uint32_t>(const GemmArgs<uint32_t> &args); |
| 105 | template bool method_is_compatible<uint8_t, uint32_t>(GemmMethod method, const GemmArgs<uint32_t> &args); |
Georgios Pinitas | 1461383 | 2019-03-01 19:07:11 +0000 | [diff] [blame^] | 106 | template std::vector<KernelDescription> get_compatible_kernels<uint8_t, uint32_t> (const GemmArgs<uint32_t> &args); |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 107 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 108 | } // namespace arm_gemm |
| 109 | |
David Mansell | e39334c | 2018-07-06 17:53:35 +0100 | [diff] [blame] | 110 | #endif // __aarch64__ |