Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 1 | /* |
Pablo Marquez Tello | 68b6dce | 2023-10-05 11:28:15 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021, 2023 Arm Limited. |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 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 | */ |
Pablo Marquez Tello | 68b6dce | 2023-10-05 11:28:15 +0100 | [diff] [blame] | 24 | #ifndef ACL_SRC_CPU_KERNELS_POOL2D_NEON_LIST_H |
| 25 | #define ACL_SRC_CPU_KERNELS_POOL2D_NEON_LIST_H |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/Types.h" |
| 28 | #include "arm_compute/core/utils/misc/Traits.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 30 | #include "src/core/NEON/wrapper/wrapper.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 31 | #include "src/cpu/kernels/pool2d/neon/quantized.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 32 | |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 33 | #include <arm_neon.h> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace cpu |
| 38 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 39 | #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 Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 42 | |
| 43 | DECLARE_POOLING_KERNEL(poolingMxN_qasymm8_neon_nhwc); |
| 44 | DECLARE_POOLING_KERNEL(poolingMxN_qasymm8_signed_neon_nhwc); |
| 45 | DECLARE_POOLING_KERNEL(poolingMxN_fp16_neon_nhwc); |
| 46 | DECLARE_POOLING_KERNEL(poolingMxN_fp32_neon_nhwc); |
| 47 | |
| 48 | #if defined(ENABLE_NCHW_KERNELS) |
| 49 | |
Pablo Marquez Tello | 68b6dce | 2023-10-05 11:28:15 +0100 | [diff] [blame] | 50 | #if defined(ENABLE_FP16_KERNELS) |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 51 | DECLARE_POOLING_KERNEL(pooling2_fp16_neon_nchw); |
| 52 | DECLARE_POOLING_KERNEL(pooling3_fp16_neon_nchw); |
| 53 | DECLARE_POOLING_KERNEL(poolingMxN_fp16_neon_nchw); |
Pablo Marquez Tello | 68b6dce | 2023-10-05 11:28:15 +0100 | [diff] [blame] | 54 | #endif /* defined(ENABLE_FP16_KERNELS) */ |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 55 | |
| 56 | DECLARE_POOLING_KERNEL(pooling2_fp32_neon_nchw); |
| 57 | DECLARE_POOLING_KERNEL(pooling3_fp32_neon_nchw); |
| 58 | DECLARE_POOLING_KERNEL(pooling7_fp32_neon_nchw); |
| 59 | DECLARE_POOLING_KERNEL(poolingMxN_fp32_neon_nchw); |
| 60 | #endif /* defined(ENABLE_NCHW_KERNELS) */ |
| 61 | |
| 62 | #undef DECLARE_POOLING_KERNEL |
| 63 | |
| 64 | template <typename T> |
Adnan AlSinan | 227db8d | 2023-02-14 14:24:09 +0000 | [diff] [blame] | 65 | T 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 | |
| 70 | template <typename T> |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 71 | inline 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 Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 77 | { |
| 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 87 | if (data_layout == DataLayout::NCHW) |
Sheri Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 88 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 89 | 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 Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 95 | |
| 96 | return offset_base; |
| 97 | } |
| 98 | else |
| 99 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 100 | 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 Zhang | 79144a6 | 2021-02-08 17:43:04 +0000 | [diff] [blame] | 105 | - in_stride_w * id[3]; |
| 106 | |
| 107 | return offset_base; |
| 108 | } |
| 109 | } |
| 110 | } // namespace cpu |
| 111 | } // namespace arm_compute |
| 112 | |
Pablo Marquez Tello | 68b6dce | 2023-10-05 11:28:15 +0100 | [diff] [blame] | 113 | #endif // ACL_SRC_CPU_KERNELS_POOL2D_NEON_LIST_H |