2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Copyright (c) 2017-2020 ARM Limited.
20 * SPDX-License-Identifier: MIT
22 * Permission is hereby granted, free of charge, to any person obtaining a copy
23 * of this software and associated documentation files (the "Software"), to
24 * deal in the Software without restriction, including without limitation the
25 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
26 * sell copies of the Software, and to permit persons to whom the Software is
27 * furnished to do so, subject to the following conditions:
29 * The above copyright notice and this permission notice shall be included in all
30 * copies or substantial portions of the Software.
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 #ifndef __ARM_COMPUTE_CLTRANSPOSECONVLAYER_H__
41 #define __ARM_COMPUTE_CLTRANSPOSECONVLAYER_H__
43 #include "arm_compute/runtime/CL/functions/CLDirectTransposeConvLayer.h"
44 #include "arm_compute/runtime/CL/functions/CLGEMMDeconvolutionLayer.h"
45 #include "arm_compute/runtime/IFunction.h"
46 #include "arm_compute/runtime/IMemoryManager.h"
52 /** Basic function to compute the deconvolution layer. This function calls the following OpenCL
55 * -# @ref CLGEMMDeconvolutionLayer
56 * -# @ref CLDirectTransposeConvLayer
58 class CLTransposeConvLayer : public IFunction
61 /** Default constructor */
62 CLTransposeConvLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
64 /** Set the input, weights, biases and output tensors.
66 * @param[in,out] input Input tensor. 3 lower dimensions represent a single input,
67 * and an optional 4th dimension for batch of inputs.
68 * Data types supported: QASYMM8_SIGNED/QASYMM8/F16/F32.
69 * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM].
70 * Data type supported: Same as @p input.
71 * @param[in] bias (Optional) The biases have one dimension.
72 * Data type supported: Same as @p input.
73 * @param[out] output Output tensor. The output has the same number of dimensions
75 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution,
76 * this is described in @ref PadStrideInfo.
77 * @param[in] invalid_right The number of zeros added to right edge of the output.
78 * @param[in] invalid_bottom The number of zeros added to bottom edge of the output.
79 * @param[in] weights_info (Optional) Weights information needed for
80 * @ref CLConvolutionLayer, specifies if the weights tensor has
81 * been reshaped with @ref CLWeightsReshapeKernel.
84 void configure(ICLTensor *input, ICLTensor *weights, const ICLTensor *bias, ICLTensor *output,
85 const PadStrideInfo &deconv_info, unsigned int invalid_right,
86 unsigned int invalid_bottom, const WeightsInfo &weights_info = WeightsInfo());
87 /** Set the input, weights, biases and output tensors.
89 * @param[in] compile_context The compile context to be used.
90 * @param[in,out] input Input tensor. 3 lower dimensions represent a single input,
91 * and an optional 4th dimension for batch of inputs.
92 * Data types supported: QASYMM8_SIGNED/QASYMM8/F16/F32.
93 * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM].
94 * Data type supported: Same as @p input.
95 * @param[in] bias (Optional) The biases have one dimension.
96 * Data type supported: Same as @p input.
97 * @param[out] output Output tensor. The output has the same number of dimensions
99 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution,
100 * this is described in @ref PadStrideInfo.
101 * @param[in] invalid_right The number of zeros added to right edge of the output.
102 * @param[in] invalid_bottom The number of zeros added to bottom edge of the output.
103 * @param[in] weights_info (Optional) Weights information needed for
104 * @ref CLConvolutionLayer, specifies if the weights tensor has
105 * been reshaped with @ref CLWeightsReshapeKernel.
108 void configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *weights,
109 const ICLTensor *bias, ICLTensor *output, const PadStrideInfo &deconv_info,
110 unsigned int invalid_right, unsigned int invalid_bottom,
111 const WeightsInfo &weights_info = WeightsInfo());
112 /** Static function to check if given info will lead to a valid configuration of @ref
113 * CLTransposeConvLayer
115 * @param[in] input Input tensor info. 3 lower dimensions represent a single input,
116 * and an optional 4th dimension for batch of inputs.
117 * Data types supported: QASYMM8_SIGNED/QASYMM8/F16/F32.
118 * @param[in] weights The 4d weights info with dimensions [width, height, IFM, OFM].
119 * Data type supported: Same as @p input.
120 * @param[in] bias (Optional) The biases have one dimension.
121 * Data type supported: Same as @p input.
122 * @param[in] output Output tensor info. The output has the same number of dimensions
124 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution,
125 * this is described in @ref PadStrideInfo.
126 * @param[in] invalid_right The number of zeros added to right edge of the output.
127 * @param[in] invalid_bottom The number of zeros added to bottom edge of the output.
128 * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer,
129 * specifies if the weights tensor has been reshaped with
130 * @ref CLWeightsReshapeKernel.
134 static Status validate(const ITensorInfo *input, const ITensorInfo *weights,
135 const ITensorInfo *bias, ITensorInfo *output,
136 const PadStrideInfo &deconv_info, unsigned int invalid_right,
137 unsigned int invalid_bottom,
138 const WeightsInfo &weights_info = WeightsInfo());
140 static DeconvolutionMethod
141 get_deconvolution_method(const ITensorInfo *input, const ITensorInfo *weights,
142 const ITensorInfo *bias, ITensorInfo *output,
143 const PadStrideInfo &deconv_info, unsigned int invalid_right,
144 unsigned int invalid_bottom, const WeightsInfo &weights_info);
145 // Inherited methods overridden:
147 void prepare() override;
150 std::shared_ptr<IMemoryManager> _memory_manager;
151 std::unique_ptr<IFunction> _function;
153 } // namespace arm_compute
154 #endif /* __ARM_COMPUTE_CLTRANSPOSECONVLAYER_H__ */