blob: 58e0cabe63ed2ad6411a7c1097b691c38be09f4e [file] [log] [blame]
Giuseppe Rossinid7647d42018-07-17 18:13:13 +01001/*
Georgios Pinitasdea2d2d2018-12-19 16:23:17 +00002 * Copyright (c) 2018-2019 ARM Limited.
Giuseppe Rossinid7647d42018-07-17 18:13:13 +01003 *
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"
Giorgio Arena205eed82019-08-14 10:13:50 +010028#include "arm_compute/core/CL/kernels/CLPadLayerKernel.h"
Manuel Bottini60f39112019-03-18 15:25:15 +000029#include "arm_compute/runtime/CL/CLTensor.h"
Giorgio Arena205eed82019-08-14 10:13:50 +010030#include "arm_compute/runtime/CL/functions/CLConcatenateLayer.h"
Manuel Bottini60f39112019-03-18 15:25:15 +000031#include "arm_compute/runtime/CL/functions/CLStridedSlice.h"
Giuseppe Rossinid7647d42018-07-17 18:13:13 +010032
33namespace arm_compute
34{
35class ICLTensor;
36
37/** Basic function to pad a tensor. This function calls the following OpenCL kernels:
38 *
39 * -# @ref CLMemsetKernel
40 * -# @ref CLFillBorderKernel
41 * -# @ref CLCopyKernel
42 */
43class CLPadLayer : public IFunction
44{
45public:
Giorgio Arena205eed82019-08-14 10:13:50 +010046 /** Default constructor */
Giuseppe Rossinid7647d42018-07-17 18:13:13 +010047 CLPadLayer();
Giorgio Arena205eed82019-08-14 10:13:50 +010048 /** 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;
Giuseppe Rossinid7647d42018-07-17 18:13:13 +010056
57 /** Initialize the function
58 *
Georgios Pinitasdea2d2d2018-12-19 16:23:17 +000059 * @param[in] input Source tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
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.
Usama Arif8cf8c112019-03-14 15:36:54 +000063 * @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 * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT). Only CONSTANT
66 * is currently supported.
Giuseppe Rossinid7647d42018-07-17 18:13:13 +010067 */
Usama Arif8cf8c112019-03-14 15:36:54 +000068 void configure(ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value = PixelValue(), PaddingMode mode = PaddingMode::CONSTANT);
Giuseppe Rossinid7647d42018-07-17 18:13:13 +010069
70 /** Static function to check if given info will lead to a valid configuration of @ref CLPadLayer.
71 *
Georgios Pinitasdea2d2d2018-12-19 16:23:17 +000072 * @param[in] input Source tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
73 * @param[in] output Output tensor info. Data type supported: same as @p input
74 * @param[in] padding The padding for each spatial dimension of the input tensor. The pair padding[i]
75 * specifies the front and the end padding in the i-th dimension.
76 * @param[in] constant_value (Optional) Constant value to be used for the padding
Usama Arif8cf8c112019-03-14 15:36:54 +000077 * @param[in] mode (Optional) Controls whether the padding should be filled with @p constant_value using CONSTANT,
78 * or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT). Only CONSTANT
79 * is currently supported.
Giuseppe Rossinid7647d42018-07-17 18:13:13 +010080 */
Usama Arif8cf8c112019-03-14 15:36:54 +000081 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, PixelValue constant_value = PixelValue(), PaddingMode mode = PaddingMode::CONSTANT);
Giuseppe Rossinid7647d42018-07-17 18:13:13 +010082
83 // Inherited methods overridden:
84 void run() override;
85
86private:
Manuel Bottini60f39112019-03-18 15:25:15 +000087 void configure_constant_mode(ICLTensor *input, ICLTensor *output, const PaddingList &padding, const PixelValue constant_value);
88 void configure_reflect_symmetric_mode(ICLTensor *input, ICLTensor *output);
89
Giorgio Arena205eed82019-08-14 10:13:50 +010090 CLPadLayerKernel _pad_kernel;
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010091 CLCopyKernel _copy_kernel;
92 PaddingMode _mode;
93 PaddingList _padding;
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010094 size_t _num_dimensions;
95 std::vector<CLStridedSlice> _slice_functions;
96 std::vector<CLConcatenateLayer> _concat_functions;
97 std::vector<CLTensor> _slice_results;
98 std::vector<CLTensor> _concat_results;
Giuseppe Rossinid7647d42018-07-17 18:13:13 +010099};
100} // namespace arm_compute
101#endif /*__ARM_COMPUTE_PADLAYER_H__ */