Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [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_CLPADLAYER_H |
| 25 | #define ARM_COMPUTE_CLPADLAYER_H |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 26 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Error.h" |
Manuel Bottini | 60f3911 | 2019-03-18 15:25:15 +0000 | [diff] [blame] | 28 | #include "arm_compute/runtime/CL/CLTensor.h" |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/IFunction.h" |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 30 | |
| 31 | namespace arm_compute |
| 32 | { |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 33 | class CLCompileContext; |
| 34 | class CLPadLayerKernel; |
| 35 | class CLCopyKernel; |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 36 | class ICLTensor; |
| 37 | |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 38 | /** Basic function to pad a tensor. This function calls the following OpenCL functions/kernels: |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 39 | * |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 40 | * -# @ref CLPadLayerKernel if there is padding to be added |
| 41 | * -# @ref CLCopyKernel otherwise |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 42 | */ |
| 43 | class CLPadLayer : public IFunction |
| 44 | { |
| 45 | public: |
Giorgio Arena | 205eed8 | 2019-08-14 10:13:50 +0100 | [diff] [blame] | 46 | /** Default constructor */ |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 47 | CLPadLayer(); |
Giorgio Arena | 205eed8 | 2019-08-14 10:13:50 +0100 | [diff] [blame] | 48 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 49 | CLPadLayer(const CLPadLayer &) = delete; |
| 50 | /** Default move constructor */ |
| 51 | CLPadLayer(CLPadLayer &&) = default; |
| 52 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 53 | CLPadLayer &operator=(const CLPadLayer &) = delete; |
| 54 | /** Default move assignment operator */ |
| 55 | CLPadLayer &operator=(CLPadLayer &&) = default; |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 56 | /** Default destructor */ |
| 57 | ~CLPadLayer(); |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 58 | |
| 59 | /** Initialize the function |
| 60 | * |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame] | 61 | * @param[in] input Source tensor. Data types supported: All. |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 62 | * @param[out] output Output tensor. Data type supported: same as @p input |
| 63 | * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] |
| 64 | * specifies the front and the end padding in the i-th dimension. |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 65 | * @param[in] constant_value (Optional) Constant value to be used for the padding. |
| 66 | * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT, |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 67 | * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT). |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 68 | */ |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 69 | void configure(ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value = PixelValue(), PaddingMode mode = PaddingMode::CONSTANT); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 70 | /** Initialize the function |
| 71 | * |
| 72 | * @param[in] compile_context The compile context to be used. |
| 73 | * @param[in] input Source tensor. Data types supported: All. |
| 74 | * @param[out] output Output tensor. Data type supported: same as @p input |
| 75 | * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] |
| 76 | * specifies the front and the end padding in the i-th dimension. |
| 77 | * @param[in] constant_value (Optional) Constant value to be used for the padding. |
| 78 | * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT, |
| 79 | * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT). |
| 80 | */ |
| 81 | void configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value = PixelValue(), |
| 82 | PaddingMode mode = PaddingMode::CONSTANT); |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 83 | |
| 84 | /** Static function to check if given info will lead to a valid configuration of @ref CLPadLayer. |
| 85 | * |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame] | 86 | * @param[in] input Source tensor info. Data types supported: All. |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 87 | * @param[in] output Output tensor info. Data type supported: same as @p input |
| 88 | * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] |
| 89 | * specifies the front and the end padding in the i-th dimension. |
| 90 | * @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] | 91 | * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT, |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 92 | * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT). |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 93 | */ |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 94 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, PixelValue constant_value = PixelValue(), PaddingMode mode = PaddingMode::CONSTANT); |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 95 | |
| 96 | // Inherited methods overridden: |
| 97 | void run() override; |
| 98 | |
| 99 | private: |
Giorgio Arena | 5c4a8e9 | 2019-08-28 17:55:07 +0100 | [diff] [blame] | 100 | void configure_reflect_mode(ICLTensor *input, ICLTensor *output); |
Manuel Bottini | 60f3911 | 2019-03-18 15:25:15 +0000 | [diff] [blame] | 101 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 102 | std::unique_ptr<CLPadLayerKernel> _pad_kernel; |
| 103 | std::unique_ptr<CLCopyKernel> _copy_kernel; |
| 104 | bool _perform_pad; |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 105 | }; |
| 106 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 107 | #endif /*ARM_COMPUTE_PADLAYER_H */ |