blob: 5f45a90cef07f4dc90890cad9c70733fad6e644e [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas55186712018-01-08 17:37:12 +00002 * Copyright (c) 2017-2018 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 */
24#ifndef __ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__
25#define __ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__
26
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 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010057 * @param[in] input Source tensor. Data types supported: QASYMM8/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.
60 */
61 void configure(const ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000062 /** Static function to check if given info will lead to a valid configuration of @ref NEPoolingLayerKernel
63 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010064 * @note F16 are supported for pool sizes 2 and 3 only
Michalis Spyrouafa5d812017-11-30 14:25:57 +000065 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010066 * @param[in] input Source tensor. Data types supported: QASYMM8/F16/F32.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000067 * @param[in] output Destination tensor. Data types supported: Same as @p input.
68 * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo.
69 *
70 * @return a status
71 */
72 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073
74 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010075 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076 BorderSize border_size() const override;
77
78private:
79 /** Function to perform 2x2 pooling.
80 *
Pablo Tello77e6c552018-12-04 15:33:49 +000081 * @param[in] window_input Input region on which to execute the kernel.
82 * @param[in] window Output region on which to execute the kernel.
83 * @param[in] pooling_type Pooling operation to be computed.
84 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085 */
Pablo Tello77e6c552018-12-04 15:33:49 +000086 void pooling2_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
Isabella Gottardi7567f5f2018-01-30 15:26:00 +000087 /** Function to perform MxN pooling for 32-bit floating point values.
88 *
Pablo Tello77e6c552018-12-04 15:33:49 +000089 * @param[in] window_input Input region on which to execute the kernel.
90 * @param[in] window Output region on which to execute the kernel.
91 * @param[in] pooling_type Pooling operation to be computed.
92 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
Isabella Gottardi7567f5f2018-01-30 15:26:00 +000093 */
Pablo Tello77e6c552018-12-04 15:33:49 +000094 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 +000095 /** Function to perform MxN pooling for 32-bit floating point values (NHWC).
96 *
Pablo Tello77e6c552018-12-04 15:33:49 +000097 * @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 * @param[in] pooling_type Pooling operation to be computed.
100 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
Michalis Spyrou57dac842018-03-01 16:03:50 +0000101 */
Pablo Tello77e6c552018-12-04 15:33:49 +0000102 void poolingMxN_f32_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
103 /** Function to perform 7x7 pooling.
104 *
105 * @param[in] window_input Input region on which to execute the kernel.
106 * @param[in] window Output region on which to execute the kernel.
107 * @param[in] pooling_type Pooling operation to be computed.
108 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
109 */
110 void pooling7_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
111 /** Function to perform 3x3 pooling.
112 *
113 * @param[in] window_input Input region on which to execute the kernel.
114 * @param[in] window Output region on which to execute the kernel.
115 * @param[in] pooling_type Pooling operation to be computed.
116 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
117 */
118 void pooling3_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
119 /** Function to perform 2x2 pooling for float16_t.
120 *
121 * @param[in] window_input Input region on which to execute the kernel.
122 * @param[in] window Output region on which to execute the kernel.
123 * @param[in] pooling_type Pooling operation to be computed.
124 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
125 */
126 void pooling2_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
127 /** Function to perform 3x3 pooling.
128 *
129 * @param[in] window_input Input region on which to execute the kernel.
130 * @param[in] window Output region on which to execute the kernel.
131 * @param[in] pooling_type Pooling operation to be computed.
132 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
133 */
134 void pooling3_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
135 /** Function to perform MxN pooling for 16-bit floating point values.
136 *
137 * @param[in] window_input Input region on which to execute the kernel.
138 * @param[in] window Output region on which to execute the kernel.
139 * @param[in] pooling_type Pooling operation to be computed.
140 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
141 */
142 void poolingMxN_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
143 /** Function to perform MxN pooling for 16-bit floating point values. (NHWC)
144 *
145 * @param[in] window_input Input region on which to execute the kernel.
146 * @param[in] window Output region on which to execute the kernel.
147 * @param[in] pooling_type Pooling operation to be computed.
148 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
149 */
150 void poolingMxN_f16_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
151 /** Function to perform 2x2 pooling for 8bit asymmetric fixed point.
152 *
153 * @param[in] window_input Input region on which to execute the kernel.
154 * @param[in] window Output region on which to execute the kernel.
155 * @param[in] pooling_type Pooling operation to be computed.
156 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
157 */
158 void pooling2_qasymm8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
159 /** Function to perform 3x3 pooling for 8bit quantized fixed point.
160 *
161 * @param[in] window_input Input region on which to execute the kernel.
162 * @param[in] window Output region on which to execute the kernel.
163 * @param[in] pooling_type Pooling operation to be computed.
164 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
165 */
166 void pooling3_qasymm8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
167 /** Function to perform MxN pooling for 8-bit quantized.
168 *
169 * @param[in] window_input Input region on which to execute the kernel.
170 * @param[in] window Output region on which to execute the kernel.
171 * @param[in] pooling_type Pooling operation to be computed.
172 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
173 */
174 void poolingMxN_qasymm8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
175 /** Function to perform MxN pooling for 8-bit quantized. (NHWC)
176 *
177 * @param[in] window_input Input region on which to execute the kernel.
178 * @param[in] window Output region on which to execute the kernel.
179 * @param[in] pooling_type Pooling operation to be computed.
180 * @param[in] exclude_padding Flag to specify exclusion of padding from the operation.
181 */
182 void poolingMxN_qasymm8_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100183 /** Common signature for all the specialised Pooling functions
184 *
Pablo Tello77e6c552018-12-04 15:33:49 +0000185 * @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.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189 */
Pablo Tello77e6c552018-12-04 15:33:49 +0000190 using PoolingFunction = void (NEPoolingLayerKernel::*)(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100191
192private:
193 PoolingFunction _func;
194 const ITensor *_input;
195 ITensor *_output;
196 PoolingLayerInfo _pool_info;
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000197 unsigned int _num_elems_processed_per_iteration;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100198 BorderSize _border_size;
Isabella Gottardi7567f5f2018-01-30 15:26:00 +0000199 bool _is_square;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100200};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100201} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100202#endif /*__ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__ */