Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 ARM Limited. |
| 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 | #ifndef __ARM_COMPUTE_NEGEMMINTERLEAVEDSTRATEGIES_H__ |
| 25 | #define __ARM_COMPUTE_NEGEMMINTERLEAVEDSTRATEGIES_H__ |
| 26 | |
| 27 | #include "../arm_gemm/utils.hpp" |
| 28 | #include "arm_gemm.hpp" |
| 29 | |
| 30 | #include "../arm_gemm/mergeresults.hpp" |
| 31 | #include "../arm_gemm/transform.hpp" |
| 32 | |
| 33 | #include "../arm_gemm/kernels/a32_sgemm_8x6.hpp" |
| 34 | #include "../arm_gemm/kernels/a64_gemm_s8_12x8.hpp" |
| 35 | #include "../arm_gemm/kernels/a64_gemm_s8_4x4.hpp" |
| 36 | #include "../arm_gemm/kernels/a64_gemm_u8_12x8.hpp" |
| 37 | #include "../arm_gemm/kernels/a64_gemm_u8_4x4.hpp" |
| 38 | #include "../arm_gemm/kernels/a64_hgemm_24x8.hpp" |
| 39 | #include "../arm_gemm/kernels/a64_sgemm_12x8.hpp" |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 40 | #include "../arm_gemm/kernels/sve_interleaved_fp16_mla_3VLx8.hpp" |
| 41 | #include "../arm_gemm/kernels/sve_interleaved_fp32_mla_3VLx8.hpp" |
| 42 | #include "../arm_gemm/kernels/sve_interleaved_s8s32_dot_3VLx8.hpp" |
| 43 | #include "../arm_gemm/kernels/sve_interleaved_u8u32_dot_3VLx8.hpp" |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 44 | |
| 45 | namespace arm_compute |
| 46 | { |
| 47 | namespace |
| 48 | { |
| 49 | template <typename To, bool use_dot = false> |
| 50 | struct Kernel |
| 51 | { |
| 52 | }; |
| 53 | |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 54 | #define DEFINE_STRATEGY_SUFFIX(strat, suffix) \ |
| 55 | using strategy = arm_gemm::strat; \ |
| 56 | static constexpr const char *name = #strat suffix; |
| 57 | |
| 58 | #define DEFINE_STRATEGY(strat) \ |
| 59 | DEFINE_STRATEGY_SUFFIX(strat, "") |
| 60 | |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 61 | #ifdef __ARM_FEATURE_SVE |
| 62 | template <> |
| 63 | struct Kernel<float, false> |
| 64 | { |
| 65 | DEFINE_STRATEGY(interleaved_fp32_mla_3VLx8) |
| 66 | }; |
| 67 | template <> |
| 68 | struct Kernel<float16_t, false> |
| 69 | { |
| 70 | DEFINE_STRATEGY(interleaved_fp16_mla_3VLx8) |
| 71 | }; |
| 72 | template <bool use_dot> |
| 73 | struct Kernel<int8_t, use_dot> |
| 74 | { |
| 75 | DEFINE_STRATEGY(interleaved_s8s32_dot_3VLx8) |
| 76 | }; |
| 77 | template <bool use_dot> |
| 78 | struct Kernel<uint8_t, use_dot> |
| 79 | { |
| 80 | DEFINE_STRATEGY(interleaved_u8u32_dot_3VLx8) |
| 81 | }; |
| 82 | #else /* __ARM_FEATURE_SVE */ |
| 83 | |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 84 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 85 | template <> |
| 86 | struct Kernel<float16_t, false> |
| 87 | { |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 88 | DEFINE_STRATEGY(hgemm_24x8) |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 89 | }; |
| 90 | #endif /*__ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 91 | #ifdef __aarch64__ |
| 92 | template <> |
| 93 | struct Kernel<float, false> |
| 94 | { |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 95 | DEFINE_STRATEGY(sgemm_12x8) |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 96 | }; |
| 97 | template <> |
| 98 | struct Kernel<int8_t, false> |
| 99 | { |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 100 | DEFINE_STRATEGY(gemm_s8_4x4) |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 101 | }; |
| 102 | template <> |
| 103 | struct Kernel<uint8_t, false> |
| 104 | { |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 105 | DEFINE_STRATEGY(gemm_u8_4x4) |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | //Use different strategies for 8bit dot product: |
| 109 | template <> |
| 110 | struct Kernel<int8_t, true> |
| 111 | { |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 112 | DEFINE_STRATEGY_SUFFIX(gemm_s8_12x8, "_dot") |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 113 | }; |
| 114 | template <> |
| 115 | struct Kernel<uint8_t, true> |
| 116 | { |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 117 | DEFINE_STRATEGY_SUFFIX(gemm_u8_12x8, "_dot") |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 118 | }; |
| 119 | #else |
| 120 | template <> |
| 121 | struct Kernel<float, false> |
| 122 | { |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 123 | DEFINE_STRATEGY(sgemm_8x6) |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 124 | }; |
| 125 | #endif /* __aarch64__ */ |
Georgios Pinitas | 421405b | 2018-10-26 19:05:32 +0100 | [diff] [blame] | 126 | #endif /* __ARM_FEATURE_SVE */ |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 127 | |
Anthony Barbier | ac314c2 | 2018-09-11 17:49:10 +0100 | [diff] [blame] | 128 | #undef DEFINE_STRATEGY |
| 129 | #undef DEFINE_STRATEGY_SUFFIX |
| 130 | |
Anthony Barbier | 3d677cc | 2018-07-23 16:42:59 +0100 | [diff] [blame] | 131 | } // namespace |
| 132 | } // namespace arm_compute |
| 133 | #endif /* __ARM_COMPUTE_NEGEMMINTERLEAVEDSTRATEGIES_H__ */ |