Compute Library
 21.02
NEPadLayerKernel.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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 #ifndef ARM_COMPUTE_NEPADLAYERKERNEL_H
25 #define ARM_COMPUTE_NEPADLAYERKERNEL_H
26 
28 
29 namespace arm_compute
30 {
31 class ITensor;
32 
33 /** Neon kernel to add padding to a tensor
34  *
35  * Add padding given padding information
36  */
38 {
39 public:
40  const char *name() const override
41  {
42  return "NEPadLayerKernel";
43  }
44  /** Default constructor */
46  /** Prevent instances of this class from being copied (As this class contains pointers) */
47  NEPadLayerKernel(const NEPadLayerKernel &) = delete;
48  /** Prevent instances of this class from being copied (As this class contains pointers) */
49  NEPadLayerKernel &operator=(const NEPadLayerKernel &) = delete;
50  /** Allow instances of this class to be moved */
51  NEPadLayerKernel(NEPadLayerKernel &&) = default;
52  /** Allow instances of this class to be moved */
54  /** Default destructor */
55  ~NEPadLayerKernel() = default;
56 
57  /** Initialize the function
58  *
59  * @param[in] input Source tensor. Data types supported: All.
60  * @param[out] output Output tensor. Data type supported: same as @p input
61  * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i]
62  * specifies the front and the end padding in the i-th dimension.
63  * @param[in] constant_value (Optional) Constant value to be used for the padding
64  * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT.
65  * Only CONSTANT padding mode is currently supported
66  */
67  void configure(ITensor *input, ITensor *output, const PaddingList &padding, const PixelValue constant_value = PixelValue(), const PaddingMode mode = PaddingMode::CONSTANT);
68  /** Static function to check if given info will lead to a valid configuration of @ref NEPadLayer.
69  *
70  * @param[in] input Source tensor info. Data types supported: All.
71  * @param[in] output Output tensor info. Data type supported: same as @p input
72  * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i]
73  * specifies the front and the end padding in the i-th dimension.
74  * @param[in] constant_value (Optional) Constant value to be used for the padding
75  * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT.
76  * Only CONSTANT padding mode is currently supported
77  *
78  * @return a status
79  */
80  static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, const PixelValue constant_value = PixelValue(), const PaddingMode mode = PaddingMode::CONSTANT);
81 
82  // Inherited methods overridden:
83  void run(const Window &window, const ThreadInfo &info) override;
84 
85 private:
86  /** Template function to run the padding function with constant padding
87  *
88  * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
89  */
90  template <typename T>
91  void run_pad_constant(const Window &window);
92 
93  /** Function to run the padding function with constant padding for 3D input and 1D, 2D, 3D 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  void run_pad_constant_uint8_3Dinput_3Dpad(const Window &window);
98 
99  /** Common signature for all the specialised permute functions
100  *
101  * @param[in] window Region on which to execute the kernel.
102  */
103  using PadFunctionPtr = void (NEPadLayerKernel::*)(const Window &window);
104 
105  PadFunctionPtr _func;
106  const ITensor *_input;
107  ITensor *_output;
108  PaddingList _padding;
109  PixelValue _constant_value;
110  PaddingMode _mode;
111 };
112 } // namespace arm_compute
113 #endif /*ARM_COMPUTE_NEPADLAYERKERNEL_H */
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
Neon kernel to add padding to a tensor.
std::vector< PaddingInfo > PaddingList
List of padding information.
Definition: Types.h:481
const char * name() const override
Name of the kernel.
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
NEPadLayerKernel()
Default constructor.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
PaddingMode
Padding mode to use for PadLayer.
Definition: Types.h:169
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, const PixelValue constant_value=PixelValue(), const PaddingMode mode=PaddingMode::CONSTANT)
Static function to check if given info will lead to a valid configuration of NEPadLayer.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
Definition: CPPTypes.h:235
void configure(ITensor *input, ITensor *output, const PaddingList &padding, const PixelValue constant_value=PixelValue(), const PaddingMode mode=PaddingMode::CONSTANT)
Initialize the function.
NEPadLayerKernel & operator=(const NEPadLayerKernel &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
Describe a multidimensional execution window.
Definition: Window.h:39
~NEPadLayerKernel()=default
Default destructor.