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_s8_nhwc_avg_generic_depthfirst.hpp"
35 #include "kernels/sme_s8_nhwc_max_2x2_s1_output2x2_depthfirst.hpp"
36 #include "kernels/sme_s8_nhwc_max_generic_depthfirst.hpp"
37 #endif // defined(ARM_COMPUTE_ENABLE_SME)
38 #if defined(ARM_COMPUTE_ENABLE_SVE)
39 #include "kernels/sve_s8_nhwc_avg_generic_depthfirst.hpp"
40 #include "kernels/sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst.hpp"
41 #include "kernels/sve_s8_nhwc_max_generic_depthfirst.hpp"
42 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
43 #include "kernels/a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst.hpp"
44 #include "kernels/a64_s8_nhwc_avg_generic_depthfirst.hpp"
45 #include "kernels/a64_s8_nhwc_max_generic_depthfirst.hpp"
46 #endif // defined(__aarch64__)
47
48 #include <cstdint>
49
50 namespace arm_conv {
51 namespace pooling {
52
53 static const PoolingImplementation<int8_t, int8_t> pooling_s8_methods[] = {
54 {
55 PoolingMethod::DEPTHFIRST,
56 "cpp_s8_nhwc_1x1_stride_any_depthfirst",
__anonf3daba970102() 57 [] (const PoolingArgs &args, const Nothing &) -> bool {
58 return args.pool_window.rows == 1 && args.pool_window.cols == 1;
59 },
60 nullptr,
__anonf3daba970202() 61 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
62 auto strat = new cpp_nhwc_1x1_stride_any_depthfirst<int8_t>(args.cpu_info);
63 return new PoolingDepthfirstGeneric<int8_t>(strat, args);
64 },
65 },
66 #if defined(__aarch64__)
67 #if defined(ARM_COMPUTE_ENABLE_SME)
68 {
69 PoolingMethod::DEPTHFIRST,
70 "sme_s8_nhwc_max_2x2_s1_output2x2_depthfirst",
__anonf3daba970302() 71 [] (const PoolingArgs &args, const Nothing &os) -> bool {
72 return args.cpu_info->has_sme() &&
73 is_supported<sme_s8_nhwc_max_2x2_s1_output2x2_depthfirst>(args, os);
74 },
75 nullptr,
__anonf3daba970402() 76 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
77 auto strat = new sme_s8_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
78 return new PoolingDepthfirst<int8_t>(strat, args);
79 },
80 },
81 {
82 PoolingMethod::DEPTHFIRST,
83 "sme_s8_nhwc_avg_generic_depthfirst",
__anonf3daba970502() 84 [] (const PoolingArgs &args, const Nothing &) -> bool {
85 return args.cpu_info->has_sme2() && args.pool_type == PoolingType::AVERAGE;
86 },
87 nullptr,
__anonf3daba970602() 88 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
89 auto strat = new sme_s8_nhwc_avg_generic_depthfirst(args.cpu_info);
90 return new PoolingDepthfirstGeneric<int8_t>(strat, args);
91 },
92 },
93 {
94 PoolingMethod::DEPTHFIRST,
95 "sme_s8_nhwc_max_generic_depthfirst",
__anonf3daba970702() 96 [] (const PoolingArgs &args, const Nothing &) -> bool {
97 return args.cpu_info->has_sme() && args.pool_type == PoolingType::MAX;
98 },
99 nullptr,
__anonf3daba970802() 100 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
101 auto strat = new sme_s8_nhwc_max_generic_depthfirst(args.cpu_info);
102 return new PoolingDepthfirstGeneric<int8_t>(strat, args);
103 },
104 },
105 #endif // defined(ARM_COMPUTE_ENABLE_SME)
106 #if defined(ARM_COMPUTE_ENABLE_SVE)
107 {
108 PoolingMethod::DEPTHFIRST,
109 "sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst",
__anonf3daba970902() 110 [] (const PoolingArgs &args, const Nothing &os) -> bool {
111 return args.cpu_info->has_sve() &&
112 is_supported<sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst>(args, os);
113 },
114 nullptr,
__anonf3daba970a02() 115 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
116 auto strat = new sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
117 return new PoolingDepthfirst<int8_t>(strat, args);
118 },
119 },
120 {
121 PoolingMethod::DEPTHFIRST,
122 "sve_s8_nhwc_avg_generic_depthfirst",
__anonf3daba970b02() 123 [] (const PoolingArgs &args, const Nothing &) -> bool {
124 return args.cpu_info->has_sve2() && args.pool_type == PoolingType::AVERAGE;
125 },
126 nullptr,
__anonf3daba970c02() 127 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
128 auto strat = new sve_s8_nhwc_avg_generic_depthfirst(args.cpu_info);
129 return new PoolingDepthfirstGeneric<int8_t>(strat, args);
130 },
131 },
132 {
133 PoolingMethod::DEPTHFIRST,
134 "sve_s8_nhwc_max_generic_depthfirst",
__anonf3daba970d02() 135 [] (const PoolingArgs &args, const Nothing &) -> bool {
136 return args.cpu_info->has_sve() && args.pool_type == PoolingType::MAX;
137 },
138 nullptr,
__anonf3daba970e02() 139 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
140 auto strat = new sve_s8_nhwc_max_generic_depthfirst(args.cpu_info);
141 return new PoolingDepthfirstGeneric<int8_t>(strat, args);
142 },
143 },
144 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
145 {
146 PoolingMethod::DEPTHFIRST,
147 "a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst",
148 is_supported<a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst>,
149 nullptr,
__anonf3daba970f02() 150 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
151 auto strat = new a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
152 return new PoolingDepthfirst<int8_t>(strat, args);
153 },
154 },
155 {
156 PoolingMethod::DEPTHFIRST,
157 "a64_s8_nhwc_avg_generic_depthfirst",
__anonf3daba971002() 158 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::AVERAGE; },
159 nullptr,
__anonf3daba971102() 160 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
161 auto strat = new a64_s8_nhwc_avg_generic_depthfirst(args.cpu_info);
162 return new PoolingDepthfirstGeneric<int8_t>(strat, args);
163 },
164 },
165 {
166 PoolingMethod::DEPTHFIRST,
167 "a64_s8_nhwc_max_generic_depthfirst",
__anonf3daba971202() 168 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::MAX; },
169 nullptr,
__anonf3daba971302() 170 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
171 auto strat = new a64_s8_nhwc_max_generic_depthfirst(args.cpu_info);
172 return new PoolingDepthfirstGeneric<int8_t>(strat, args);
173 },
174 },
175 #endif // defined(__aarch64__)
176 { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
177 };
178
179 template <>
pooling_implementation_list()180 const PoolingImplementation<int8_t, int8_t> *pooling_implementation_list()
181 {
182 return pooling_s8_methods;
183 }
184
185 template UniquePoolingCommon<int8_t, int8_t> pooling(const PoolingArgs &, const Nothing &);
186
187 } // namespace pooling
188 } // namespace arm_conv
189