blob: 859de8cc5fb28fbce743e13a83e68a63234aac6d [file] [log] [blame]
Michele Di Giorgio19289042021-02-03 16:05:00 +00001/*
Giorgio Arena5ae8d802021-11-18 18:02:13 +00002 * Copyright (c) 2017-2022 Arm Limited.
Michele Di Giorgio19289042021-02-03 16:05:00 +00003 *
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_KERNEL_H
25#define ARM_COMPUTE_CPU_POOL2D_KERNEL_H
Michele Di Giorgio19289042021-02-03 16:05:00 +000026
27#include "arm_compute/core/Types.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Michele Di Giorgio19289042021-02-03 16:05:00 +000029#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
32namespace arm_compute
33{
34namespace cpu
35{
36namespace kernels
37{
38/** Interface for the pooling layer kernel */
Yair Schwarzbaum46d44d22022-01-12 16:38:58 +020039class CpuPool2dKernel : public ICpuKernel<CpuPool2dKernel>
Michele Di Giorgio19289042021-02-03 16:05:00 +000040{
Giorgio Arena5ae8d802021-11-18 18:02:13 +000041private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010042 using PoolingKernelPtr = std::add_pointer<void(
43 const ITensor *, ITensor *, ITensor *, PoolingLayerInfo &, const Window &, const Window &)>::type;
Giorgio Arena5ae8d802021-11-18 18:02:13 +000044
Michele Di Giorgio19289042021-02-03 16:05:00 +000045public:
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010046 CpuPool2dKernel() = default;
47 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuPool2dKernel);
Michele Di Giorgio19289042021-02-03 16:05:00 +000048 /** Configure kernel for a given list of arguments
49 *
50 * @note F16 are supported for pool sizes 2 and 3 only
51 *
52 * @param[in] src Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
53 * @param[out] dst Destination tensor info. Data types supported: Same as @p src.
54 * @param[in] pool_info Contains pooling operation information described in @ref PoolingLayerInfo.
55 * @param[out] indices (optional) The indices of the maximal values. Data type supported: U32.
56 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010057 void
58 configure(ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &pool_info, ITensorInfo *indices = nullptr);
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010059 /** Static function to check if given info will lead to a valid configuration
Michele Di Giorgio19289042021-02-03 16:05:00 +000060 *
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010061 * Similar to CpuPool2dKernel::configure()
Michele Di Giorgio19289042021-02-03 16:05:00 +000062 *
63 * @return a status
64 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010065 static Status validate(const ITensorInfo *src,
66 const ITensorInfo *dst,
67 const PoolingLayerInfo &pool_info,
68 const ITensorInfo *indices = nullptr);
Michele Di Giorgio19289042021-02-03 16:05:00 +000069
70 // Inherited methods overridden:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010071 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
Sheri Zhang79144a62021-02-08 17:43:04 +000072 const char *name() const override;
Michele Di Giorgio19289042021-02-03 16:05:00 +000073
Giorgio Arena5ae8d802021-11-18 18:02:13 +000074 struct PoolingKernel
75 {
76 const char *name;
77 const PoolDataTypeISASelectorPtr is_selected;
78 PoolingKernelPtr ukernel;
79 };
80
81 static const std::vector<PoolingKernel> &get_available_kernels();
Georgios Pinitas5fdde992021-06-25 05:42:57 +010082
83private:
Michele Di Giorgio19289042021-02-03 16:05:00 +000084 PoolingLayerInfo _pool_info{};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010085 DataLayout _data_layout{DataLayout::UNKNOWN};
86 unsigned int _num_elems_processed_per_iteration{0};
Sheri Zhang79144a62021-02-08 17:43:04 +000087 Size2D _pool_size{};
88 int _pool_stride_x{};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010089 PoolingKernelPtr _run_method{nullptr};
Georgios Pinitas5fdde992021-06-25 05:42:57 +010090 std::string _name{};
Michele Di Giorgio19289042021-02-03 16:05:00 +000091};
92} // namespace kernels
93} // namespace cpu
94} // namespace arm_compute
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010095#endif /* ARM_COMPUTE_CPU_POOL2D_KERNEL_H */