blob: 15d63c746bbdd36f786d74e08a5fdc6aacde0944 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H
25#define ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
31class ITensor;
32
33/** Interface for the pooling layer kernel */
34class NEPoolingLayerKernel : public INEKernel
35{
36public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000037 const char *name() const override
38 {
39 return "NEPoolingLayerKernel";
40 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041 /** Default constructor */
42 NEPoolingLayerKernel();
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 NEPoolingLayerKernel(const NEPoolingLayerKernel &) = delete;
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 NEPoolingLayerKernel &operator=(const NEPoolingLayerKernel &) = delete;
47 /** Allow instances of this class to be moved */
48 NEPoolingLayerKernel(NEPoolingLayerKernel &&) = default;
49 /** Allow instances of this class to be moved */
50 NEPoolingLayerKernel &operator=(NEPoolingLayerKernel &&) = default;
51 /** Default destructor */
52 ~NEPoolingLayerKernel() = default;
53 /** Set the input and output tensors.
54 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010055 * @note F16 are supported for pool sizes 2 and 3 only
Gian Marco Iodice16824302017-09-28 15:41:37 +010056 *
Manuel Bottinib4bb8272019-12-18 18:01:27 +000057 * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 * @param[out] output Destination tensor. Data types supported: Same as @p input.
59 * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo.
morgolockcc1f6c92020-03-24 09:26:48 +000060 * @param[out] indices (optional) The indices of the maximal values. Data type supported: U32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 */
morgolockcc1f6c92020-03-24 09:26:48 +000062 void configure(const ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info, ITensor *indices = nullptr);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000063 /** Static function to check if given info will lead to a valid configuration of @ref NEPoolingLayerKernel
64 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010065 * @note F16 are supported for pool sizes 2 and 3 only
Michalis Spyrouafa5d812017-11-30 14:25:57 +000066 *
Manuel Bottinib4bb8272019-12-18 18:01:27 +000067 * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000068 * @param[in] output Destination tensor. Data types supported: Same as @p input.
69 * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo.
morgolockcc1f6c92020-03-24 09:26:48 +000070 * @param[in] indices (optional) The indices of the maximal values. Data type supported: U32.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000071 *
72 * @return a status
73 */
morgolockcc1f6c92020-03-24 09:26:48 +000074 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info, const ITensorInfo *indices = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075
76 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010077 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078 BorderSize border_size() const override;
79
80private:
81 /** Function to perform 2x2 pooling.
82 *
Pablo Tello77e6c552018-12-04 15:33:49 +000083 * @param[in] window_input Input region on which to execute the kernel.
84 * @param[in] window Output region on which to execute the kernel.
85 * @param[in] pooling_type Pooling operation to be computed.
86 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010087 */
Pablo Tello77e6c552018-12-04 15:33:49 +000088 void pooling2_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
morgolockcc1f6c92020-03-24 09:26:48 +000089 /** Function to perform 2x2 pooling and compute the pooling indices. The indices can be used for max unpool.
90 *
91 * @param[in] window_input Input region on which to execute the kernel.
92 * @param[in] window Output region on which to execute the kernel.
93 */
94 void pooling2_f32_nchw_maxpool_indices(const Window &window_input, const Window &window);
morgolocke383c352020-04-03 16:57:46 +010095 /** Function to perform 2x2 pooling and compute the pooling indices. The indices can be used for max unpool.
96 *
97 * @param[in] window_input Input region on which to execute the kernel.
98 * @param[in] window Output region on which to execute the kernel.
99 */
100 void pooling2_f32_nhwc_maxpool_indices(const Window &window_input, const Window &window);
Isabella Gottardi7567f5f2018-01-30 15:26:00 +0000101 /** Function to perform MxN pooling for 32-bit floating point values.
102 *
Pablo Tello77e6c552018-12-04 15:33:49 +0000103 * @param[in] window_input Input region on which to execute the kernel.
104 * @param[in] window Output region on which to execute the kernel.
105 * @param[in] pooling_type Pooling operation to be computed.
106 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
Isabella Gottardi7567f5f2018-01-30 15:26:00 +0000107 */
Pablo Tello77e6c552018-12-04 15:33:49 +0000108 void poolingMxN_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
Michalis Spyrou57dac842018-03-01 16:03:50 +0000109 /** Function to perform MxN pooling for 32-bit floating point values (NHWC).
110 *
Pablo Tello77e6c552018-12-04 15:33:49 +0000111 * @param[in] window_input Input region on which to execute the kernel.
112 * @param[in] window Output region on which to execute the kernel.
113 * @param[in] pooling_type Pooling operation to be computed.
114 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
Michalis Spyrou57dac842018-03-01 16:03:50 +0000115 */
Pablo Tello77e6c552018-12-04 15:33:49 +0000116 void poolingMxN_f32_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
117 /** Function to perform 7x7 pooling.
118 *
119 * @param[in] window_input Input region on which to execute the kernel.
120 * @param[in] window Output region on which to execute the kernel.
121 * @param[in] pooling_type Pooling operation to be computed.
122 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
123 */
124 void pooling7_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
125 /** Function to perform 3x3 pooling.
126 *
127 * @param[in] window_input Input region on which to execute the kernel.
128 * @param[in] window Output region on which to execute the kernel.
129 * @param[in] pooling_type Pooling operation to be computed.
130 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
131 */
132 void pooling3_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
133 /** Function to perform 2x2 pooling for float16_t.
134 *
135 * @param[in] window_input Input region on which to execute the kernel.
136 * @param[in] window Output region on which to execute the kernel.
137 * @param[in] pooling_type Pooling operation to be computed.
138 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
139 */
140 void pooling2_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
141 /** Function to perform 3x3 pooling.
142 *
143 * @param[in] window_input Input region on which to execute the kernel.
144 * @param[in] window Output region on which to execute the kernel.
145 * @param[in] pooling_type Pooling operation to be computed.
146 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
147 */
148 void pooling3_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
149 /** Function to perform MxN pooling for 16-bit floating point values.
150 *
151 * @param[in] window_input Input region on which to execute the kernel.
152 * @param[in] window Output region on which to execute the kernel.
153 * @param[in] pooling_type Pooling operation to be computed.
154 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
155 */
156 void poolingMxN_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
157 /** Function to perform MxN pooling for 16-bit floating point values. (NHWC)
158 *
159 * @param[in] window_input Input region on which to execute the kernel.
160 * @param[in] window Output region on which to execute the kernel.
161 * @param[in] pooling_type Pooling operation to be computed.
162 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
163 */
164 void poolingMxN_f16_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
Manuel Bottinib4bb8272019-12-18 18:01:27 +0000165 /** Template function to perform 2x2 pooling for 8bit quantized fixed point. (NCHW)
Pablo Tello77e6c552018-12-04 15:33:49 +0000166 *
167 * @param[in] window_input Input region on which to execute the kernel.
168 * @param[in] window Output region on which to execute the kernel.
169 * @param[in] pooling_type Pooling operation to be computed.
170 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
171 */
Manuel Bottinib4bb8272019-12-18 18:01:27 +0000172 template <typename T>
173 void pooling2_q8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
174 /** Template function to perform 3x3 pooling for 8bit quantized fixed point. (NCHW)
Pablo Tello77e6c552018-12-04 15:33:49 +0000175 *
176 * @param[in] window_input Input region on which to execute the kernel.
177 * @param[in] window Output region on which to execute the kernel.
178 * @param[in] pooling_type Pooling operation to be computed.
179 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
180 */
Manuel Bottinib4bb8272019-12-18 18:01:27 +0000181 template <typename T>
182 void pooling3_q8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
183 /** Template function to perform MxN pooling for 8-bit quantized. (NCHW)
Pablo Tello77e6c552018-12-04 15:33:49 +0000184 *
185 * @param[in] window_input Input region on which to execute the kernel.
186 * @param[in] window Output region on which to execute the kernel.
187 * @param[in] pooling_type Pooling operation to be computed.
188 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
189 */
Manuel Bottinib4bb8272019-12-18 18:01:27 +0000190 template <typename T>
191 void poolingMxN_q8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
192 /** Template function to perform MxN pooling for 8-bit quantized. (NHWC)
Pablo Tello77e6c552018-12-04 15:33:49 +0000193 *
194 * @param[in] window_input Input region on which to execute the kernel.
195 * @param[in] window Output region on which to execute the kernel.
196 * @param[in] pooling_type Pooling operation to be computed.
197 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
198 */
Manuel Bottinib4bb8272019-12-18 18:01:27 +0000199 template <typename T>
200 void poolingMxN_q8_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100201 /** Common signature for all the specialised Pooling functions
202 *
Pablo Tello77e6c552018-12-04 15:33:49 +0000203 * @param[in] window_input Input region on which to execute the kernel.
204 * @param[in] window Output region on which to execute the kernel.
205 * @param[in] pooling_type Pooling operation to be computed.
206 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100207 */
Pablo Tello77e6c552018-12-04 15:33:49 +0000208 using PoolingFunction = void (NEPoolingLayerKernel::*)(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100209
210private:
211 PoolingFunction _func;
212 const ITensor *_input;
213 ITensor *_output;
morgolockcc1f6c92020-03-24 09:26:48 +0000214 ITensor *_indices;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215 PoolingLayerInfo _pool_info;
Georgios Pinitas14d9d982019-12-13 12:33:09 +0000216 DataLayout _data_layout;
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000217 unsigned int _num_elems_processed_per_iteration;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100218 BorderSize _border_size;
Isabella Gottardi7567f5f2018-01-30 15:26:00 +0000219 bool _is_square;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100220};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100221} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000222#endif /*ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H */