Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 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 | */ |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CPU_POOL2D_ASSEMBLY_WRAPPER_KERNEL_H |
| 25 | #define ARM_COMPUTE_CPU_POOL2D_ASSEMBLY_WRAPPER_KERNEL_H |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/Types.h" |
| 28 | #include "src/core/NEON/kernels/assembly/pooling.hpp" |
| 29 | #include "src/core/common/Macros.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 30 | #include "src/cpu/ICpuKernel.h" |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 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 |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 44 | * CpuPool2dAssemblyWrapperKernel and other auxiliary data structures to |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 45 | * execute a single assembly kernel in the context of an NEFunction. |
| 46 | * |
| 47 | */ |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 48 | class CpuPool2dAssemblyWrapperKernel final : public ICpuKernel |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 49 | { |
| 50 | public: |
| 51 | /** Constructor |
| 52 | */ |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 53 | CpuPool2dAssemblyWrapperKernel() = default; |
| 54 | ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuPool2dAssemblyWrapperKernel); |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 55 | |
| 56 | const char *name() const override |
| 57 | { |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 58 | return "CpuPool2dAssemblyWrapperKernel"; |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 59 | } |
| 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 Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 70 | /** Static function to check if given info will lead to a valid configuration |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 71 | * |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 72 | * Similar to CpuPool2dAssemblyWrapperKernel::configure() |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 73 | * |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 74 | * @return a status |
Michele Di Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 75 | */ |
| 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 | |
| 95 | private: |
| 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 Zlotnik | 4cdd6b8 | 2021-10-07 15:31:54 +0300 | [diff] [blame^] | 115 | |
| 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 Giorgio | 1928904 | 2021-02-03 16:05:00 +0000 | [diff] [blame] | 124 | }; |
| 125 | } // namespace kernels |
| 126 | } // namespace cpu |
| 127 | } // namespace arm_compute |
Manuel Bottini | b4bb6a0 | 2021-05-24 16:01:32 +0100 | [diff] [blame] | 128 | #endif /* ARM_COMPUTE_CPU_POOL2D_ASSEMBLY_WRAPPER_KERNEL_H */ |