Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 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 | */ |
| 24 | #ifndef __ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__ |
| 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
| 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 | * |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 55 | * @note QS8, QS16 and F16 are supported for pool sizes 2 and 3 only |
| 56 | * |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 57 | * @param[in] input Source tensor. Data types supported: QS8/QASYMM8/QS16/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. |
| 60 | */ |
| 61 | void configure(const ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 62 | /** Static function to check if given info will lead to a valid configuration of @ref NEPoolingLayerKernel |
| 63 | * |
| 64 | * @note QS8, QS16 and F16 are supported for pool sizes 2 and 3 only |
| 65 | * |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 66 | * @param[in] input Source tensor. Data types supported: QS8/QASYMM8/QS16/F16/F32. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 67 | * @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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 73 | |
| 74 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 75 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 76 | BorderSize border_size() const override; |
| 77 | |
| 78 | private: |
| 79 | /** Function to perform 2x2 pooling. |
| 80 | * |
| 81 | * @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 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 84 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 85 | void pooling2_f32_nchw(const Window &window_input, const Window &window); |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 86 | /** Function to perform 2x2 pooling for float16_t. |
| 87 | * |
| 88 | * @param[in] window_input Input region on which to execute the kernel. |
| 89 | * @param[in] window Output region on which to execute the kernel. |
| 90 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 91 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 92 | void pooling2_f16_nchw(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 93 | /** Function to perform 2x2 pooling for 8bit fixed point. |
| 94 | * |
| 95 | * @param[in] window_input Input region on which to execute the kernel. |
| 96 | * @param[in] window Output region on which to execute the kernel. |
| 97 | */ |
| 98 | template <PoolingType pooling_type> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 99 | void pooling2_q8_nchw(const Window &window_input, const Window &window); |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 100 | /** Function to perform 2x2 pooling for 8bit asymmetric fixed point. |
| 101 | * |
| 102 | * @param[in] window_input Input region on which to execute the kernel. |
| 103 | * @param[in] window Output region on which to execute the kernel. |
| 104 | */ |
| 105 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 106 | void pooling2_qasymm8_nchw(const Window &window_input, const Window &window); |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 107 | /** Function to perform 2x2 pooling for 16bit fixed point. |
| 108 | * |
| 109 | * @param[in] window_input Input region on which to execute the kernel. |
| 110 | * @param[in] window Output region on which to execute the kernel. |
| 111 | */ |
| 112 | template <PoolingType pooling_type> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 113 | void pooling2_q16_nchw(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 114 | /** Function to perform 3x3 pooling. |
| 115 | * |
| 116 | * @param[in] window_input Input region on which to execute the kernel. |
| 117 | * @param[in] window Output region on which to execute the kernel. |
| 118 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 119 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 120 | void pooling3_f32_nchw(const Window &window_input, const Window &window); |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 121 | /** Function to perform 3x3 pooling. |
| 122 | * |
| 123 | * @param[in] window_input Input region on which to execute the kernel. |
| 124 | * @param[in] window Output region on which to execute the kernel. |
| 125 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 126 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 127 | void pooling3_f16_nchw(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 128 | /** Function to perform 3x3 pooling for 8bit fixed point. |
| 129 | * |
| 130 | * @param[in] window_input Input region on which to execute the kernel. |
| 131 | * @param[in] window Output region on which to execute the kernel. |
| 132 | */ |
| 133 | template <PoolingType pooling_type> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 134 | void pooling3_q8_nchw(const Window &window_input, const Window &window); |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 135 | /** Function to perform 3x3 pooling for 8bit quantized fixed point. |
| 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 <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 141 | void pooling3_qasymm8_nchw(const Window &window_input, const Window &window); |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 142 | /** Function to perform 3x3 pooling for 16bit fixed point. |
| 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 | template <PoolingType pooling_type> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 148 | void pooling3_q16_nchw(const Window &window_input, const Window &window); |
Michele Di Giorgio | 8af2dd6 | 2017-06-19 15:19:29 +0100 | [diff] [blame] | 149 | /** Function to perform 7x7 pooling. |
| 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 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 154 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 155 | void pooling7_f32_nchw(const Window &window_input, const Window &window); |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 156 | /** Function to perform MxN pooling for 8bit fixed point. |
| 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 | */ |
| 161 | template <PoolingType pooling_type> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 162 | void poolingMxN_q8_nchw(const Window &window_input, const Window &window); |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 163 | /** Function to perform MxN pooling for 8-bit quantized. |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 164 | * |
| 165 | * @param[in] window_input Input region on which to execute the kernel. |
| 166 | * @param[in] window Output region on which to execute the kernel. |
| 167 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 168 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 169 | void poolingMxN_qasymm8_nchw(const Window &window_input, const Window &window); |
| 170 | /** Function to perform MxN pooling for 8-bit quantized. (NHWC) |
| 171 | * |
| 172 | * @param[in] window_input Input region on which to execute the kernel. |
| 173 | * @param[in] window Output region on which to execute the kernel. |
| 174 | */ |
| 175 | template <PoolingType pooling_type, bool exclude_padding = false> |
| 176 | void poolingMxN_qasymm8_nhwc(const Window &window_input, const Window &window); |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 177 | /** Function to perform MxN pooling for 16bit fixed point. |
| 178 | * |
| 179 | * @param[in] window_input Input region on which to execute the kernel. |
| 180 | * @param[in] window Output region on which to execute the kernel. |
| 181 | */ |
| 182 | template <PoolingType pooling_type> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 183 | void poolingMxN_q16_nchw(const Window &window_input, const Window &window); |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 184 | /** Function to perform MxN pooling for 16-bit floating point values. |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame] | 185 | * |
| 186 | * @param[in] window_input Input region on which to execute the kernel. |
| 187 | * @param[in] window Output region on which to execute the kernel. |
| 188 | */ |
| 189 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 190 | void poolingMxN_f16_nchw(const Window &window_input, const Window &window); |
| 191 | /** Function to perform MxN pooling for 16-bit floating point values. (NHWC) |
| 192 | * |
| 193 | * @param[in] window_input Input region on which to execute the kernel. |
| 194 | * @param[in] window Output region on which to execute the kernel. |
| 195 | */ |
| 196 | template <PoolingType pooling_type, bool exclude_padding = false> |
| 197 | void poolingMxN_f16_nhwc(const Window &window_input, const Window &window); |
Isabella Gottardi | 7567f5f | 2018-01-30 15:26:00 +0000 | [diff] [blame] | 198 | /** Function to perform MxN pooling for 32-bit floating point values. |
| 199 | * |
| 200 | * @param[in] window_input Input region on which to execute the kernel. |
| 201 | * @param[in] window Output region on which to execute the kernel. |
| 202 | */ |
| 203 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michalis Spyrou | 57dac84 | 2018-03-01 16:03:50 +0000 | [diff] [blame] | 204 | void poolingMxN_f32_nchw(const Window &window_input, const Window &window); |
| 205 | /** Function to perform MxN pooling for 32-bit floating point values (NHWC). |
| 206 | * |
| 207 | * @param[in] window_input Input region on which to execute the kernel. |
| 208 | * @param[in] window Output region on which to execute the kernel. |
| 209 | */ |
| 210 | template <PoolingType pooling_type, bool exclude_padding = false> |
| 211 | void poolingMxN_f32_nhwc(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 212 | /** Common signature for all the specialised Pooling functions |
| 213 | * |
| 214 | * @param[in] window_input Input region on which to execute the kernel. |
| 215 | * @param[in] window Output region on which to execute the kernel. |
| 216 | */ |
| 217 | using PoolingFunction = void (NEPoolingLayerKernel::*)(const Window &window_input, const Window &window); |
| 218 | |
| 219 | private: |
| 220 | PoolingFunction _func; |
| 221 | const ITensor *_input; |
| 222 | ITensor *_output; |
| 223 | PoolingLayerInfo _pool_info; |
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 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 229 | #endif /*__ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__ */ |