blob: 9d7c75179a68decbc97e130e0a2ad8e6539ea1c1 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
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
29namespace arm_compute
30{
31class ITensor;
32
33/** Interface for the pooling layer kernel */
34class NEPoolingLayerKernel : public INEKernel
35{
36public:
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 Iodice16824302017-09-28 15:41:37 +010051 * @note QS8, QS16 and F16 are supported for pool sizes 2 and 3 only
52 *
Michalis Spyroubbd9fb92017-06-22 12:57:51 +010053 * @param[in] input Source tensor. Data types supported: QS8/QS16/F16/F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054 * @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);
58
59 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010060 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 BorderSize border_size() const override;
62
63private:
64 /** Function to perform 2x2 pooling.
65 *
66 * @param[in] window_input Input region on which to execute the kernel.
67 * @param[in] window Output region on which to execute the kernel.
68 */
69 template <PoolingType pooling_type>
70 void pooling2_f32(const Window &window_input, const Window &window);
Pablo Tello0c34fe22017-06-26 17:17:42 +010071 /** Function to perform 2x2 pooling for float16_t.
72 *
73 * @param[in] window_input Input region on which to execute the kernel.
74 * @param[in] window Output region on which to execute the kernel.
75 */
76 template <PoolingType pooling_type>
77 void pooling2_f16(const Window &window_input, const Window &window);
78
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079 /** Function to perform 2x2 pooling for 8bit fixed point.
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 */
84 template <PoolingType pooling_type>
85 void pooling2_q8(const Window &window_input, const Window &window);
Michalis Spyroubbd9fb92017-06-22 12:57:51 +010086 /** Function to perform 2x2 pooling for 16bit fixed point.
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 */
91 template <PoolingType pooling_type>
92 void pooling2_q16(const Window &window_input, const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093 /** Function to perform 3x3 pooling.
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>
99 void pooling3_f32(const Window &window_input, const Window &window);
Pablo Tello0c34fe22017-06-26 17:17:42 +0100100 /** Function to perform 3x3 pooling.
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>
106 void pooling3_f16(const Window &window_input, const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100107 /** Function to perform 3x3 pooling for 8bit 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>
113 void pooling3_q8(const Window &window_input, const Window &window);
Michalis Spyroubbd9fb92017-06-22 12:57:51 +0100114 /** Function to perform 3x3 pooling for 16bit fixed point.
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 */
119 template <PoolingType pooling_type>
120 void pooling3_q16(const Window &window_input, const Window &window);
Michele Di Giorgio8af2dd62017-06-19 15:19:29 +0100121 /** Function to perform 7x7 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 */
126 template <PoolingType pooling_type>
127 void pooling7_f32(const Window &window_input, const Window &window);
Gian Marco Iodice16824302017-09-28 15:41:37 +0100128 /** Function to perform NxN pooling.
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>
134 void poolingN_f32(const Window &window_input, const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100135 /** Common signature for all the specialised Pooling functions
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 using PoolingFunction = void (NEPoolingLayerKernel::*)(const Window &window_input, const Window &window);
141
142private:
143 PoolingFunction _func;
144 const ITensor *_input;
145 ITensor *_output;
146 PoolingLayerInfo _pool_info;
147 int _num_elems_processed_per_iteration;
148 BorderSize _border_size;
149};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100150} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100151#endif /*__ARM_COMPUTE_NEPOOLINGLAYERKERNEL_H__ */