xref: /aosp_15_r20/external/ComputeLibrary/src/core/NEON/kernels/assembly/pool_common.hpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2021-2022 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  */
24 
25 #pragma once
26 #ifdef CYCLE_PROFILING
27 #include "profiler.hpp"
28 #endif
29 
30 namespace arm_conv
31 {
32 namespace pooling
33 {
34 enum class PoolingType
35 {
36     AVERAGE,
37     MAX,
38 };
39 
40 enum class PoolingMethod
41 {
42     DEFAULT,
43     DEPTHFIRST,
44     PLANAR,
45 };
46 
47 struct PoolingWindow
48 {
49     unsigned int rows, cols;
50 };
51 
52 struct PoolingStride
53 {
54     unsigned int rows, cols;
55 };
56 
57 struct PaddingValues
58 {
59     unsigned int left, top, right, bottom;
60 };
61 
62 class IPoolingCommon
63 {
64 public:
65     virtual ~IPoolingCommon() = default;
66 
67     // Determine the amount of working space required.
68     virtual size_t get_working_size(unsigned int num_threads) const = 0;
69     virtual size_t get_working_size(unsigned int num_threads, unsigned int n_channels) const = 0;
70 
71     // Execute pooling over the specified area of memory.
72     virtual void execute(
73         const void *const input,
74         void *const       output,
75         void             *working_space,
76         unsigned int      thread_id,
77         unsigned int      num_threads) const = 0;
78 
79     virtual void execute(
80         const void *const input,
81         size_t            ld_input_col,
82         size_t            ld_input_row,
83         size_t            ld_input_batch,
84         void *const       output,
85         size_t            ld_output_col,
86         size_t            ld_output_row,
87         size_t            ld_output_batch,
88         void             *working_space,
89         unsigned int      thread_id,
90         unsigned int      num_threads) const = 0;
91 
92     virtual void execute(
93         unsigned int      batches,
94         unsigned int      height,
95         unsigned int      width,
96         unsigned int      channels,
97         const void *const input,
98         size_t            ld_input_col,
99         size_t            ld_input_row,
100         size_t            ld_input_batch,
101         const PaddingValues &,
102         unsigned int output_height,
103         unsigned int output_width,
104         void *const  output,
105         size_t       ld_output_col,
106         size_t       ld_output_row,
107         size_t       ld_output_batch,
108         void        *working_space,
109         unsigned int thread_id,
110         unsigned int num_threads) const = 0;
111 };
112 
113 } // namespace pooling
114 } // namespace arm_conv
115