blob: 42f23a158e6fc767d38fd3ec3ff4b699b74941b1 [file] [log] [blame]
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +00001/*
2 * Copyright (c) 2021 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// 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__)
Michalis Spyrou20fca522021-06-07 14:23:57 +010036#if defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000037#include "kernels/sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst.hpp"
38#include "kernels/sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst.hpp"
39#include "kernels/sve_fp16_nhwc_avg_generic_depthfirst.hpp"
40#include "kernels/sve_fp16_nhwc_max_generic_depthfirst.hpp"
Michalis Spyrou20fca522021-06-07 14:23:57 +010041#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000042#include "kernels/a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst.hpp"
43#include "kernels/a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst.hpp"
44#include "kernels/a64_fp16_nhwc_avg_generic_depthfirst.hpp"
45#include "kernels/a64_fp16_nhwc_max_generic_depthfirst.hpp"
46#endif // defined(__aarch64__)
47
48namespace arm_conv {
49namespace pooling {
50
51namespace
52{
53 template <class Strategy>
54 bool is_supported(const PoolingArgs &args, const Nothing &)
55 {
56 return ((args.pool_type == Strategy::pooling_type()) &&
57 (args.pool_window.rows == Strategy::pool_rows()) &&
58 (args.pool_window.cols == Strategy::pool_cols()) &&
59 (args.pool_stride.rows == Strategy::stride_rows()) &&
60 (args.pool_stride.cols == Strategy::stride_cols()));
61 }
62}
63
64static const PoolingImplementation<__fp16, __fp16> pooling_fp16_methods[] = {
65 {
66 PoolingMethod::DEPTHFIRST,
67 "cpp_fp16_nhwc_1x1_stride_any_depthfirst",
68 [] (const PoolingArgs &args, const Nothing &) -> bool {
69 return args.pool_window.rows == 1 && args.pool_window.cols == 1;
70 },
71 nullptr,
72 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
73 return new PoolingDepthfirstGeneric<cpp_nhwc_1x1_stride_any_depthfirst<__fp16>>(args);
74 },
75 },
76#if defined(__aarch64__)
Michalis Spyrou20fca522021-06-07 14:23:57 +010077#if defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000078 {
79 PoolingMethod::DEPTHFIRST,
80 "sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +010081 [] (const PoolingArgs &args, const Nothing &unused) -> bool {
82 return args.cpu_info->has_sve() && is_supported<sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args, unused);
83 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000084 nullptr,
85 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
86 return new PoolingDepthfirst<sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args);
87 },
88 },
89 {
90 PoolingMethod::DEPTHFIRST,
91 "sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +010092 [] (const PoolingArgs &args, const Nothing &unused) -> bool {
93 return args.cpu_info->has_sve() && is_supported<sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args, unused);
94 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000095 nullptr,
96 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
97 return new PoolingDepthfirst<sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args);
98 },
99 },
100 {
101 PoolingMethod::DEPTHFIRST,
102 "sve_fp16_nhwc_avg_generic_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100103 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_sve() && args.pool_type == PoolingType::AVERAGE; },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000104 nullptr,
105 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
106 return new PoolingDepthfirstGeneric<sve_fp16_nhwc_avg_generic_depthfirst>(args);
107 },
108 },
109 {
110 PoolingMethod::DEPTHFIRST,
111 "sve_fp16_nhwc_max_generic_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100112 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_sve() && args.pool_type == PoolingType::MAX; },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000113 nullptr,
114 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
115 return new PoolingDepthfirstGeneric<sve_fp16_nhwc_max_generic_depthfirst>(args);
116 },
117 },
Michalis Spyrou20fca522021-06-07 14:23:57 +0100118#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000119#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
120 {
121 PoolingMethod::DEPTHFIRST,
122 "a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100123 [] (const PoolingArgs &args, const Nothing &unused) -> bool {
124 return args.cpu_info->has_fp16() && is_supported<a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args, unused);
125 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000126 nullptr,
127 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
128 return new PoolingDepthfirst<a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args);
129 },
130 },
131 {
132 PoolingMethod::DEPTHFIRST,
133 "a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100134 [] (const PoolingArgs &args, const Nothing &unused) -> bool {
135 return args.cpu_info->has_fp16() && is_supported<a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args, unused);
136 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000137 nullptr,
138 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
139 return new PoolingDepthfirst<a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args);
140 },
141 },
142 {
143 PoolingMethod::DEPTHFIRST,
144 "a64_fp16_nhwc_avg_generic_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100145 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_fp16() && args.pool_type == PoolingType::AVERAGE; },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000146 nullptr,
147 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
148 return new PoolingDepthfirstGeneric<a64_fp16_nhwc_avg_generic_depthfirst>(args);
149 },
150 },
151 {
152 PoolingMethod::DEPTHFIRST,
153 "a64_fp16_nhwc_max_generic_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100154 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_fp16() && args.pool_type == PoolingType::MAX; },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000155 nullptr,
156 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * {
157 return new PoolingDepthfirstGeneric<a64_fp16_nhwc_max_generic_depthfirst>(args);
158 },
159 },
160#endif // defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
161#endif // defined(__aarch64__)
162 { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
163};
164
165template <>
166const PoolingImplementation<__fp16, __fp16> *pooling_implementation_list()
167{
168 return pooling_fp16_methods;
169}
170
171template UniquePoolingCommon<__fp16, __fp16> pooling(const PoolingArgs &, const Nothing &);
172
173} // namespace pooling
174} // namespace arm_conv
175
176#endif // __ARM_FP16_ARGS