Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 1 | /* |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021-2022 Arm Limited. |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +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 | |
| 25 | // This can only be built if the target/compiler supports FP16 arguments. |
| 26 | #ifdef __ARM_FP16_ARGS |
| 27 | |
| 28 | #include "arm_gemm_local.hpp" |
| 29 | |
| 30 | #include "pooling_implementation.hpp" |
| 31 | #include "pooling_depthfirst.hpp" |
| 32 | #include "pooling_depthfirst_generic.hpp" |
| 33 | |
| 34 | #include "kernels/cpp_nhwc_1x1_stride_any_depthfirst.hpp" |
| 35 | #if defined(__aarch64__) |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 36 | #if defined(ARM_COMPUTE_ENABLE_SME) |
| 37 | #include "kernels/sme_fp16_nhwc_max_2x2_s1_output2x2_depthfirst.hpp" |
| 38 | #include "kernels/sme_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst.hpp" |
| 39 | #include "kernels/sme_fp16_nhwc_avg_generic_depthfirst.hpp" |
| 40 | #include "kernels/sme_fp16_nhwc_max_generic_depthfirst.hpp" |
| 41 | #endif // defined(ARM_COMPUTE_ENABLE_SME) |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 42 | #if defined(ARM_COMPUTE_ENABLE_SVE) |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 43 | #include "kernels/sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst.hpp" |
| 44 | #include "kernels/sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst.hpp" |
| 45 | #include "kernels/sve_fp16_nhwc_avg_generic_depthfirst.hpp" |
| 46 | #include "kernels/sve_fp16_nhwc_max_generic_depthfirst.hpp" |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 47 | #endif // defined(ARM_COMPUTE_ENABLE_SVE) |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 48 | #include "kernels/a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst.hpp" |
| 49 | #include "kernels/a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst.hpp" |
| 50 | #include "kernels/a64_fp16_nhwc_avg_generic_depthfirst.hpp" |
| 51 | #include "kernels/a64_fp16_nhwc_max_generic_depthfirst.hpp" |
| 52 | #endif // defined(__aarch64__) |
| 53 | |
| 54 | namespace arm_conv { |
| 55 | namespace pooling { |
| 56 | |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 57 | static const PoolingImplementation<__fp16, __fp16> pooling_fp16_methods[] = { |
| 58 | { |
| 59 | PoolingMethod::DEPTHFIRST, |
| 60 | "cpp_fp16_nhwc_1x1_stride_any_depthfirst", |
| 61 | [] (const PoolingArgs &args, const Nothing &) -> bool { |
| 62 | return args.pool_window.rows == 1 && args.pool_window.cols == 1; |
| 63 | }, |
| 64 | nullptr, |
| 65 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 66 | auto strat = new cpp_nhwc_1x1_stride_any_depthfirst<__fp16>(args.cpu_info); |
| 67 | return new PoolingDepthfirstGeneric<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 68 | }, |
| 69 | }, |
| 70 | #if defined(__aarch64__) |
Viet-Hoa Do | 03b2971 | 2022-06-01 11:47:14 +0100 | [diff] [blame] | 71 | #if defined(ARM_COMPUTE_ENABLE_SME) |
| 72 | { |
| 73 | PoolingMethod::DEPTHFIRST, |
| 74 | "sme_fp16_nhwc_max_2x2_s1_output2x2_depthfirst", |
| 75 | [] (const PoolingArgs &args, const Nothing &os) -> bool { |
| 76 | return args.cpu_info->has_sme() && |
| 77 | is_supported<sme_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args, os); |
| 78 | }, |
| 79 | nullptr, |
| 80 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 81 | auto strat = new sme_fp16_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info); |
| 82 | return new PoolingDepthfirst<__fp16>(strat, args); |
| 83 | }, |
| 84 | }, |
| 85 | { |
| 86 | PoolingMethod::DEPTHFIRST, |
| 87 | "sme_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst", |
| 88 | [] (const PoolingArgs &args, const Nothing &os) -> bool { |
| 89 | return args.cpu_info->has_sme() && |
| 90 | is_supported<sme_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args, os); |
| 91 | }, |
| 92 | nullptr, |
| 93 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 94 | auto strat = new sme_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info); |
| 95 | return new PoolingDepthfirst<__fp16>(strat, args); |
| 96 | }, |
| 97 | }, |
| 98 | { |
| 99 | PoolingMethod::DEPTHFIRST, |
| 100 | "sme_fp16_nhwc_avg_generic_depthfirst", |
| 101 | [] (const PoolingArgs &args, const Nothing &) -> bool { |
| 102 | return args.cpu_info->has_sme() && args.pool_type == PoolingType::AVERAGE; |
| 103 | }, |
| 104 | nullptr, |
| 105 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 106 | auto strat = new sme_fp16_nhwc_avg_generic_depthfirst(args.cpu_info); |
| 107 | return new PoolingDepthfirstGeneric<__fp16>(strat, args); |
| 108 | }, |
| 109 | }, |
| 110 | { |
| 111 | PoolingMethod::DEPTHFIRST, |
| 112 | "sme_fp16_nhwc_max_generic_depthfirst", |
| 113 | [] (const PoolingArgs &args, const Nothing &) -> bool { |
| 114 | return args.cpu_info->has_sme() && args.pool_type == PoolingType::MAX; |
| 115 | }, |
| 116 | nullptr, |
| 117 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 118 | auto strat = new sme_fp16_nhwc_max_generic_depthfirst(args.cpu_info); |
| 119 | return new PoolingDepthfirstGeneric<__fp16>(strat, args); |
| 120 | }, |
| 121 | }, |
| 122 | #endif // defined(ARM_COMPUTE_ENABLE_SME) |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 123 | #if defined(ARM_COMPUTE_ENABLE_SVE) |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 124 | { |
| 125 | PoolingMethod::DEPTHFIRST, |
| 126 | "sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst", |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 127 | [] (const PoolingArgs &args, const Nothing &os) -> bool { |
| 128 | return args.cpu_info->has_sve() && |
| 129 | is_supported<sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args, os); |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 130 | }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 131 | nullptr, |
| 132 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 133 | auto strat = new sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info); |
| 134 | return new PoolingDepthfirst<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 135 | }, |
| 136 | }, |
| 137 | { |
| 138 | PoolingMethod::DEPTHFIRST, |
| 139 | "sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst", |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 140 | [] (const PoolingArgs &args, const Nothing &os) -> bool { |
| 141 | return args.cpu_info->has_sve() && |
| 142 | is_supported<sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args, os); |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 143 | }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 144 | nullptr, |
| 145 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 146 | auto strat = new sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info); |
| 147 | return new PoolingDepthfirst<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 148 | }, |
| 149 | }, |
| 150 | { |
| 151 | PoolingMethod::DEPTHFIRST, |
| 152 | "sve_fp16_nhwc_avg_generic_depthfirst", |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 153 | [] (const PoolingArgs &args, const Nothing &) -> bool { |
| 154 | return args.cpu_info->has_sve() && args.pool_type == PoolingType::AVERAGE; |
| 155 | }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 156 | nullptr, |
| 157 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 158 | auto strat = new sve_fp16_nhwc_avg_generic_depthfirst(args.cpu_info); |
| 159 | return new PoolingDepthfirstGeneric<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 160 | }, |
| 161 | }, |
| 162 | { |
| 163 | PoolingMethod::DEPTHFIRST, |
| 164 | "sve_fp16_nhwc_max_generic_depthfirst", |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 165 | [] (const PoolingArgs &args, const Nothing &) -> bool { |
| 166 | return args.cpu_info->has_sve() && args.pool_type == PoolingType::MAX; |
| 167 | }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 168 | nullptr, |
| 169 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 170 | auto strat = new sve_fp16_nhwc_max_generic_depthfirst(args.cpu_info); |
| 171 | return new PoolingDepthfirstGeneric<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 172 | }, |
| 173 | }, |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame] | 174 | #endif // defined(ARM_COMPUTE_ENABLE_SVE) |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 175 | #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) |
| 176 | { |
| 177 | PoolingMethod::DEPTHFIRST, |
| 178 | "a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst", |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 179 | is_supported<a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 180 | nullptr, |
| 181 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 182 | auto strat = new a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info); |
| 183 | return new PoolingDepthfirst<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 184 | }, |
| 185 | }, |
| 186 | { |
| 187 | PoolingMethod::DEPTHFIRST, |
| 188 | "a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst", |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 189 | is_supported<a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 190 | nullptr, |
| 191 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 192 | auto strat = new a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info); |
| 193 | return new PoolingDepthfirst<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 194 | }, |
| 195 | }, |
| 196 | { |
| 197 | PoolingMethod::DEPTHFIRST, |
| 198 | "a64_fp16_nhwc_avg_generic_depthfirst", |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 199 | [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::AVERAGE; }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 200 | nullptr, |
| 201 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 202 | auto strat = new a64_fp16_nhwc_avg_generic_depthfirst(args.cpu_info); |
| 203 | return new PoolingDepthfirstGeneric<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 204 | }, |
| 205 | }, |
| 206 | { |
| 207 | PoolingMethod::DEPTHFIRST, |
| 208 | "a64_fp16_nhwc_max_generic_depthfirst", |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 209 | [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::MAX; }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 210 | nullptr, |
| 211 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
ramelg01 | c827e99 | 2022-04-08 03:52:28 +0100 | [diff] [blame] | 212 | auto strat = new a64_fp16_nhwc_max_generic_depthfirst(args.cpu_info); |
| 213 | return new PoolingDepthfirstGeneric<__fp16>(strat, args); |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 214 | }, |
| 215 | }, |
| 216 | #endif // defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) |
| 217 | #endif // defined(__aarch64__) |
| 218 | { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list |
| 219 | }; |
| 220 | |
| 221 | template <> |
| 222 | const PoolingImplementation<__fp16, __fp16> *pooling_implementation_list() |
| 223 | { |
| 224 | return pooling_fp16_methods; |
| 225 | } |
| 226 | |
| 227 | template UniquePoolingCommon<__fp16, __fp16> pooling(const PoolingArgs &, const Nothing &); |
| 228 | |
| 229 | } // namespace pooling |
| 230 | } // namespace arm_conv |
| 231 | |
| 232 | #endif // __ARM_FP16_ARGS |