blob: 5db843d56b7b60d2685de87aadbf0e518bd79af1 [file] [log] [blame]
Sheri Zhang79144a62021-02-08 17:43:04 +00001/*
Pablo Marquez Tello68b6dce2023-10-05 11:28:15 +01002 * Copyright (c) 2021, 2023 Arm Limited.
Sheri Zhang79144a62021-02-08 17:43:04 +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 */
Pablo Marquez Tello68b6dce2023-10-05 11:28:15 +010024#ifndef ACL_SRC_CPU_KERNELS_POOL2D_NEON_LIST_H
25#define ACL_SRC_CPU_KERNELS_POOL2D_NEON_LIST_H
Sheri Zhang79144a62021-02-08 17:43:04 +000026
27#include "arm_compute/core/Types.h"
28#include "arm_compute/core/utils/misc/Traits.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
Sheri Zhang79144a62021-02-08 17:43:04 +000030#include "src/core/NEON/wrapper/wrapper.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010031#include "src/cpu/kernels/pool2d/neon/quantized.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010032
Sheri Zhang79144a62021-02-08 17:43:04 +000033#include <arm_neon.h>
34
35namespace arm_compute
36{
37namespace cpu
38{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010039#define DECLARE_POOLING_KERNEL(func_name) \
40 void func_name(const ITensor *src0, ITensor *dst0, ITensor *dst1, PoolingLayerInfo &, const Window &window_src, \
41 const Window &window)
Sheri Zhang79144a62021-02-08 17:43:04 +000042
43DECLARE_POOLING_KERNEL(poolingMxN_qasymm8_neon_nhwc);
44DECLARE_POOLING_KERNEL(poolingMxN_qasymm8_signed_neon_nhwc);
45DECLARE_POOLING_KERNEL(poolingMxN_fp16_neon_nhwc);
46DECLARE_POOLING_KERNEL(poolingMxN_fp32_neon_nhwc);
47
48#if defined(ENABLE_NCHW_KERNELS)
49
Pablo Marquez Tello68b6dce2023-10-05 11:28:15 +010050#if defined(ENABLE_FP16_KERNELS)
Sheri Zhang79144a62021-02-08 17:43:04 +000051DECLARE_POOLING_KERNEL(pooling2_fp16_neon_nchw);
52DECLARE_POOLING_KERNEL(pooling3_fp16_neon_nchw);
53DECLARE_POOLING_KERNEL(poolingMxN_fp16_neon_nchw);
Pablo Marquez Tello68b6dce2023-10-05 11:28:15 +010054#endif /* defined(ENABLE_FP16_KERNELS) */
Sheri Zhang79144a62021-02-08 17:43:04 +000055
56DECLARE_POOLING_KERNEL(pooling2_fp32_neon_nchw);
57DECLARE_POOLING_KERNEL(pooling3_fp32_neon_nchw);
58DECLARE_POOLING_KERNEL(pooling7_fp32_neon_nchw);
59DECLARE_POOLING_KERNEL(poolingMxN_fp32_neon_nchw);
60#endif /* defined(ENABLE_NCHW_KERNELS) */
61
62#undef DECLARE_POOLING_KERNEL
63
64template <typename T>
Adnan AlSinan227db8d2023-02-14 14:24:09 +000065T get_initial_min(bool use_inf_as_limit)
66{
67 return use_inf_as_limit ? -std::numeric_limits<T>::infinity() : std::numeric_limits<T>::lowest();
68}
69
70template <typename T>
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010071inline uint32_t offset_no_padding(uint32_t padded_offset,
72 const Coordinates &id,
73 const ITensorInfo &info,
74 int pool_stride_x,
75 int pool_stride_y,
76 DataLayout data_layout)
Sheri Zhang79144a62021-02-08 17:43:04 +000077{
78 const int pad_left = info.padding().left;
79 const int pad_right = info.padding().right;
80 const int pad_top = info.padding().top;
81 const int pad_bottom = info.padding().bottom;
82 const int in_stride_y = static_cast<int>(info.strides_in_bytes().y());
83 const int in_stride_w = static_cast<int>(info.strides_in_bytes()[3]);
84 const int pad_horiz = pad_left + pad_right;
85 const int pad_vert = pad_top + pad_bottom;
86
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 if (data_layout == DataLayout::NCHW)
Sheri Zhang79144a62021-02-08 17:43:04 +000088 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010089 const uint32_t offset_base =
90 padded_offset - sizeof(T) * pad_horiz * id.y() * pool_stride_y /* subtract padding elems per row */
91 - pad_top * sizeof(T) /* top padding */
92 - sizeof(T) * pad_horiz * info.tensor_shape()[1] * id.z() -
93 pad_vert * in_stride_y * id.z() /* for each Z plane there are height*pad_right padding elems */
94 - in_stride_w * id[3];
Sheri Zhang79144a62021-02-08 17:43:04 +000095
96 return offset_base;
97 }
98 else
99 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100100 const uint32_t offset_base = padded_offset -
101 sizeof(T) * pad_horiz * id.y() * pool_stride_x // subtract padding elems per row
102 - pad_top * sizeof(T) // top padding
103 - sizeof(T) * pad_horiz * info.tensor_shape()[1] * id.z() *
104 pool_stride_y // for each Z plane there are width*pad_right padding elems
Sheri Zhang79144a62021-02-08 17:43:04 +0000105 - in_stride_w * id[3];
106
107 return offset_base;
108 }
109}
110} // namespace cpu
111} // namespace arm_compute
112
Pablo Marquez Tello68b6dce2023-10-05 11:28:15 +0100113#endif // ACL_SRC_CPU_KERNELS_POOL2D_NEON_LIST_H