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