blob: 8f436b07e39e740ef868eac681933f0c5c78cdf3 [file] [log] [blame]
giuros0146a49a02019-04-01 13:50:22 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
giuros0146a49a02019-04-01 13:50:22 +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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLDECONVOLUTIONLAYERRESHAPEOUTPUTKERNEL_H
25#define ARM_COMPUTE_CLDECONVOLUTIONLAYERRESHAPEOUTPUTKERNEL_H
giuros0146a49a02019-04-01 13:50:22 +010026
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010027#include "src/core/CL/ICLSimpleKernel.h"
giuros0146a49a02019-04-01 13:50:22 +010028
29namespace arm_compute
30{
31class ICLTensor;
32
33/** Interface for the OpenCL kernel to be used for reshaping the tensor before returning the result of deconvolution.
34 *
35 * The input tensor to this OpenCL kernel is expected to be the result of a @ref CLGEMM operation between the Deconvolution input and the Deconvolution filter.
36 *
37 * The input tensor should have the following shape: [filter_width * filter_height * ofms, width, height, batch_size]
38 *
39 * The output tensor should have the following shape: [stride_x * (input_width - 1) + filter_width - 2 * padx, stride_y * (input_height - 1) + filter_height - 2 * pady, ofms, batch_size]
40 *
41 * For example, given a tensor with dimensions [4, 2, 2] this function returns a tensor with dimensions [1, 4, 4].
42 *
43 */
44class CLDeconvolutionReshapeOutputKernel : public ICLSimpleKernel
45{
46public:
47 /** Default constructor */
48 CLDeconvolutionReshapeOutputKernel();
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 CLDeconvolutionReshapeOutputKernel(const CLDeconvolutionReshapeOutputKernel &) = delete;
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 CLDeconvolutionReshapeOutputKernel &operator=(const CLDeconvolutionReshapeOutputKernel &) = delete;
53 /** Allow instances of this class to be moved */
54 CLDeconvolutionReshapeOutputKernel(CLDeconvolutionReshapeOutputKernel &&) = default;
55 /** Allow instances of this class to be moved */
56 CLDeconvolutionReshapeOutputKernel &operator=(CLDeconvolutionReshapeOutputKernel &&) = default;
57 /** Default destructor */
58 ~CLDeconvolutionReshapeOutputKernel() = default;
59
60 /** Initialise the kernel's source and destination.
61 *
Manuel Bottini8481d832019-12-10 15:28:40 +000062 * @param[in] input Input tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/S32/F16/F32.
giuros0146a49a02019-04-01 13:50:22 +010063 * @param[in] bias Bias tensor to be added directly during the reshape operation. Supported data types: same as @p input. Supported data layouts: same as @p input.
64 * @param[out] output Output tensor with the following shape: [stride_x * (input_width - 1) + filter_width - 2 * padx, stride_y * (input_height - 1) + filter_height - 2 * pady, ofms, batch_size]
65 * Supported data types: same as @p input. Supported data layouts: same as @p input.
66 * @param[in] input_info Deconvolution input tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input.
67 * @param[in] weights_info Deconvolution weights tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input.
68 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo. This kernel supports only stride_x = weights.width && stride_y = weights.height. Moreover, padding is not supported.
69 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010070 void configure(const ICLTensor *input,
71 const ICLTensor *bias,
72 ICLTensor *output,
73 const ITensorInfo *input_info,
74 const ITensorInfo *weights_info,
75 const PadStrideInfo &deconv_info);
Manuel Bottini4c6bd512020-04-08 10:15:51 +010076 /** Initialise the kernel's source and destination.
77 *
78 * @param[in] compile_context The compile context to be used.
79 * @param[in] input Input tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/S32/F16/F32.
80 * @param[in] bias Bias tensor to be added directly during the reshape operation. Supported data types: same as @p input. Supported data layouts: same as @p input.
81 * @param[out] output Output tensor with the following shape: [stride_x * (input_width - 1) + filter_width - 2 * padx, stride_y * (input_height - 1) + filter_height - 2 * pady, ofms, batch_size]
82 * Supported data types: same as @p input. Supported data layouts: same as @p input.
83 * @param[in] input_info Deconvolution input tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input.
84 * @param[in] weights_info Deconvolution weights tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input.
85 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo. This kernel supports only stride_x = weights.width && stride_y = weights.height. Moreover, padding is not supported.
86 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 void configure(const CLCompileContext &compile_context,
88 const ICLTensor *input,
89 const ICLTensor *bias,
90 ICLTensor *output,
91 const ITensorInfo *input_info,
92 const ITensorInfo *weights_info,
93 const PadStrideInfo &deconv_info);
giuros0146a49a02019-04-01 13:50:22 +010094
95 /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionReshapeOutputKernel.
96 *
Manuel Bottini8481d832019-12-10 15:28:40 +000097 * @param[in] input GEMM output tensor info to be reshaped. Supported data types: QASYMM8/QASYMM8_SIGNED/S32/F16/F32.
giuros0146a49a02019-04-01 13:50:22 +010098 * @param[in] bias (Optional) Optional bias tensor info to be added directly during the reshape operation. Supported data types: same as @p input. Supported data layouts: same as @p input.
99 * @param[in] output Reshaped output tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input.
100 * @param[in] input_info Original input tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input.
101 * @param[in] weights_info Original weights tensor info output. Supported data types: same as @p input. Supported data layouts: same as @p input.
102 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo. This kernel supports only stride_x = weights.width && stride_y = weights.height. Moreover, padding is not supported.
103 *
104 * @return a Status
105 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100106 static Status validate(const ITensorInfo *input,
107 const ITensorInfo *bias,
108 const ITensorInfo *output,
109 const ITensorInfo *input_info,
110 const ITensorInfo *weights_info,
111 const PadStrideInfo &deconv_info);
giuros0146a49a02019-04-01 13:50:22 +0100112
113 // Inherited methods overridden:
114 void run(const Window &window, cl::CommandQueue &queue) override;
115
116private:
117 bool _add_bias;
118 const ICLTensor *_bias;
119};
120} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000121#endif /*ARM_COMPUTE_CLDECONVOLUTIONLAYERRESHAPEOUTPUTKERNEL_H */