Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 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 | */ |
| 24 | #ifndef __ARM_COMPUTE_CLPADLAYER_H__ |
| 25 | #define __ARM_COMPUTE_CLPADLAYER_H__ |
| 26 | |
| 27 | #include "arm_compute/core/CL/kernels/CLCopyKernel.h" |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/CL/kernels/CLMemsetKernel.h" |
| 29 | #include "arm_compute/core/Types.h" |
Manuel Bottini | 60f3911 | 2019-03-18 15:25:15 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/CL/functions/CLConcatenateLayer.h" |
| 31 | |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 32 | #include "arm_compute/runtime/CL/CLScheduler.h" |
Manuel Bottini | 60f3911 | 2019-03-18 15:25:15 +0000 | [diff] [blame] | 33 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 34 | #include "arm_compute/runtime/CL/functions/CLStridedSlice.h" |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 35 | #include "arm_compute/runtime/IFunction.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | class ICLTensor; |
| 40 | |
| 41 | /** Basic function to pad a tensor. This function calls the following OpenCL kernels: |
| 42 | * |
| 43 | * -# @ref CLMemsetKernel |
| 44 | * -# @ref CLFillBorderKernel |
| 45 | * -# @ref CLCopyKernel |
| 46 | */ |
| 47 | class CLPadLayer : public IFunction |
| 48 | { |
| 49 | public: |
| 50 | /** Default constructor*/ |
| 51 | CLPadLayer(); |
| 52 | |
| 53 | /** Initialize the function |
| 54 | * |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 55 | * @param[in] input Source tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32. |
| 56 | * @param[out] output Output tensor. Data type supported: same as @p input |
| 57 | * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i] |
| 58 | * specifies the front and the end padding in the i-th dimension. |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 59 | * @param[in] constant_value (Optional) Constant value to be used for the padding. |
| 60 | * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT, |
| 61 | * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT). Only CONSTANT |
| 62 | * is currently supported. |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 63 | */ |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 64 | void configure(ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value = PixelValue(), PaddingMode mode = PaddingMode::CONSTANT); |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 65 | |
| 66 | /** Static function to check if given info will lead to a valid configuration of @ref CLPadLayer. |
| 67 | * |
Georgios Pinitas | dea2d2d | 2018-12-19 16:23:17 +0000 | [diff] [blame] | 68 | * @param[in] input Source tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32. |
| 69 | * @param[in] output Output tensor info. 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). Only CONSTANT |
| 75 | * is currently supported. |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 76 | */ |
Usama Arif | 8cf8c11 | 2019-03-14 15:36:54 +0000 | [diff] [blame] | 77 | 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] | 78 | |
| 79 | // Inherited methods overridden: |
| 80 | void run() override; |
| 81 | |
| 82 | private: |
Manuel Bottini | 60f3911 | 2019-03-18 15:25:15 +0000 | [diff] [blame] | 83 | void configure_constant_mode(ICLTensor *input, ICLTensor *output, const PaddingList &padding, const PixelValue constant_value); |
| 84 | void configure_reflect_symmetric_mode(ICLTensor *input, ICLTensor *output); |
| 85 | |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 86 | CLCopyKernel _copy_kernel; |
| 87 | PaddingMode _mode; |
| 88 | PaddingList _padding; |
| 89 | CLMemsetKernel _memset_kernel; |
| 90 | size_t _num_dimensions; |
| 91 | std::vector<CLStridedSlice> _slice_functions; |
| 92 | std::vector<CLConcatenateLayer> _concat_functions; |
| 93 | std::vector<CLTensor> _slice_results; |
| 94 | std::vector<CLTensor> _concat_results; |
Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame] | 95 | }; |
| 96 | } // namespace arm_compute |
| 97 | #endif /*__ARM_COMPUTE_PADLAYER_H__ */ |