Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEPADLAYER_H |
| 25 | #define ARM_COMPUTE_NEPADLAYER_H |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 28 | #include "arm_compute/runtime/NEON/functions/NEConcatenateLayer.h" |
| 29 | #include "arm_compute/runtime/NEON/functions/NEStridedSlice.h" |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/SubTensor.h" |
| 31 | |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/Types.h" |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 33 | #include "arm_compute/runtime/Tensor.h" |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 34 | #include <memory> |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 35 | |
| 36 | namespace arm_compute |
| 37 | { |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 38 | class NECopyKernel; |
| 39 | class NEPadLayerKernel; |
| 40 | |
Manuel Bottini | 9032ee3 | 2019-08-07 17:04:11 +0100 | [diff] [blame] | 41 | /** Basic function to pad a tensor. This function calls the following NEON functions/kernels: |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 42 | * |
Manuel Bottini | 9032ee3 | 2019-08-07 17:04:11 +0100 | [diff] [blame] | 43 | * - For padding mode = PaddingMode::CONSTANT: |
| 44 | * -# @ref NEPadLayerKernel |
| 45 | * - Otherwise: |
| 46 | * -# @ref NECopyKernel |
| 47 | * -# @ref NEStridedSlice |
| 48 | * -# @ref NEConcatenateLayer |
| 49 | * |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 50 | */ |
| 51 | class NEPadLayer : public IFunction |
| 52 | { |
| 53 | public: |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 54 | /** Default Constructor */ |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 55 | NEPadLayer(); |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 56 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 57 | NEPadLayer(const NEPadLayer &) = delete; |
| 58 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 59 | NEPadLayer &operator=(const NEPadLayer &) = delete; |
| 60 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 61 | NEPadLayer(NEPadLayer &&) = delete; |
| 62 | /** Prevent instances of this class from being moved (As this class contains non movable objects) */ |
| 63 | NEPadLayer &operator=(NEPadLayer &&) = delete; |
| 64 | /** Default destructor */ |
| 65 | ~NEPadLayer(); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 66 | /** Initialize the function |
| 67 | * |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 68 | * @param[in] input Source tensor. Data types supported: All. |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 69 | * @param[out] output Output tensor. 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 |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 73 | * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT, |
| 74 | * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT). |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 75 | */ |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 76 | void configure(ITensor *input, ITensor *output, const PaddingList &padding, const PixelValue constant_value = PixelValue(), const PaddingMode mode = PaddingMode::CONSTANT); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 77 | /** Static function to check if given info will lead to a valid configuration of @ref NEPadLayer. |
| 78 | * |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 79 | * @param[in] input Source tensor info. Data types supported: All. |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 80 | * @param[in] output Output tensor info. Data type supported: same as @p input |
| 81 | * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] |
| 82 | * specifies the front and the end padding in the i-th dimension. |
| 83 | * @param[in] constant_value (Optional) Constant value to be used for the padding |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 84 | * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT, |
| 85 | * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT). |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 86 | * |
| 87 | * @return a status |
| 88 | */ |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 89 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, const PixelValue constant_value = PixelValue(), const PaddingMode mode = PaddingMode::CONSTANT); |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 90 | |
| 91 | // Inherited methods overridden: |
| 92 | void run() override; |
| 93 | |
| 94 | private: |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 95 | /** Configure kernels for when constant padding is used. |
| 96 | * |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 97 | * @param[in] input Source tensor. Data types supported: All. |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 98 | * @param[out] output Output tensor. Data type supported: same as @p input |
| 99 | * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] |
| 100 | * specifies the front and the end padding in the i-th dimension. |
| 101 | * @param[in] constant_value Constant value to be used for the padding |
| 102 | */ |
| 103 | void configure_constant_mode(ITensor *input, ITensor *output, const PaddingList &padding, const PixelValue constant_value); |
| 104 | /** Configure functions for when reflect or symmetric padding is used. |
| 105 | * |
Georgios Pinitas | 3384356 | 2019-12-10 13:33:18 +0000 | [diff] [blame] | 106 | * @param[in] input Source tensor. Data types supported: All. |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 107 | * @param[out] output Output tensor. Data type supported: same as @p input |
| 108 | */ |
| 109 | void configure_reflect_symmetric_mode(ITensor *input, ITensor *output); |
| 110 | |
| 111 | private: |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 112 | std::unique_ptr<NECopyKernel> _copy_kernel; |
| 113 | std::unique_ptr<NEPadLayerKernel> _pad_kernel; |
| 114 | PaddingMode _mode; |
| 115 | PaddingList _padding; |
| 116 | uint32_t _num_dimensions; |
| 117 | std::vector<NEStridedSlice> _slice_functions; |
| 118 | std::vector<NEConcatenateLayer> _concat_functions; |
| 119 | std::vector<Tensor> _slice_results; |
| 120 | std::vector<Tensor> _concat_results; |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 121 | }; |
| 122 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 123 | #endif /*ARM_COMPUTE_NEPADLAYER_H */ |