Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H |
| 25 | #define ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 27 | #include "src/core/NEON/INEKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | class ITensor; |
| 32 | |
| 33 | /** Interface for the pooling layer kernel */ |
| 34 | class NEPoolingLayerKernel : public INEKernel |
| 35 | { |
| 36 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 37 | const char *name() const override |
| 38 | { |
| 39 | return "NEPoolingLayerKernel"; |
| 40 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | /** 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 Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 55 | * @note F16 are supported for pool sizes 2 and 3 only |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 56 | * |
Manuel Bottini | b4bb827 | 2019-12-18 18:01:27 +0000 | [diff] [blame] | 57 | * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 58 | * @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. |
morgolock | cc1f6c9 | 2020-03-24 09:26:48 +0000 | [diff] [blame] | 60 | * @param[out] indices (optional) The indices of the maximal values. Data type supported: U32. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | */ |
morgolock | cc1f6c9 | 2020-03-24 09:26:48 +0000 | [diff] [blame] | 62 | void configure(const ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info, ITensor *indices = nullptr); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 63 | /** Static function to check if given info will lead to a valid configuration of @ref NEPoolingLayerKernel |
| 64 | * |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 65 | * @note F16 are supported for pool sizes 2 and 3 only |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 66 | * |
Manuel Bottini | b4bb827 | 2019-12-18 18:01:27 +0000 | [diff] [blame] | 67 | * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 68 | * @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. |
morgolock | cc1f6c9 | 2020-03-24 09:26:48 +0000 | [diff] [blame] | 70 | * @param[in] indices (optional) The indices of the maximal values. Data type supported: U32. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 71 | * |
| 72 | * @return a status |
| 73 | */ |
morgolock | cc1f6c9 | 2020-03-24 09:26:48 +0000 | [diff] [blame] | 74 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info, const ITensorInfo *indices = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | |
| 76 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 77 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 78 | BorderSize border_size() const override; |
| 79 | |
| 80 | private: |
| 81 | /** Function to perform 2x2 pooling. |
| 82 | * |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 83 | * @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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 87 | */ |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 88 | void pooling2_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
morgolock | cc1f6c9 | 2020-03-24 09:26:48 +0000 | [diff] [blame] | 89 | /** 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 | */ |
morgolock | e383c35 | 2020-04-03 16:57:46 +0100 | [diff] [blame] | 94 | void pooling2_f32_nhwc_maxpool_indices(const Window &window_input, const Window &window); |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 95 | /** Function to perform MxN pooling for 32-bit floating point values. |
| 96 | * |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 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 | * @param[in] pooling_type Pooling operation to be computed. |
| 100 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 101 | */ |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 102 | void poolingMxN_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 103 | /** Function to perform MxN pooling for 32-bit floating point values (NHWC). |
| 104 | * |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 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. |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 109 | */ |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 110 | void poolingMxN_f32_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
| 111 | /** Function to perform 7x7 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 pooling7_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
| 119 | /** Function to perform 3x3 pooling. |
| 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 pooling3_f32_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
| 127 | /** Function to perform 2x2 pooling for float16_t. |
| 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 pooling2_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
Sheri Zhang | e068199 | 2020-07-14 15:29:28 +0100 | [diff] [blame] | 135 | /** Function to perform 2x2 pooling and compute the pooling indices for FP32/FP16. The indices can be used for max unpool. |
| 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 | */ |
| 140 | template <typename T> |
| 141 | void pooling2_nchw_maxpool_indices(const Window &window_input, const Window &window); |
| 142 | /** Function to perform 2x2 pooling and compute the pooling indices. The indices can be used for max unpool. |
| 143 | * |
| 144 | * @param[in] window_input Input region on which to execute the kernel. |
| 145 | * @param[in] window Output region on which to execute the kernel. |
| 146 | */ |
| 147 | void pooling2_f16_nhwc_maxpool_indices(const Window &window_input, const Window &window); |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 148 | /** Function to perform 3x3 pooling. |
| 149 | * |
| 150 | * @param[in] window_input Input region on which to execute the kernel. |
| 151 | * @param[in] window Output region on which to execute the kernel. |
| 152 | * @param[in] pooling_type Pooling operation to be computed. |
| 153 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
| 154 | */ |
| 155 | void pooling3_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
| 156 | /** Function to perform MxN pooling for 16-bit floating point values. |
| 157 | * |
| 158 | * @param[in] window_input Input region on which to execute the kernel. |
| 159 | * @param[in] window Output region on which to execute the kernel. |
| 160 | * @param[in] pooling_type Pooling operation to be computed. |
| 161 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
| 162 | */ |
| 163 | void poolingMxN_f16_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
| 164 | /** Function to perform MxN pooling for 16-bit floating point values. (NHWC) |
| 165 | * |
| 166 | * @param[in] window_input Input region on which to execute the kernel. |
| 167 | * @param[in] window Output region on which to execute the kernel. |
| 168 | * @param[in] pooling_type Pooling operation to be computed. |
| 169 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
| 170 | */ |
| 171 | void poolingMxN_f16_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
Manuel Bottini | b4bb827 | 2019-12-18 18:01:27 +0000 | [diff] [blame] | 172 | /** Template function to perform 2x2 pooling for 8bit quantized fixed point. (NCHW) |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 173 | * |
| 174 | * @param[in] window_input Input region on which to execute the kernel. |
| 175 | * @param[in] window Output region on which to execute the kernel. |
| 176 | * @param[in] pooling_type Pooling operation to be computed. |
| 177 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
| 178 | */ |
Manuel Bottini | b4bb827 | 2019-12-18 18:01:27 +0000 | [diff] [blame] | 179 | template <typename T> |
| 180 | void pooling2_q8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
| 181 | /** Template function to perform 3x3 pooling for 8bit quantized fixed point. (NCHW) |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 182 | * |
| 183 | * @param[in] window_input Input region on which to execute the kernel. |
| 184 | * @param[in] window Output region on which to execute the kernel. |
| 185 | * @param[in] pooling_type Pooling operation to be computed. |
| 186 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
| 187 | */ |
Manuel Bottini | b4bb827 | 2019-12-18 18:01:27 +0000 | [diff] [blame] | 188 | template <typename T> |
| 189 | void pooling3_q8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
| 190 | /** Template function to perform MxN pooling for 8-bit quantized. (NCHW) |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 191 | * |
| 192 | * @param[in] window_input Input region on which to execute the kernel. |
| 193 | * @param[in] window Output region on which to execute the kernel. |
| 194 | * @param[in] pooling_type Pooling operation to be computed. |
| 195 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
| 196 | */ |
Manuel Bottini | b4bb827 | 2019-12-18 18:01:27 +0000 | [diff] [blame] | 197 | template <typename T> |
| 198 | void poolingMxN_q8_nchw(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
| 199 | /** Template function to perform MxN pooling for 8-bit quantized. (NHWC) |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 200 | * |
| 201 | * @param[in] window_input Input region on which to execute the kernel. |
| 202 | * @param[in] window Output region on which to execute the kernel. |
| 203 | * @param[in] pooling_type Pooling operation to be computed. |
| 204 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
| 205 | */ |
Manuel Bottini | b4bb827 | 2019-12-18 18:01:27 +0000 | [diff] [blame] | 206 | template <typename T> |
| 207 | void poolingMxN_q8_nhwc(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding = false); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 208 | /** Common signature for all the specialised Pooling functions |
| 209 | * |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 210 | * @param[in] window_input Input region on which to execute the kernel. |
| 211 | * @param[in] window Output region on which to execute the kernel. |
| 212 | * @param[in] pooling_type Pooling operation to be computed. |
| 213 | * @param[in] exclude_padding Flag to specify exclusion of padding from the operation. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 214 | */ |
Pablo Tello | 77e6c55 | 2018-12-04 15:33:49 +0000 | [diff] [blame] | 215 | using PoolingFunction = void (NEPoolingLayerKernel::*)(const Window &window_input, const Window &window, PoolingType pooling_type, bool exclude_padding); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 216 | |
| 217 | private: |
| 218 | PoolingFunction _func; |
| 219 | const ITensor *_input; |
| 220 | ITensor *_output; |
morgolock | cc1f6c9 | 2020-03-24 09:26:48 +0000 | [diff] [blame] | 221 | ITensor *_indices; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 222 | PoolingLayerInfo _pool_info; |
Georgios Pinitas | 14d9d98 | 2019-12-13 12:33:09 +0000 | [diff] [blame] | 223 | DataLayout _data_layout; |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 224 | unsigned int _num_elems_processed_per_iteration; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 225 | BorderSize _border_size; |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 226 | bool _is_square; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 227 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 228 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 229 | #endif /*ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H */ |