blob: 490fc0d8633ff782dd98577c2bc29e8f0a71056b [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__)
33#if defined(__ARM_FEATURE_SVE)
34#if defined(SVE2)
35#include "kernels/sve_s8_nhwc_avg_generic_depthfirst.hpp"
36#endif // defined(SVE2)
37#include "kernels/sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst.hpp"
38#include "kernels/sve_s8_nhwc_max_generic_depthfirst.hpp"
39#endif // defined(__ARM_FEATURE_SVE)
40#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__)
76#if defined(__ARM_FEATURE_SVE)
77#if defined(SVE2)
78 {
79 PoolingMethod::DEPTHFIRST,
80 "sve_s8_nhwc_avg_generic_depthfirst",
81 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::AVERAGE; },
82 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 },
87#endif // defined(SVE2)
88 {
89 PoolingMethod::DEPTHFIRST,
90 "sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst",
91 is_supported<sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst>,
92 nullptr,
93 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
94 return new PoolingDepthfirst<sve_s8_nhwc_max_2x2_s1_output2x2_depthfirst>(args);
95 },
96 },
97 {
98 PoolingMethod::DEPTHFIRST,
99 "sve_s8_nhwc_max_generic_depthfirst",
100 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::MAX; },
101 nullptr,
102 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
103 return new PoolingDepthfirstGeneric<sve_s8_nhwc_max_generic_depthfirst>(args);
104 },
105 },
106#endif // defined(__ARM_FEATURE_SVE)
107 {
108 PoolingMethod::DEPTHFIRST,
109 "a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst",
110 is_supported<a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst>,
111 nullptr,
112 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
113 return new PoolingDepthfirst<a64_s8_nhwc_max_2x2_s1_output2x2_depthfirst>(args);
114 },
115 },
116 {
117 PoolingMethod::DEPTHFIRST,
118 "a64_s8_nhwc_avg_generic_depthfirst",
119 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::AVERAGE; },
120 nullptr,
121 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
122 return new PoolingDepthfirstGeneric<a64_s8_nhwc_avg_generic_depthfirst>(args);
123 },
124 },
125 {
126 PoolingMethod::DEPTHFIRST,
127 "a64_s8_nhwc_max_generic_depthfirst",
128 [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::MAX; },
129 nullptr,
130 [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<int8_t, int8_t> * {
131 return new PoolingDepthfirstGeneric<a64_s8_nhwc_max_generic_depthfirst>(args);
132 },
133 },
134#endif // defined(__aarch64__)
135 { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
136};
137
138template <>
139const PoolingImplementation<int8_t, int8_t> *pooling_implementation_list()
140{
141 return pooling_s8_methods;
142}
143
144template UniquePoolingCommon<int8_t, int8_t> pooling(const PoolingArgs &, const Nothing &);
145
146} // namespace pooling
147} // namespace arm_conv