blob: 8625fd96b413c99fc77c71c332a3024e2fe2d696 [file] [log] [blame]
Michele Di Giorgio19289042021-02-03 16:05:00 +00001/*
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 */
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010024#ifndef ARM_COMPUTE_CPU_POOL2D_ASSEMBLY_WRAPPER_KERNEL_H
25#define ARM_COMPUTE_CPU_POOL2D_ASSEMBLY_WRAPPER_KERNEL_H
Michele Di Giorgio19289042021-02-03 16:05:00 +000026
27#include "arm_compute/core/Types.h"
28#include "src/core/NEON/kernels/assembly/pooling.hpp"
29#include "src/core/common/Macros.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010030#include "src/cpu/ICpuKernel.h"
Michele Di Giorgio19289042021-02-03 16:05:00 +000031
32#include "pool_common.hpp"
33
34namespace arm_compute
35{
36namespace cpu
37{
38namespace 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
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010044 * CpuPool2dAssemblyWrapperKernel and other auxiliary data structures to
Michele Di Giorgio19289042021-02-03 16:05:00 +000045 * execute a single assembly kernel in the context of an NEFunction.
46 *
47 */
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010048class CpuPool2dAssemblyWrapperKernel final : public ICpuKernel
Michele Di Giorgio19289042021-02-03 16:05:00 +000049{
50public:
51 /** Constructor
52 */
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010053 CpuPool2dAssemblyWrapperKernel() = default;
54 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuPool2dAssemblyWrapperKernel);
Michele Di Giorgio19289042021-02-03 16:05:00 +000055
56 const char *name() const override
57 {
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010058 return "CpuPool2dAssemblyWrapperKernel";
Michele Di Giorgio19289042021-02-03 16:05:00 +000059 }
60
61 /** Initialise the kernel's src and dst.
62 *
63 * @param[in] src Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
64 * @param[out] dst Destination tensor info to store the result of pooling. Data types supported: same as @p src.
65 * @param[in] info Pooling meta-data.
66 * @param[in] cpu_info CPU information needed to select the most appropriate kernel.
67 */
68 void configure(const ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, const CPUInfo &cpu_info);
69
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010070 /** Static function to check if given info will lead to a valid configuration
Michele Di Giorgio19289042021-02-03 16:05:00 +000071 *
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010072 * Similar to CpuPool2dAssemblyWrapperKernel::configure()
Michele Di Giorgio19289042021-02-03 16:05:00 +000073 *
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010074 * @return a status
Michele Di Giorgio19289042021-02-03 16:05:00 +000075 */
76 static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &info);
77
78 // Inherited methods overridden:
79 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
80
81 /** Get size of the workspace needed by the assembly kernel.
82 *
83 * @param[in] num_threads Maximum number of threads that are going to be spawned.
84 *
85 * @return size of workspace
86 */
87 size_t get_working_size(unsigned int num_threads) const;
88
89 /** Was the asm kernel successfully configured?
90 *
91 * @return True if the asm kernel is configured and ready to run
92 */
93 bool is_configured() const;
94
95private:
96 /** Helper function to create the assembly kernel.
97 *
98 * @param[in] src Source tensor info.
99 * @param[in] dst Destination tensor info.
100 * @param[in] info Pooling layer meta-data.
101 */
102 template <typename Typesrc, typename Typedst>
103 void create_arm_pooling(const ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, const CPUInfo &cpu_info);
104
105 /** Helper function to create the assembly kernel with requantization support
106 *
107 * @param[in] src Source tensor info.
108 * @param[in] dst Destination tensor info.
109 * @param[in] info Pooling layer meta-data.
110 */
111 template <typename Typesrc, typename Typedst>
112 void create_arm_pooling_requant(const ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, const CPUInfo &cpu_info);
113
114 std::unique_ptr<arm_conv::pooling::IPoolingCommon> _kernel_asm{ nullptr };
Dana Zlotnik4cdd6b82021-10-07 15:31:54 +0300115
116 /** Return minimum workload size of the relevant kernel
117 *
118 * @param[in] platform The CPU platform used to create the context.
119 * @param[in] thread_count Number of threads in the execution.
120 *
121 * @return[out] small_network_mws Minimum workload size for requsted configuration.
122 */
123 size_t get_mws(const CPUInfo &platform, size_t thread_count) const override;
Michele Di Giorgio19289042021-02-03 16:05:00 +0000124};
125} // namespace kernels
126} // namespace cpu
127} // namespace arm_compute
Manuel Bottinib4bb6a02021-05-24 16:01:32 +0100128#endif /* ARM_COMPUTE_CPU_POOL2D_ASSEMBLY_WRAPPER_KERNEL_H */