blob: fdc18aef3932a786b5cc7059620473338cf6c9a7 [file] [log] [blame]
Michele Di Giorgiod556d7b2020-10-27 10:56:31 +00001/*
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 */
24
25#pragma once
26
27#ifdef CYCLE_PROFILING
28#include "profiler.hpp"
29#endif // CYCLE_PROFILING
30
31namespace arm_conv
32{
33namespace pooling
34{
35enum class PoolingType
36{
37 AVERAGE,
38 MAX,
39};
40
41enum class PoolingMethod
42{
43 DEFAULT,
44 DEPTHFIRST,
45 PLANAR,
46};
47
48struct PoolingWindow
49{
50 unsigned int rows, cols;
51};
52
53struct PoolingStride
54{
55 unsigned int rows, cols;
56};
57
58struct PaddingValues
59{
60 unsigned int left, top, right, bottom;
61};
62
63class IPoolingCommon
64{
65public:
66 virtual ~IPoolingCommon() = default;
67
68 // Determine the amount of working space required.
69 virtual size_t get_working_size(unsigned int num_threads) 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
113struct Nothing
114{
115};
116
117template <typename TInput, typename TOutput, class OutputStage = Nothing>
118class PoolingCommon : public IPoolingCommon
119{
120};
121
122} // namespace pooling
123} // namespace arm_conv