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