Debian Codegraph @

arm_compute/runtime/NEON/functions/NEPadLayer.h

raw
1 /*
2 * Copyright (c) 2018-2021, 2024 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 #ifndef ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEPADLAYER_H
25 #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEPADLAYER_H
26
27 #include "arm_compute/core/Types.h"
28 #include "arm_compute/runtime/IFunction.h"
29 #include "arm_compute/runtime/NEON/functions/NEConcatenateLayer.h"
30 #include "arm_compute/runtime/NEON/functions/NECopy.h"
31 #include "arm_compute/runtime/NEON/functions/NEStridedSlice.h"
32 #include "arm_compute/runtime/SubTensor.h"
33 #include "arm_compute/runtime/Tensor.h"
34
35 #include <memory>
36
37 namespace arm_compute
38 {
39 class NEPadLayerKernel;
40
41 /** Basic function to pad a tensor. This function calls the following functions/kernels:
42 *
43 * - For padding mode = PaddingMode::CONSTANT:
44 * -# NEPadLayerKernel
45 * - Otherwise:
46 * -# @ref NECopy
47 * -# @ref NEStridedSlice
48 * -# @ref NEConcatenateLayer
49 *
50 */
51 class NEPadLayer : public IFunction
52 {
53 public:
54 /** Default Constructor */
55 NEPadLayer();
56 /** Prevent instances of this class from being copied (As this class contains pointers) */
57 NEPadLayer(const NEPadLayer &) = delete;
58 /** Prevent instances of this class from being copied (As this class contains pointers) */
59 NEPadLayer &operator=(const NEPadLayer &) = delete;
60 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
61 NEPadLayer(NEPadLayer &&) = delete;
62 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
63 NEPadLayer &operator=(NEPadLayer &&) = delete;
64 /** Default destructor */
65 ~NEPadLayer();
66 /** Initialize the function
67 *
68 * Valid data layouts:
69 * - NHWC
70 * - NCHW
71 *
72 * Valid data type configurations:
73 * |src |dst |
74 * |:--------|:---------|
75 * |All |All |
76 *
77 * @param[in] input Source tensor. Data types supported: All.
78 * @param[out] output Output tensor. Data type supported: same as @p input
79 * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i]
80 * specifies the front and the end padding in the i-th dimension.
81 * @param[in] constant_value (Optional) Constant value to be used for the padding
82 * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT,
83 * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT).
84 */
85 void configure(ITensor *input,
86 ITensor *output,
87 const PaddingList &padding,
88 const PixelValue constant_value = PixelValue(),
89 const PaddingMode mode = PaddingMode::CONSTANT);
90 /** Static function to check if given info will lead to a valid configuration of @ref NEPadLayer.
91 *
92 * @param[in] input Source tensor info. Data types supported: All.
93 * @param[in] output Output tensor info. Data type supported: same as @p input
94 * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i]
95 * specifies the front and the end padding in the i-th dimension.
96 * @param[in] constant_value (Optional) Constant value to be used for the padding
97 * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT,
98 * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT).
99 *
100 * @return a status
101 */
102 static Status validate(const ITensorInfo *input,
103 const ITensorInfo *output,
104 const PaddingList &padding,
105 const PixelValue constant_value = PixelValue(),
106 const PaddingMode mode = PaddingMode::CONSTANT);
107
108 // Inherited methods overridden:
109 void run() override;
110
111 private:
112 /** Configure kernels for when constant padding is used.
113 *
114 * @param[in] input Source tensor. Data types supported: All.
115 * @param[out] output Output tensor. Data type supported: same as @p input
116 * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i]
117 * specifies the front and the end padding in the i-th dimension.
118 * @param[in] constant_value Constant value to be used for the padding
119 */
120 void configure_constant_mode(ITensor *input,
121 ITensor *output,
122 const PaddingList &padding,
123 const PixelValue constant_value);
124 /** Configure functions for when reflect or symmetric padding is used.
125 *
126 * @param[in] input Source tensor. Data types supported: All.
127 * @param[out] output Output tensor. Data type supported: same as @p input
128 */
129 void configure_reflect_symmetric_mode(ITensor *input, ITensor *output);
130
131 private:
132 NECopy _copy_function;
133 std::unique_ptr<NEPadLayerKernel> _pad_kernel;
134 PaddingMode _mode;
135 PaddingList _padding;
136 uint32_t _num_dimensions;
137 std::vector<NEStridedSlice> _slice_functions;
138 std::vector<NEConcatenateLayer> _concat_functions;
139 std::vector<Tensor> _slice_results;
140 std::vector<Tensor> _concat_results;
141 };
142 } // namespace arm_compute
143 #endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEPADLAYER_H