Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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 | * |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 51 | * @param[in] input Source tensor. Data types supported: QS8/QS16/F16/F32. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 52 | * @param[out] output Destination tensor. Data types supported: Same as @p input. |
| 53 | * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo. |
| 54 | */ |
| 55 | void configure(const ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info); |
| 56 | |
| 57 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 58 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | BorderSize border_size() const override; |
| 60 | |
| 61 | private: |
| 62 | /** Function to perform 2x2 pooling. |
| 63 | * |
| 64 | * @param[in] window_input Input region on which to execute the kernel. |
| 65 | * @param[in] window Output region on which to execute the kernel. |
| 66 | */ |
| 67 | template <PoolingType pooling_type> |
| 68 | void pooling2_f32(const Window &window_input, const Window &window); |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 69 | /** Function to perform 2x2 pooling for float16_t. |
| 70 | * |
| 71 | * @param[in] window_input Input region on which to execute the kernel. |
| 72 | * @param[in] window Output region on which to execute the kernel. |
| 73 | */ |
| 74 | template <PoolingType pooling_type> |
| 75 | void pooling2_f16(const Window &window_input, const Window &window); |
| 76 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 77 | /** Function to perform 2x2 pooling for 8bit fixed point. |
| 78 | * |
| 79 | * @param[in] window_input Input region on which to execute the kernel. |
| 80 | * @param[in] window Output region on which to execute the kernel. |
| 81 | */ |
| 82 | template <PoolingType pooling_type> |
| 83 | void pooling2_q8(const Window &window_input, const Window &window); |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 84 | /** Function to perform 2x2 pooling for 16bit fixed point. |
| 85 | * |
| 86 | * @param[in] window_input Input region on which to execute the kernel. |
| 87 | * @param[in] window Output region on which to execute the kernel. |
| 88 | */ |
| 89 | template <PoolingType pooling_type> |
| 90 | void pooling2_q16(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 91 | /** Function to perform 3x3 pooling. |
| 92 | * |
| 93 | * @param[in] window_input Input region on which to execute the kernel. |
| 94 | * @param[in] window Output region on which to execute the kernel. |
| 95 | */ |
| 96 | template <PoolingType pooling_type> |
| 97 | void pooling3_f32(const Window &window_input, const Window &window); |
Pablo Tello | 0c34fe2 | 2017-06-26 17:17:42 +0100 | [diff] [blame] | 98 | /** Function to perform 3x3 pooling. |
| 99 | * |
| 100 | * @param[in] window_input Input region on which to execute the kernel. |
| 101 | * @param[in] window Output region on which to execute the kernel. |
| 102 | */ |
| 103 | template <PoolingType pooling_type> |
| 104 | void pooling3_f16(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 105 | /** Function to perform 3x3 pooling for 8bit fixed point. |
| 106 | * |
| 107 | * @param[in] window_input Input region on which to execute the kernel. |
| 108 | * @param[in] window Output region on which to execute the kernel. |
| 109 | */ |
| 110 | template <PoolingType pooling_type> |
| 111 | void pooling3_q8(const Window &window_input, const Window &window); |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 112 | /** Function to perform 3x3 pooling for 16bit fixed point. |
| 113 | * |
| 114 | * @param[in] window_input Input region on which to execute the kernel. |
| 115 | * @param[in] window Output region on which to execute the kernel. |
| 116 | */ |
| 117 | template <PoolingType pooling_type> |
| 118 | void pooling3_q16(const Window &window_input, const Window &window); |
Michele Di Giorgio | 8af2dd6 | 2017-06-19 15:19:29 +0100 | [diff] [blame] | 119 | /** Function to perform 7x7 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 | */ |
| 124 | template <PoolingType pooling_type> |
| 125 | void pooling7_f32(const Window &window_input, const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 126 | /** Common signature for all the specialised Pooling functions |
| 127 | * |
| 128 | * @param[in] window_input Input region on which to execute the kernel. |
| 129 | * @param[in] window Output region on which to execute the kernel. |
| 130 | */ |
| 131 | using PoolingFunction = void (NEPoolingLayerKernel::*)(const Window &window_input, const Window &window); |
| 132 | |
| 133 | private: |
| 134 | PoolingFunction _func; |
| 135 | const ITensor *_input; |
| 136 | ITensor *_output; |
| 137 | PoolingLayerInfo _pool_info; |
| 138 | int _num_elems_processed_per_iteration; |
| 139 | BorderSize _border_size; |
| 140 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame^] | 141 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 142 | #endif /*__ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__ */ |