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: |
| 37 | /** Default constructor */ |
| 38 | NEPoolingLayerKernel(); |
| 39 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 40 | NEPoolingLayerKernel(const NEPoolingLayerKernel &) = delete; |
| 41 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 42 | NEPoolingLayerKernel &operator=(const NEPoolingLayerKernel &) = delete; |
| 43 | /** Allow instances of this class to be moved */ |
| 44 | NEPoolingLayerKernel(NEPoolingLayerKernel &&) = default; |
| 45 | /** Allow instances of this class to be moved */ |
| 46 | NEPoolingLayerKernel &operator=(NEPoolingLayerKernel &&) = default; |
| 47 | /** Default destructor */ |
| 48 | ~NEPoolingLayerKernel() = default; |
| 49 | /** Set the input and output tensors. |
| 50 | * |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 51 | * @note QS8, QS16 and F16 are supported for pool sizes 2 and 3 only |
| 52 | * |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame^] | 53 | * @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] | 54 | * @param[out] output Destination tensor. Data types supported: Same as @p input. |
| 55 | * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo. |
| 56 | */ |
| 57 | void configure(const ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 58 | /** Static function to check if given info will lead to a valid configuration of @ref NEPoolingLayerKernel |
| 59 | * |
| 60 | * @note QS8, QS16 and F16 are supported for pool sizes 2 and 3 only |
| 61 | * |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame^] | 62 | * @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] | 63 | * @param[in] output Destination tensor. Data types supported: Same as @p input. |
| 64 | * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo. |
| 65 | * |
| 66 | * @return a status |
| 67 | */ |
| 68 | 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] | 69 | |
| 70 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 71 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 72 | BorderSize border_size() const override; |
| 73 | |
| 74 | private: |
| 75 | /** Function to perform 2x2 pooling. |
| 76 | * |
| 77 | * @param[in] window_input Input region on which to execute the kernel. |
| 78 | * @param[in] window Output region on which to execute the kernel. |
| 79 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 80 | template <PoolingType pooling_type, bool exclude_padding = false> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 81 | void pooling2_f32(const Window &window_input, const Window &window); |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 82 | /** Function to perform 2x2 pooling for float16_t. |
| 83 | * |
| 84 | * @param[in] window_input Input region on which to execute the kernel. |
| 85 | * @param[in] window Output region on which to execute the kernel. |
| 86 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 87 | template <PoolingType pooling_type, bool exclude_padding = false> |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 88 | void pooling2_f16(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 89 | /** Function to perform 2x2 pooling for 8bit fixed point. |
| 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 | template <PoolingType pooling_type> |
| 95 | void pooling2_q8(const Window &window_input, const Window &window); |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame^] | 96 | /** Function to perform 2x2 pooling for 8bit asymmetric fixed point. |
| 97 | * |
| 98 | * @param[in] window_input Input region on which to execute the kernel. |
| 99 | * @param[in] window Output region on which to execute the kernel. |
| 100 | */ |
| 101 | template <PoolingType pooling_type, bool exclude_padding = false> |
| 102 | void pooling2_qasymm8(const Window &window_input, const Window &window); |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 103 | /** Function to perform 2x2 pooling for 16bit fixed point. |
| 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 | */ |
| 108 | template <PoolingType pooling_type> |
| 109 | void pooling2_q16(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 110 | /** Function to perform 3x3 pooling. |
| 111 | * |
| 112 | * @param[in] window_input Input region on which to execute the kernel. |
| 113 | * @param[in] window Output region on which to execute the kernel. |
| 114 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 115 | template <PoolingType pooling_type, bool exclude_padding = false> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | void pooling3_f32(const Window &window_input, const Window &window); |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 117 | /** Function to perform 3x3 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 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 122 | template <PoolingType pooling_type, bool exclude_padding = false> |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 123 | void pooling3_f16(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 124 | /** Function to perform 3x3 pooling for 8bit fixed point. |
| 125 | * |
| 126 | * @param[in] window_input Input region on which to execute the kernel. |
| 127 | * @param[in] window Output region on which to execute the kernel. |
| 128 | */ |
| 129 | template <PoolingType pooling_type> |
| 130 | void pooling3_q8(const Window &window_input, const Window &window); |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame^] | 131 | /** Function to perform 3x3 pooling for 8bit quantized fixed point. |
| 132 | * |
| 133 | * @param[in] window_input Input region on which to execute the kernel. |
| 134 | * @param[in] window Output region on which to execute the kernel. |
| 135 | */ |
| 136 | template <PoolingType pooling_type, bool exclude_padding = false> |
| 137 | void pooling3_qasymm8(const Window &window_input, const Window &window); |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 138 | /** Function to perform 3x3 pooling for 16bit fixed point. |
| 139 | * |
| 140 | * @param[in] window_input Input region on which to execute the kernel. |
| 141 | * @param[in] window Output region on which to execute the kernel. |
| 142 | */ |
| 143 | template <PoolingType pooling_type> |
| 144 | void pooling3_q16(const Window &window_input, const Window &window); |
Michele Di Giorgio | 8af2dd6 | 2017-06-19 15:19:29 +0100 | [diff] [blame] | 145 | /** Function to perform 7x7 pooling. |
| 146 | * |
| 147 | * @param[in] window_input Input region on which to execute the kernel. |
| 148 | * @param[in] window Output region on which to execute the kernel. |
| 149 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 150 | template <PoolingType pooling_type, bool exclude_padding = false> |
Michele Di Giorgio | 8af2dd6 | 2017-06-19 15:19:29 +0100 | [diff] [blame] | 151 | void pooling7_f32(const Window &window_input, const Window &window); |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 152 | /** Function to perform NxN pooling. |
| 153 | * |
| 154 | * @param[in] window_input Input region on which to execute the kernel. |
| 155 | * @param[in] window Output region on which to execute the kernel. |
| 156 | */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 157 | template <PoolingType pooling_type, bool exclude_padding = false> |
Georgios Pinitas | 5518671 | 2018-01-08 17:37:12 +0000 | [diff] [blame^] | 158 | void poolingN_qasymm8(const Window &window_input, const Window &window); |
| 159 | /** Function to perform NxN pooling. |
| 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 | */ |
| 164 | template <PoolingType pooling_type, bool exclude_padding = false> |
Gian Marco Iodice | 1682430 | 2017-09-28 15:41:37 +0100 | [diff] [blame] | 165 | void poolingN_f32(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 166 | /** Common signature for all the specialised Pooling functions |
| 167 | * |
| 168 | * @param[in] window_input Input region on which to execute the kernel. |
| 169 | * @param[in] window Output region on which to execute the kernel. |
| 170 | */ |
| 171 | using PoolingFunction = void (NEPoolingLayerKernel::*)(const Window &window_input, const Window &window); |
| 172 | |
| 173 | private: |
| 174 | PoolingFunction _func; |
| 175 | const ITensor *_input; |
| 176 | ITensor *_output; |
| 177 | PoolingLayerInfo _pool_info; |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 178 | unsigned int _num_elems_processed_per_iteration; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 179 | BorderSize _border_size; |
| 180 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 181 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 182 | #endif /*__ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__ */ |