blob: 1cad674e6e96aa8a882c90e96e015abffb196d60 [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#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__)
Michalis Spyrou20fca522021-06-07 14:23:57 +010033#if defined(ARM_COMPUTE_ENABLE_SVE)
34#if defined(ARM_COMPUTE_ENABLE_SVE2)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000035#include "kernels/sve_s8_nhwc_avg_generic_depthfirst.hpp"
Michalis Spyrou20fca522021-06-07 14:23:57 +010036#endif // defined(ARM_COMPUTE_ENABLE_SVE2)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000037#include "kernels/sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst.hpp"
38#include "kernels/sve_s8_nhwc_max_generic_depthfirst.hpp"
Michalis Spyrou20fca522021-06-07 14:23:57 +010039#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000040#include "kernels/a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst.hpp"
41#include "kernels/a64_s8_nhwc_avg_generic_depthfirst.hpp"
42#include "kernels/a64_s8_nhwc_max_generic_depthfirst.hpp"
43#endif // defined(__aarch64__)
44
45#include <cstdint>
46
47namespace arm_conv {
48namespace pooling {
49
50namespace
51{
52 template <class Strategy>
53 bool is_supported(const PoolingArgs &args, const Nothing &)
54 {
55 return ((args.pool_type == Strategy::pooling_type()) &&
56 (args.pool_window.rows == Strategy::pool_rows()) &&
57 (args.pool_window.cols == Strategy::pool_cols()) &&
58 (args.pool_stride.rows == Strategy::stride_rows()) &&
59 (args.pool_stride.cols == Strategy::stride_cols()));
60 }
61}
62
63static const PoolingImplementation<int8_t, int8_t> pooling_s8_methods[] = {
64 {
65 PoolingMethod::DEPTHFIRST,
66 "cpp_s8_nhwc_1x1_stride_any_depthfirst",
67 [] (const PoolingArgs &args, const Nothing &) -> bool {
68 return args.pool_window.rows == 1 && args.pool_window.cols == 1;
69 },
70 nullptr,
71 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
72 return new PoolingDepthfirstGeneric<cpp_nhwc_1x1_stride_any_depthfirst<int8_t>>(args);
73 },
74 },
75#if defined(__aarch64__)
Michalis Spyrou20fca522021-06-07 14:23:57 +010076#if defined(ARM_COMPUTE_ENABLE_SVE)
77#if defined(ARM_COMPUTE_ENABLE_SVE2)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000078 {
79 PoolingMethod::DEPTHFIRST,
80 "sve_s8_nhwc_avg_generic_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +010081 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_sve2() && args.pool_type == PoolingType::AVERAGE; },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000082 nullptr,
83 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
84 return new PoolingDepthfirstGeneric<sve_s8_nhwc_avg_generic_depthfirst>(args);
85 },
86 },
Michalis Spyrou20fca522021-06-07 14:23:57 +010087#endif // defined(ARM_COMPUTE_ENABLE_SVE2)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000088 {
89 PoolingMethod::DEPTHFIRST,
90 "sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +010091 [] (const PoolingArgs &args, const Nothing &unused) -> bool {
92 return args.cpu_info->has_sve() && is_supported<sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst>(args, unused);
93 },
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +000094 nullptr,
95 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
96 return new PoolingDepthfirst<sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst>(args);
97 },
98 },
99 {
100 PoolingMethod::DEPTHFIRST,
101 "sve_s8_nhwc_max_generic_depthfirst",
Michalis Spyrou20fca522021-06-07 14:23:57 +0100102 [] (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 +0000103 nullptr,
104 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
105 return new PoolingDepthfirstGeneric<sve_s8_nhwc_max_generic_depthfirst>(args);
106 },
107 },
Michalis Spyrou20fca522021-06-07 14:23:57 +0100108#endif // defined(ARM_COMPUTE_ENABLE_SVE)
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +0000109 {
110 PoolingMethod::DEPTHFIRST,
111 "a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst",
112 is_supported<a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst>,
113 nullptr,
114 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
115 return new PoolingDepthfirst<a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst>(args);
116 },
117 },
118 {
119 PoolingMethod::DEPTHFIRST,
120 "a64_s8_nhwc_avg_generic_depthfirst",
121 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::AVERAGE; },
122 nullptr,
123 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
124 return new PoolingDepthfirstGeneric<a64_s8_nhwc_avg_generic_depthfirst>(args);
125 },
126 },
127 {
128 PoolingMethod::DEPTHFIRST,
129 "a64_s8_nhwc_max_generic_depthfirst",
130 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::MAX; },
131 nullptr,
132 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
133 return new PoolingDepthfirstGeneric<a64_s8_nhwc_max_generic_depthfirst>(args);
134 },
135 },
136#endif // defined(__aarch64__)
137 { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
138};
139
140template <>
141const PoolingImplementation<int8_t, int8_t> *pooling_implementation_list()
142{
143 return pooling_s8_methods;
144}
145
146template UniquePoolingCommon<int8_t, int8_t> pooling(const PoolingArgs &, const Nothing &);
147
148} // namespace pooling
149} // namespace arm_conv