Compute Library
 21.05
CpuPooling.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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_CPU_POOLING_H
25 #define ARM_COMPUTE_CPU_POOLING_H
26 
28 
31 
32 #include <memory>
33 
34 namespace arm_compute
35 {
36 // Forward Declarations
37 struct PoolingLayerInfo;
38 
39 namespace cpu
40 {
41 // Forward Declarations
42 class CpuPoolingAssemblyDispatch;
43 /** Basic function to simulate a pooling layer with the specified pooling operation. This function calls the following kernels:
44  *
45  * -# @ref NEFillBorderKernel (executed if padding size is different from zero)
46  * -# @ref kernels::CpuPoolingKernel
47  * -# @ref CpuPoolingAssemblyDispatch
48  */
49 class CpuPooling : public ICpuOperator
50 {
51 public:
52  /** Constructor */
53  CpuPooling(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
54  /** Prevent instances of this class from being copied (As this class contains pointers) */
55  CpuPooling(const CpuPooling &) = delete;
56  /** Prevent instances of this class from being copied (As this class contains pointers) */
57  CpuPooling &operator=(const CpuPooling &) = delete;
58  /** Prevent instances of this class from being moved (As this class contains non movable objects) */
59  CpuPooling(CpuPooling &&) = delete;
60  /** Prevent instances of this class from being moved (As this class contains non movable objects) */
61  CpuPooling &operator=(CpuPooling &&) = delete;
62  /** Default destructor */
63  ~CpuPooling();
64  /** Set the src and dst tensors.
65  *
66  * @note F16 is supported for pool sizes 2 and 3 only
67  *
68  * @param[in, out] src Source tensor info. (Written to only when padding != 0) Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
69  * @param[out] dst Destination tensor info. Data types supported: same as @p src.
70  * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo.
71  * @param[out] indices (optional) The indices of the maximal values. Data type supported: U32.
72  */
73  void configure(ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &pool_info, ITensorInfo *indices = nullptr);
74  /** Static function to check if given info will lead to a valid configuration of @ref CpuPooling
75  *
76  * @note F16 is supported for pool sizes 2 and 3 only
77  *
78  * @param[in] src Source tensor info. (Written to only when padding != 0) Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
79  * @param[in] dst Destination tensor info. Data types supported: same as @p src.
80  * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo.
81  * @param[in] indices (optional) Tensor info of the indices of the maximal values. Data type supported: U32.
82  *
83  * @return a status
84  */
85  static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &pool_info, const ITensorInfo *indices = nullptr);
86 
87  // Inherited methods overridden:
88  void run(ITensorPack &tensors) override;
89 
90 private:
91  std::shared_ptr<IMemoryManager> _memory_manager;
92 
93  std::unique_ptr<INEKernel> _pooling_layer_kernel;
94  std::unique_ptr<INEKernel> _border_handler;
95  std::unique_ptr<CpuPoolingAssemblyDispatch> _asm_glue;
96 
97  bool _is_global_pooling_layer;
98  DataLayout _data_layout;
99 };
100 } // namespace cpu
101 } // namespace arm_compute
102 #endif /* ARM_COMPUTE_CPU_POOLING_H */
Basic interface for functions which have a single async CPU kernel.
Definition: INEOperator.h:43
Basic function to simulate a pooling layer with the specified pooling operation.
Definition: CpuPooling.h:49
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &pool_info, const ITensorInfo *indices=nullptr)
Static function to check if given info will lead to a valid configuration of CpuPooling.
Definition: CpuPooling.cpp:91
Store the tensor's metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2021 Arm Limited.
~CpuPooling()
Default destructor.
void configure(ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &pool_info, ITensorInfo *indices=nullptr)
Set the src and dst tensors.
Definition: CpuPooling.cpp:43
CpuPooling & operator=(const CpuPooling &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
Pooling Layer Information struct.
Definition: Types.h:1142
CpuPooling(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Constructor.
Definition: CpuPooling.cpp:36
Tensor packing service.
Definition: ITensorPack.h:37
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
Definition: CpuPooling.cpp:103