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_generic.hpp"
29
30 #if defined(__aarch64__)
31 #if defined(ARM_COMPUTE_ENABLE_SME)
32 #include "kernels/sme_s8q_nhwc_avg_generic_depthfirst.hpp"
33 #include "kernels/sme_s8q_nhwc_max_generic_depthfirst.hpp"
34 #endif // defined(ARM_COMPUTE_ENABLE_SME)
35 #if defined(ARM_COMPUTE_ENABLE_SVE)
36 #include "kernels/sve_s8q_nhwc_avg_generic_depthfirst.hpp"
37 #include "kernels/sve_s8q_nhwc_max_generic_depthfirst.hpp"
38 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
39 #include "kernels/a64_s8q_nhwc_avg_generic_depthfirst.hpp"
40 #include "kernels/a64_s8q_nhwc_max_generic_depthfirst.hpp"
41 #endif // defined(__aarch64__)
42
43 #include <cstdint>
44
45 namespace arm_conv {
46 namespace pooling {
47
48 static const PoolingImplementation<int8_t, int8_t, Requantize32> pooling_s8q_methods[] = {
49 #if defined(__aarch64__)
50 #if defined(ARM_COMPUTE_ENABLE_SME)
51 {
52 PoolingMethod::DEPTHFIRST,
53 "sme_s8q_nhwc_avg_generic_depthfirst",
__anon73d130480102() 54 [] (const PoolingArgs &args, const Requantize32 &) -> bool {
55 return args.cpu_info->has_sme2() && args.pool_type == PoolingType::AVERAGE;
56 },
57 nullptr,
__anon73d130480202() 58 [] (const PoolingArgs &args, const Requantize32 &rq) -> PoolingCommon<int8_t, int8_t> * {
59 auto strat = new sme_s8q_nhwc_avg_generic_depthfirst(args.cpu_info);
60 return new PoolingDepthfirstGeneric<int8_t, int8_t, Requantize32>(strat, args, rq);
61 },
62 },
63 {
64 PoolingMethod::DEPTHFIRST,
65 "sme_s8q_nhwc_max_generic_depthfirst",
__anon73d130480302() 66 [] (const PoolingArgs &args, const Requantize32 &) -> bool {
67 return args.cpu_info->has_sme2() && args.pool_type == PoolingType::MAX;
68 },
69 nullptr,
__anon73d130480402() 70 [] (const PoolingArgs &args, const Requantize32 &rq) -> PoolingCommon<int8_t, int8_t> * {
71 auto strat = new sme_s8q_nhwc_max_generic_depthfirst(args.cpu_info);
72 return new PoolingDepthfirstGeneric<int8_t, int8_t, Requantize32>(strat, args, rq);
73 },
74 },
75 #endif // defined(ARM_COMPUTE_ENABLE_SME)
76 #if defined(ARM_COMPUTE_ENABLE_SVE)
77 {
78 PoolingMethod::DEPTHFIRST,
79 "sve_s8q_nhwc_avg_generic_depthfirst",
__anon73d130480502() 80 [] (const PoolingArgs &args, const Requantize32 &) -> bool {
81 return args.cpu_info->has_sve2() && args.pool_type == PoolingType::AVERAGE;
82 },
83 nullptr,
__anon73d130480602() 84 [] (const PoolingArgs &args, const Requantize32 &rq) -> PoolingCommon<int8_t, int8_t> * {
85 auto strat = new sve_s8q_nhwc_avg_generic_depthfirst(args.cpu_info);
86 return new PoolingDepthfirstGeneric<int8_t, int8_t, Requantize32>(strat, args, rq);
87 },
88 },
89 {
90 PoolingMethod::DEPTHFIRST,
91 "sve_s8q_nhwc_max_generic_depthfirst",
__anon73d130480702() 92 [] (const PoolingArgs &args, const Requantize32 &) -> bool {
93 return args.cpu_info->has_sve2() && args.pool_type == PoolingType::MAX;
94 },
95 nullptr,
__anon73d130480802() 96 [] (const PoolingArgs &args, const Requantize32 &rq) -> PoolingCommon<int8_t, int8_t> * {
97 auto strat = new sve_s8q_nhwc_max_generic_depthfirst(args.cpu_info);
98 return new PoolingDepthfirstGeneric<int8_t, int8_t, Requantize32>(strat, args, rq);
99 },
100 },
101 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
102 {
103 PoolingMethod::DEPTHFIRST,
104 "a64_s8q_nhwc_avg_generic_depthfirst",
__anon73d130480902() 105 [] (const PoolingArgs &args, const Requantize32 &) -> bool {
106 return args.pool_type == PoolingType::AVERAGE;
107 },
108 nullptr,
__anon73d130480a02() 109 [] (const PoolingArgs &args, const Requantize32 &rq) -> PoolingCommon<int8_t, int8_t> * {
110 auto strat = new a64_s8q_nhwc_avg_generic_depthfirst(args.cpu_info);
111 return new PoolingDepthfirstGeneric<int8_t, int8_t, Requantize32>(strat, args, rq);
112 },
113 },
114 {
115 PoolingMethod::DEPTHFIRST,
116 "a64_s8q_nhwc_max_generic_depthfirst",
__anon73d130480b02() 117 [] (const PoolingArgs &args, const Requantize32 &) -> bool { return args.pool_type == PoolingType::MAX; },
118 nullptr,
__anon73d130480c02() 119 [] (const PoolingArgs &args, const Requantize32 &rq) -> PoolingCommon<int8_t, int8_t> * {
120 auto strat = new a64_s8q_nhwc_max_generic_depthfirst(args.cpu_info);
121 return new PoolingDepthfirstGeneric<int8_t, int8_t, Requantize32>(strat, args, rq);
122 },
123 },
124 #endif // defined(__aarch64__)
125 { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
126 };
127
128 template <>
pooling_implementation_list()129 const PoolingImplementation<int8_t, int8_t, Requantize32> *pooling_implementation_list()
130 {
131 return pooling_s8q_methods;
132 }
133
134 template UniquePoolingCommon<int8_t, int8_t> pooling(const PoolingArgs &, const Requantize32 &);
135
136 } // namespace pooling
137 } // namespace arm_conv
138