Compute Library
 22.11
pooling_u8.cpp
Go to the documentation of this file.
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 
28 #include "pooling_depthfirst.hpp"
30 
32 #if defined(__aarch64__)
33 #if defined(ARM_COMPUTE_ENABLE_SVE)
37 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
41 #endif // defined(__aarch64__)
42 
43 #include <cstdint>
44 
45 namespace arm_conv {
46 namespace pooling {
47 
48 static const PoolingImplementation<uint8_t, uint8_t> pooling_u8_methods[] = {
49  {
50  PoolingMethod::DEPTHFIRST,
51  "cpp_u8_nhwc_1x1_stride_any_depthfirst",
52  [] (const PoolingArgs &args, const Nothing &) -> bool {
53  return args.pool_window.rows == 1 && args.pool_window.cols == 1;
54  },
55  nullptr,
56  [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<uint8_t, uint8_t> * {
57  auto strat = new cpp_nhwc_1x1_stride_any_depthfirst<uint8_t>(args.cpu_info);
58  return new PoolingDepthfirstGeneric<uint8_t>(strat, args);
59  },
60  },
61 #if defined(__aarch64__)
62 #if defined(ARM_COMPUTE_ENABLE_SVE)
63  {
64  PoolingMethod::DEPTHFIRST,
65  "sve_u8_nhwc_max_2x2_s1_output2x2_depthfirst",
66  [] (const PoolingArgs &args, const Nothing &os) -> bool {
67  return args.cpu_info->has_sve() &&
68  is_supported<sve_u8_nhwc_max_2x2_s1_output2x2_depthfirst>(args, os);
69  },
70  nullptr,
71  [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<uint8_t, uint8_t> * {
72  auto strat = new sve_u8_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
73  return new PoolingDepthfirst<uint8_t>(strat, args);
74  },
75  },
76  {
77  PoolingMethod::DEPTHFIRST,
78  "sve_u8_nhwc_avg_generic_depthfirst",
79  [] (const PoolingArgs &args, const Nothing &) -> bool {
80  // This kernel can only be used when there is either no padding, or we don't care
81  // about the value of the padding. Otherwise, we would need to pass in the zero-point
82  // for the quantization regime.
83  return (args.exclude_padding ||
84  (args.padding.top == 0 && args.padding.bottom == 0 &&
85  args.padding.left == 0 && args.padding.right == 0)
86  ) && args.pool_type == PoolingType::AVERAGE &&
87  args.cpu_info->has_sve2();
88  },
89  nullptr,
90  [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<uint8_t, uint8_t> * {
91  auto strat = new sve_u8_nhwc_avg_generic_depthfirst(args.cpu_info);
92  return new PoolingDepthfirstGeneric<uint8_t>(strat, args);
93  },
94  },
95  {
96  PoolingMethod::DEPTHFIRST,
97  "sve_u8_nhwc_max_generic_depthfirst",
98  [] (const PoolingArgs &args, const Nothing &) -> bool {
99  return args.cpu_info->has_sve() && args.pool_type == PoolingType::MAX;
100  },
101  nullptr,
102  [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<uint8_t, uint8_t> * {
103  auto strat = new sve_u8_nhwc_max_generic_depthfirst(args.cpu_info);
104  return new PoolingDepthfirstGeneric<uint8_t>(strat, args);
105  },
106  },
107 #endif // defined(ARM_COMPUTE_ENABLE_SVE)
108  {
109  PoolingMethod::DEPTHFIRST,
110  "a64_u8_nhwc_max_2x2_s1_output2x2_depthfirst",
111  is_supported<a64_u8_nhwc_max_2x2_s1_output2x2_depthfirst>,
112  nullptr,
113  [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<uint8_t, uint8_t> * {
114  auto strat = new a64_u8_nhwc_max_2x2_s1_output2x2_depthfirst(args.cpu_info);
115  return new PoolingDepthfirst<uint8_t>(strat, args);
116  },
117  },
118  {
119  PoolingMethod::DEPTHFIRST,
120  "a64_u8_nhwc_avg_generic_depthfirst",
121  [] (const PoolingArgs &args, const Nothing &) -> bool {
122  // This kernel can only be used when there is either no padding, or we don't care
123  // about the value of the padding. Otherwise, we would need to pass in the zero-point
124  // for the quantization regime.
125  return (args.exclude_padding ||
126  (args.padding.top == 0 && args.padding.bottom == 0 &&
127  args.padding.left == 0 && args.padding.right == 0)
128  ) && args.pool_type == PoolingType::AVERAGE;
129  },
130  nullptr,
131  [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<uint8_t, uint8_t> * {
132  auto strat = new a64_u8_nhwc_avg_generic_depthfirst(args.cpu_info);
133  return new PoolingDepthfirstGeneric<uint8_t>(strat, args);
134  },
135  },
136  {
137  PoolingMethod::DEPTHFIRST,
138  "a64_u8_nhwc_max_generic_depthfirst",
139  [] (const PoolingArgs &args, const Nothing &) -> bool { return args.pool_type == PoolingType::MAX; },
140  nullptr,
141  [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<uint8_t, uint8_t> * {
142  auto strat = new a64_u8_nhwc_max_generic_depthfirst(args.cpu_info);
143  return new PoolingDepthfirstGeneric<uint8_t>(strat, args);
144  },
145  },
146 #endif // defined(__aarch64__)
147  { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list
148 };
149 
150 template <>
152 {
153  return pooling_u8_methods;
154 }
155 
156 template UniquePoolingCommon<uint8_t, uint8_t> pooling(const PoolingArgs &, const Nothing &);
157 
158 } // namespace pooling
159 } // namespace arm_conv
#define MAX(x, y)
template UniquePoolingCommon< float, float > pooling(const PoolingArgs &, const Nothing &)
const PoolingImplementation< float, float > * pooling_implementation_list()