• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019-2020 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 
27 #include "src/core/NEON/INEKernel.h"
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  */
37 class NEPadLayerKernel : public INEKernel
38 {
39 public:
name()40     const char *name() const override
41     {
42         return "NEPadLayerKernel";
43     }
44     /** Default constructor */
45     NEPadLayerKernel();
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 */
53     NEPadLayerKernel &operator=(NEPadLayerKernel &&) = default;
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 */
114