1 /*
2 * Copyright (c) 2021-2022 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
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__)
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)
39 #if defined(ARM_COMPUTE_ENABLE_SVE)
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"
44 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
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
54 static const PoolingImplementation<float, float> pooling_fp32_methods[] = {
55 {
56 PoolingMethod::DEPTHFIRST,
57 "cpp_fp32_nhwc_1x1_stride_any_depthfirst",
__anon34e7f8270102() 58 [] (const PoolingArgs &args, const Nothing &) -> bool {
59 return args.pool_window.rows == 1 && args.pool_window.cols == 1;
60 },
61 nullptr,
__anon34e7f8270202() 62 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
63 auto strat = new cpp_nhwc_1x1_stride_any_depthfirst<float>(args.cpu_info);
64 return new PoolingDepthfirstGeneric<float, float, Nothing>(strat, args);
65 },
66 },
67 #if defined(__aarch64__)
68 #if defined(ARM_COMPUTE_ENABLE_SME)
69 {
70 PoolingMethod::DEPTHFIRST,
71 "sme_fp32_nhwc_max_2x2_s1_output2x2_depthfirst",
__anon34e7f8270302() 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,
__anon34e7f8270402() 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",
__anon34e7f8270502() 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,
__anon34e7f8270602() 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",
__anon34e7f8270702() 98 [] (const PoolingArgs &args, const Nothing &) -> bool {
99 return args.cpu_info->has_sme() && args.pool_type == PoolingType::AVERAGE;
100 },
101 nullptr,
__anon34e7f8270802() 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",
__anon34e7f8270902() 110 [] (const PoolingArgs &args, const Nothing &) -> bool {
111 return args.cpu_info->has_sme() && args.pool_type == PoolingType::MAX;
112 },
113 nullptr,
__anon34e7f8270a02() 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)
120 #if defined(ARM_COMPUTE_ENABLE_SVE)
121 {
122 PoolingMethod::DEPTHFIRST,
123 "sve_fp32_nhwc_max_2x2_s1_output2x2_depthfirst",
__anon34e7f8270b02() 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);
127 },
128 nullptr,
__anon34e7f8270c02() 129 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
130 auto strat = new sve_fp32_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
131 return new PoolingDepthfirst<float>(strat, args);
132 },
133 },
134 {
135 PoolingMethod::DEPTHFIRST,
136 "sve_fp32_nhwc_avg_3x3_s1_output2x2_depthfirst",
__anon34e7f8270d02() 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);
140 },
141 nullptr,
__anon34e7f8270e02() 142 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
143 auto strat = new sve_fp32_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info);
144 return new PoolingDepthfirst<float>(strat, args);
145 },
146 },
147 {
148 PoolingMethod::DEPTHFIRST,
149 "sve_fp32_nhwc_avg_generic_depthfirst",
__anon34e7f8270f02() 150 [] (const PoolingArgs &args, const Nothing &) -> bool {
151 return args.cpu_info->has_sve() && args.pool_type == PoolingType::AVERAGE;
152 },
153 nullptr,
__anon34e7f8271002() 154 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
155 auto strat = new sve_fp32_nhwc_avg_generic_depthfirst(args.cpu_info);
156 return new PoolingDepthfirstGeneric<float>(strat, args);
157 },
158 },
159 {
160 PoolingMethod::DEPTHFIRST,
161 "sve_fp32_nhwc_max_generic_depthfirst",
__anon34e7f8271102() 162 [] (const PoolingArgs &args, const Nothing &) -> bool {
163 return args.cpu_info->has_sve() && args.pool_type == PoolingType::MAX;
164 },
165 nullptr,
__anon34e7f8271202() 166 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
167 auto strat = new sve_fp32_nhwc_max_generic_depthfirst(args.cpu_info);
168 return new PoolingDepthfirstGeneric<float>(strat, args);
169 },
170 },
171 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
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,
__anon34e7f8271302() 177 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
178 auto strat = new a64_fp32_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
179 return new PoolingDepthfirst<float>(strat, args);
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,
__anon34e7f8271402() 187 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
188 auto strat = new a64_fp32_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info);
189 return new PoolingDepthfirst<float>(strat, args);
190 },
191 },
192 {
193 PoolingMethod::DEPTHFIRST,
194 "a64_fp32_nhwc_avg_generic_depthfirst",
__anon34e7f8271502() 195 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::AVERAGE; },
196 nullptr,
__anon34e7f8271602() 197 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
198 auto strat = new a64_fp32_nhwc_avg_generic_depthfirst(args.cpu_info);
199 return new PoolingDepthfirstGeneric<float>(strat, args);
200 },
201 },
202 {
203 PoolingMethod::DEPTHFIRST,
204 "a64_fp32_nhwc_max_generic_depthfirst",
__anon34e7f8271702() 205 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::MAX; },
206 nullptr,
__anon34e7f8271802() 207 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<float, float> * {
208 auto strat = new a64_fp32_nhwc_max_generic_depthfirst(args.cpu_info);
209 return new PoolingDepthfirstGeneric<float>(strat, args);
210 },
211 },
212 #endif // defined(__aarch64__)
213 { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
214 };
215
216 template <>
pooling_implementation_list()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
226