Compute Library
 21.05
CpuPoolingAssemblyWrapperKernel.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_ASSEMBLY_WRAPPER_KERNEL_H
25 #define ARM_COMPUTE_CPU_POOLING_ASSEMBLY_WRAPPER_KERNEL_H
26 
27 #include "arm_compute/core/Types.h"
28 #include "src/core/NEON/kernels/assembly/pooling.hpp"
29 #include "src/core/common/Macros.h"
31 
32 #include "pool_common.hpp"
33 
34 namespace arm_compute
35 {
36 namespace cpu
37 {
38 namespace kernels
39 {
40 /** This class is a wrapper for the assembly kernels.
41  *
42  * Some kernels were written in assembly and highly optimised for specific
43  * CPUs like A53 or A55. The arm compute library creates an instance of
44  * CpuPoolingAssemblyWrapperKernel and other auxiliary data structures to
45  * execute a single assembly kernel in the context of an NEFunction.
46  *
47  */
49 {
50 public:
51  /** Constructor
52  */
57 
58  const char *name() const override
59  {
60  return "CpuPoolingAssemblyWrapperKernel";
61  }
62 
63  /** Initialise the kernel's src and dst.
64  *
65  * @param[in] src Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
66  * @param[out] dst Destination tensor info to store the result of pooling. Data types supported: same as @p src.
67  * @param[in] info Pooling meta-data.
68  * @param[in] cpu_info CPU information needed to select the most appropriate kernel.
69  */
70  void configure(const ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, const CPUInfo &cpu_info);
71 
72  /** Indicates whether or not this function can be used to process the given parameters.
73  *
74  * @param[in] src Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
75  * @param[in] dst Destination tensor to store the result of pooling. Data types supported: same as @p src.
76  * @param[in] info Pooling meta-data
77  *
78  * @return a status.
79  */
80  static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &info);
81 
82  // Inherited methods overridden:
83  void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
84 
85  /** Get size of the workspace needed by the assembly kernel.
86  *
87  * @param[in] num_threads Maximum number of threads that are going to be spawned.
88  *
89  * @return size of workspace
90  */
91  size_t get_working_size(unsigned int num_threads) const;
92 
93  /** Was the asm kernel successfully configured?
94  *
95  * @return True if the asm kernel is configured and ready to run
96  */
97  bool is_configured() const;
98 
99 private:
100  /** Helper function to create the assembly kernel.
101  *
102  * @param[in] src Source tensor info.
103  * @param[in] dst Destination tensor info.
104  * @param[in] info Pooling layer meta-data.
105  */
106  template <typename Typesrc, typename Typedst>
107  void create_arm_pooling(const ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, const CPUInfo &cpu_info);
108 
109  /** Helper function to create the assembly kernel with requantization support
110  *
111  * @param[in] src Source tensor info.
112  * @param[in] dst Destination tensor info.
113  * @param[in] info Pooling layer meta-data.
114  */
115  template <typename Typesrc, typename Typedst>
116  void create_arm_pooling_requant(const ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, const CPUInfo &cpu_info);
117 
118  std::unique_ptr<arm_conv::pooling::IPoolingCommon> _kernel_asm{ nullptr };
119 };
120 } // namespace kernels
121 } // namespace cpu
122 } // namespace arm_compute
123 #endif /* ARM_COMPUTE_CPU_POOLING_ASSEMBLY_WRAPPER_KERNEL_H */
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
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.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &info)
Indicates whether or not this function can be used to process the given parameters.
bool is_configured() const
Was the asm kernel successfully configured?
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
Pooling Layer Information struct.
Definition: Types.h:1142
size_t get_working_size(unsigned int num_threads) const
Get size of the workspace needed by the assembly kernel.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
Definition: CPPTypes.h:252
Tensor packing service.
Definition: ITensorPack.h:37
Describe a multidimensional execution window.
Definition: Window.h:39
CpuPoolingAssemblyWrapperKernel & operator=(CpuPoolingAssemblyWrapperKernel &)=delete
void configure(const ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, const CPUInfo &cpu_info)
Initialise the kernel's src and dst.