blob: d432887d2c4f223268b6e2d8ebc29108e18363a7 [file] [log] [blame]
Manuel Bottini9032ee32019-08-07 17:04:11 +01001/*
Matthew Bentham043613f2023-05-30 16:43:14 +00002 * Copyright (c) 2019-2021, 2023 Arm Limited.
Manuel Bottini9032ee32019-08-07 17:04:11 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEPADLAYERKERNEL_H
25#define ARM_COMPUTE_NEPADLAYERKERNEL_H
Manuel Bottini9032ee32019-08-07 17:04:11 +010026
Matthew Bentham043613f2023-05-30 16:43:14 +000027#include "arm_compute/core/PixelValue.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Michalis Spyrouebcebf12020-10-21 00:04:14 +010029#include "src/core/NEON/INEKernel.h"
Manuel Bottini9032ee32019-08-07 17:04:11 +010030
31namespace arm_compute
32{
33class ITensor;
34
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +000035/** Basic kernel to pad the input tensor given padding information. */
Manuel Bottini9032ee32019-08-07 17:04:11 +010036class NEPadLayerKernel : public INEKernel
37{
38public:
39 const char *name() const override
40 {
41 return "NEPadLayerKernel";
42 }
43 /** Default constructor */
44 NEPadLayerKernel();
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 NEPadLayerKernel(const NEPadLayerKernel &) = delete;
47 /** Prevent instances of this class from being copied (As this class contains pointers) */
48 NEPadLayerKernel &operator=(const NEPadLayerKernel &) = delete;
49 /** Allow instances of this class to be moved */
50 NEPadLayerKernel(NEPadLayerKernel &&) = default;
51 /** Allow instances of this class to be moved */
52 NEPadLayerKernel &operator=(NEPadLayerKernel &&) = default;
53 /** Default destructor */
54 ~NEPadLayerKernel() = default;
55
56 /** Initialize the function
57 *
Georgios Pinitas33843562019-12-10 13:33:18 +000058 * @param[in] input Source tensor. Data types supported: All.
Manuel Bottini9032ee32019-08-07 17:04:11 +010059 * @param[out] output Output tensor. Data type supported: same as @p input
60 * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i]
61 * specifies the front and the end padding in the i-th dimension.
62 * @param[in] constant_value (Optional) Constant value to be used for the padding
63 * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT.
64 * Only CONSTANT padding mode is currently supported
65 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010066 void configure(ITensor *input,
67 ITensor *output,
68 const PaddingList &padding,
69 const PixelValue constant_value = PixelValue(),
70 const PaddingMode mode = PaddingMode::CONSTANT);
Manuel Bottini9032ee32019-08-07 17:04:11 +010071 /** Static function to check if given info will lead to a valid configuration of @ref NEPadLayer.
72 *
Georgios Pinitas33843562019-12-10 13:33:18 +000073 * @param[in] input Source tensor info. Data types supported: All.
Manuel Bottini9032ee32019-08-07 17:04:11 +010074 * @param[in] output Output tensor info. Data type supported: same as @p input
75 * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i]
76 * specifies the front and the end padding in the i-th dimension.
77 * @param[in] constant_value (Optional) Constant value to be used for the padding
78 * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT.
79 * Only CONSTANT padding mode is currently supported
80 *
81 * @return a status
82 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010083 static Status validate(const ITensorInfo *input,
84 const ITensorInfo *output,
85 const PaddingList &padding,
86 const PixelValue constant_value = PixelValue(),
87 const PaddingMode mode = PaddingMode::CONSTANT);
Manuel Bottini9032ee32019-08-07 17:04:11 +010088
89 // Inherited methods overridden:
90 void run(const Window &window, const ThreadInfo &info) override;
91
Dana Zlotnik4cdd6b82021-10-07 15:31:54 +030092 /** Return minimum workload size of the relevant kernel
93 *
94 * @param[in] platform The CPU platform used to create the context.
95 * @param[in] thread_count Number of threads in the execution.
96 *
97 * @return[out] small_network_mws Minimum workload size for requsted configuration.
98 */
99 size_t get_mws(const CPUInfo &platform, size_t thread_count) const override;
100
Manuel Bottini9032ee32019-08-07 17:04:11 +0100101private:
102 /** Template function to run the padding function with constant padding
103 *
104 * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
105 */
106 template <typename T>
107 void run_pad_constant(const Window &window);
108
109 /** Function to run the padding function with constant padding for 3D input and 1D, 2D, 3D padding
110 *
111 * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
112 */
113 void run_pad_constant_uint8_3Dinput_3Dpad(const Window &window);
114
115 /** Common signature for all the specialised permute functions
116 *
117 * @param[in] window Region on which to execute the kernel.
118 */
119 using PadFunctionPtr = void (NEPadLayerKernel::*)(const Window &window);
120
121 PadFunctionPtr _func;
122 const ITensor *_input;
123 ITensor *_output;
124 PaddingList _padding;
125 PixelValue _constant_value;
126 PaddingMode _mode;
127};
128} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000129#endif /*ARM_COMPUTE_NEPADLAYERKERNEL_H */