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 27 #include "src/core/NEON/INEKernel.h" 28 29 namespace arm_compute 30 { 31 class ITensor; 32 33 /** Basic kernel to pad the input tensor given padding information. */ 34 class NEPadLayerKernel : public INEKernel 35 { 36 public: name()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 * 56 * @param[in] input Source tensor. Data types supported: All. 57 * @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 * 67 * @param[in] input Source tensor info. Data types supported: All. 68 * @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 82 /** 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 91 private: 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 119 #endif /*ARM_COMPUTE_NEPADLAYERKERNEL_H */ 120