blob: a7f3dd3a93a983fc76b8349aa45a1cb62448a4cf [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// 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 Do03b29712022-06-01 11:47:14 +010036#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 Spyrou20fca522021-06-07 14:23:57 +010042#if defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000043#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 Spyrou20fca522021-06-07 14:23:57 +010047#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000048#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
54namespace arm_conv {
55namespace pooling {
56
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000057static 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> * {
ramelg01c827e992022-04-08 03:52:28 +010066 auto strat = new cpp_nhwc_1x1_stride_any_depthfirst<__fp16>(args.cpu_info);
67 return new PoolingDepthfirstGeneric<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000068 },
69 },
70#if defined(__aarch64__)
Viet-Hoa Do03b29712022-06-01 11:47:14 +010071#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 Spyrou20fca522021-06-07 14:23:57 +0100123#if defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000124 {
125 PoolingMethod::DEPTHFIRST,
126 "sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100127 [] (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 Spyrou20fca522021-06-07 14:23:57 +0100130 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000131 nullptr,
132 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
ramelg01c827e992022-04-08 03:52:28 +0100133 auto strat = new sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
134 return new PoolingDepthfirst<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000135 },
136 },
137 {
138 PoolingMethod::DEPTHFIRST,
139 "sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100140 [] (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 Spyrou20fca522021-06-07 14:23:57 +0100143 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000144 nullptr,
145 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
ramelg01c827e992022-04-08 03:52:28 +0100146 auto strat = new sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info);
147 return new PoolingDepthfirst<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000148 },
149 },
150 {
151 PoolingMethod::DEPTHFIRST,
152 "sve_fp16_nhwc_avg_generic_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100153 [] (const PoolingArgs &args, const Nothing &) -> bool {
154 return args.cpu_info->has_sve() && args.pool_type == PoolingType::AVERAGE;
155 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000156 nullptr,
157 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
ramelg01c827e992022-04-08 03:52:28 +0100158 auto strat = new sve_fp16_nhwc_avg_generic_depthfirst(args.cpu_info);
159 return new PoolingDepthfirstGeneric<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000160 },
161 },
162 {
163 PoolingMethod::DEPTHFIRST,
164 "sve_fp16_nhwc_max_generic_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100165 [] (const PoolingArgs &args, const Nothing &) -> bool {
166 return args.cpu_info->has_sve() && args.pool_type == PoolingType::MAX;
167 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000168 nullptr,
169 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
ramelg01c827e992022-04-08 03:52:28 +0100170 auto strat = new sve_fp16_nhwc_max_generic_depthfirst(args.cpu_info);
171 return new PoolingDepthfirstGeneric<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000172 },
173 },
Michalis Spyrou20fca522021-06-07 14:23:57 +0100174#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000175#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
176 {
177 PoolingMethod::DEPTHFIRST,
178 "a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100179 is_supported<a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>,
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000180 nullptr,
181 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
ramelg01c827e992022-04-08 03:52:28 +0100182 auto strat = new a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
183 return new PoolingDepthfirst<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000184 },
185 },
186 {
187 PoolingMethod::DEPTHFIRST,
188 "a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100189 is_supported<a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>,
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000190 nullptr,
191 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
ramelg01c827e992022-04-08 03:52:28 +0100192 auto strat = new a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst(args.cpu_info);
193 return new PoolingDepthfirst<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000194 },
195 },
196 {
197 PoolingMethod::DEPTHFIRST,
198 "a64_fp16_nhwc_avg_generic_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100199 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::AVERAGE; },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000200 nullptr,
201 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
ramelg01c827e992022-04-08 03:52:28 +0100202 auto strat = new a64_fp16_nhwc_avg_generic_depthfirst(args.cpu_info);
203 return new PoolingDepthfirstGeneric<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000204 },
205 },
206 {
207 PoolingMethod::DEPTHFIRST,
208 "a64_fp16_nhwc_max_generic_depthfirst",
ramelg01c827e992022-04-08 03:52:28 +0100209 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::MAX; },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000210 nullptr,
211 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
ramelg01c827e992022-04-08 03:52:28 +0100212 auto strat = new a64_fp16_nhwc_max_generic_depthfirst(args.cpu_info);
213 return new PoolingDepthfirstGeneric<__fp16>(strat, args);
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000214 },
215 },
216#endif // defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
217#endif // defined(__aarch64__)
218 { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
219};
220
221template <>
222const PoolingImplementation<__fp16, __fp16> *pooling_implementation_list()
223{
224 return pooling_fp16_methods;
225}
226
227template UniquePoolingCommon<__fp16, __fp16> pooling(const PoolingArgs &, const Nothing &);
228
229} // namespace pooling
230} // namespace arm_conv
231
232#endif // __ARM_FP16_ARGS