blob: 99d106583e8ecb74c0763fed41083d09cb5bdf49 [file] [log] [blame]
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +00001/*
ramelg01c827e992022-04-08 03:52:28 +01002 * Copyright (c) 2021-2022 Arm Limited.
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +00003 *
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 Do03b29712022-06-01 11:47:14 +010033#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 Spyrou20fca522021-06-07 14:23:57 +010039#if defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000040#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 Spyrou20fca522021-06-07 14:23:57 +010044#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000045#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
51namespace arm_conv {
52namespace pooling {
53
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000054static 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> * {
ramelg01c827e992022-04-08 03:52:28 +010063 auto strat = new cpp_nhwc_1x1_stride_any_depthfirst<float>(args.cpu_info);
64 return new PoolingDepthfirstGeneric<float, float, Nothing>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000065 },
66 },
67#if defined(__aarch64__)
Viet-Hoa Do03b29712022-06-01 11:47:14 +010068#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 Spyrou20fca522021-06-07 14:23:57 +0100120#if defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000121 {
122 PoolingMethod::DEPTHFIRST,
123 "sve_fp32_nhwc_max_2x2_s1_output2x2_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100124 [] (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 Spyrou20fca522021-06-07 14:23:57 +0100127 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000128 nullptr,
129 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
ramelg01c827e992022-04-08 03:52:28 +0100130 auto strat = new sve_fp32_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
131 return new PoolingDepthfirst<float>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000132 },
133 },
134 {
135 PoolingMethod::DEPTHFIRST,
136 "sve_fp32_nhwc_avg_3x3_s1_output2x2_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100137 [] (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 Spyrou20fca522021-06-07 14:23:57 +0100140 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000141 nullptr,
142 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
ramelg01c827e992022-04-08 03:52:28 +0100143 auto strat = new sve_fp32_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info);
144 return new PoolingDepthfirst<float>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000145 },
146 },
147 {
148 PoolingMethod::DEPTHFIRST,
149 "sve_fp32_nhwc_avg_generic_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100150 [] (const PoolingArgs &args, const Nothing &) -> bool {
151 return args.cpu_info->has_sve() && args.pool_type == PoolingType::AVERAGE;
152 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000153 nullptr,
154 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
ramelg01c827e992022-04-08 03:52:28 +0100155 auto strat = new sve_fp32_nhwc_avg_generic_depthfirst(args.cpu_info);
156 return new PoolingDepthfirstGeneric<float>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000157 },
158 },
159 {
160 PoolingMethod::DEPTHFIRST,
161 "sve_fp32_nhwc_max_generic_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100162 [] (const PoolingArgs &args, const Nothing &) -> bool {
163 return args.cpu_info->has_sve() && args.pool_type == PoolingType::MAX;
164 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000165 nullptr,
166 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
ramelg01c827e992022-04-08 03:52:28 +0100167 auto strat = new sve_fp32_nhwc_max_generic_depthfirst(args.cpu_info);
168 return new PoolingDepthfirstGeneric<float>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000169 },
170 },
Michalis Spyrou20fca522021-06-07 14:23:57 +0100171#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000172 {
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> * {
ramelg01c827e992022-04-08 03:52:28 +0100178 auto strat = new a64_fp32_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
179 return new PoolingDepthfirst<float>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000180 },
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> * {
ramelg01c827e992022-04-08 03:52:28 +0100188 auto strat = new a64_fp32_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info);
189 return new PoolingDepthfirst<float>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000190 },
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> * {
ramelg01c827e992022-04-08 03:52:28 +0100198 auto strat = new a64_fp32_nhwc_avg_generic_depthfirst(args.cpu_info);
199 return new PoolingDepthfirstGeneric<float>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000200 },
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> * {
ramelg01c827e992022-04-08 03:52:28 +0100208 auto strat = new a64_fp32_nhwc_max_generic_depthfirst(args.cpu_info);
209 return new PoolingDepthfirstGeneric<float>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000210 },
211 },
212#endif // defined(__aarch64__)
213 { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
214};
215
216template <>
217const PoolingImplementation<float, float> *pooling_implementation_list()
218{
219 return pooling_fp32_methods;
220}
221
222template UniquePoolingCommon<float, float> pooling(const PoolingArgs &, const Nothing &);
223
224} // namespace pooling
225} // namespace arm_conv