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