blob: e5b406ee5e2eddfc0cd0c57b0547b4ec80ae85e6 [file] [log] [blame]
Michalis Spyrou780db4e2017-11-23 09:49:51 +00001/*
giuros01a69a88b2019-01-31 16:29:19 +00002 * Copyright (c) 2017-2019 ARM Limited.
Michalis Spyrou780db4e2017-11-23 09:49:51 +00003 *
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_CLDECONVOLUTIONLAYER_H__
25#define __ARM_COMPUTE_CLDECONVOLUTIONLAYER_H__
26
giuros014a8ec802019-03-18 13:25:05 +000027#include "arm_compute/runtime/CL/functions/CLDirectDeconvolutionLayer.h"
giuros0146a49a02019-04-01 13:50:22 +010028#include "arm_compute/runtime/CL/functions/CLGEMMDeconvolutionLayer.h"
Michalis Spyrou780db4e2017-11-23 09:49:51 +000029#include "arm_compute/runtime/IFunction.h"
30#include "arm_compute/runtime/IMemoryManager.h"
31
32#include <memory>
33
34namespace arm_compute
35{
giuros014a8ec802019-03-18 13:25:05 +000036/** Basic function to compute the deconvolution layer. This function calls the following OpenCL kernels/functions:
Michalis Spyrou780db4e2017-11-23 09:49:51 +000037 *
giuros0146a49a02019-04-01 13:50:22 +010038 * -# @ref CLGEMMDeconvolutionLayer
giuros014a8ec802019-03-18 13:25:05 +000039 * -# @ref CLDirectDeconvolutionLayer
Michalis Spyrou780db4e2017-11-23 09:49:51 +000040 */
41class CLDeconvolutionLayer : public IFunction
42{
43public:
giuros014a8ec802019-03-18 13:25:05 +000044 /** Default constructor */
Michalis Spyrou780db4e2017-11-23 09:49:51 +000045 CLDeconvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
giuros014a8ec802019-03-18 13:25:05 +000046
Michalis Spyrou780db4e2017-11-23 09:49:51 +000047 /** Set the input, weights, biases and output tensors.
48 *
giuros0146a49a02019-04-01 13:50:22 +010049 * @note This method will be deprecated in the next release.
giuros01a69a88b2019-01-31 16:29:19 +000050 *
Michele Di Giorgio9fef38a2018-07-06 18:06:58 +010051 * @param[in,out] input Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: QASYMM8/F16/F32.
Michalis Spyroua8ca2b02018-04-04 11:03:51 +010052 * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000053 * @param[in] bias (Optional) The biases have one dimension. Data type supported: Same as @p input.
54 * @param[out] output Output tensor. The output has the same number of dimensions as the @p input.
giuros014a8ec802019-03-18 13:25:05 +000055 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000056 * @param[in] inner_border_right The number of zeros added to right edge of the input.
57 * @param[in] inner_border_top The number of zeros added to top edge of the input.
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +010058 * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref CLWeightsReshapeKernel.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000059 *
60 */
giuros014a8ec802019-03-18 13:25:05 +000061 void configure(ICLTensor *input, ICLTensor *weights, const ICLTensor *bias, ICLTensor *output, const PadStrideInfo &deconv_info,
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +010062 unsigned int inner_border_right, unsigned int inner_border_top, const WeightsInfo &weights_info = WeightsInfo());
Michalis Spyrou780db4e2017-11-23 09:49:51 +000063 /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionLayer
64 *
giuros0146a49a02019-04-01 13:50:22 +010065 * @note This method will be deprecated in the next release.
giuros01a69a88b2019-01-31 16:29:19 +000066 *
Michele Di Giorgio9fef38a2018-07-06 18:06:58 +010067 * @param[in] input Input tensor info. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: QASYMM8/F16/F32.
Michalis Spyroua8ca2b02018-04-04 11:03:51 +010068 * @param[in] weights The 4d weights info with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000069 * @param[in] bias (Optional) The biases have one dimension. Data type supported: Same as @p input.
70 * @param[in] output Output tensor info. The output has the same number of dimensions as the @p input.
giuros014a8ec802019-03-18 13:25:05 +000071 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000072 * @param[in] inner_border_right The number of zeros added to right edge of the input.
73 * @param[in] inner_border_top The number of zeros added to top edge of the input.
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +010074 * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref CLWeightsReshapeKernel.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000075 *
76 * @return a status
77 */
giuros014a8ec802019-03-18 13:25:05 +000078 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, ITensorInfo *output, const PadStrideInfo &deconv_info,
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +010079 unsigned int inner_border_right, unsigned int inner_border_top, const WeightsInfo &weights_info = WeightsInfo());
Michalis Spyrou780db4e2017-11-23 09:49:51 +000080
giuros01a69a88b2019-01-31 16:29:19 +000081 /** Set the input, weights, biases and output tensors.
82 *
83 * @param[in,out] input Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: QASYMM8/F16/F32.
84 * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input.
85 * @param[in] bias (Optional) The biases have one dimension. Data type supported: Same as @p input.
86 * @param[out] output Output tensor. The output has the same number of dimensions as the @p input.
giuros014a8ec802019-03-18 13:25:05 +000087 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo.
giuros01a69a88b2019-01-31 16:29:19 +000088 * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref CLWeightsReshapeKernel.
89 *
90 */
giuros014a8ec802019-03-18 13:25:05 +000091 void configure(ICLTensor *input, ICLTensor *weights, const ICLTensor *bias, ICLTensor *output, const PadStrideInfo &deconv_info, const WeightsInfo &weights_info = WeightsInfo());
giuros01a69a88b2019-01-31 16:29:19 +000092 /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionLayer
93 *
94 * @param[in] input Input tensor info. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: QASYMM8/F16/F32.
95 * @param[in] weights The 4d weights info with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input.
96 * @param[in] bias (Optional) The biases have one dimension. Data type supported: Same as @p input.
97 * @param[in] output Output tensor info. The output has the same number of dimensions as the @p input.
giuros014a8ec802019-03-18 13:25:05 +000098 * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo.
giuros01a69a88b2019-01-31 16:29:19 +000099 * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref CLWeightsReshapeKernel.
100 *
101 * @return a status
102 */
giuros014a8ec802019-03-18 13:25:05 +0000103 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, ITensorInfo *output, const PadStrideInfo &deconv_info,
104 const WeightsInfo &weights_info = WeightsInfo());
giuros01a69a88b2019-01-31 16:29:19 +0000105
giuros0146a49a02019-04-01 13:50:22 +0100106 static DeconvolutionMethod get_deconvolution_method(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, ITensorInfo *output, const PadStrideInfo &deconv_info,
107 const WeightsInfo &weights_info);
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000108 // Inherited methods overridden:
109 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +0100110 void prepare() override;
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000111
112private:
giuros014a8ec802019-03-18 13:25:05 +0000113 std::shared_ptr<IMemoryManager> _memory_manager;
114 std::unique_ptr<IFunction> _function;
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000115};
giuros0146a49a02019-04-01 13:50:22 +0100116} // namespace arm_compute
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +0100117#endif /* __ARM_COMPUTE_CLDECONVOLUTIONLAYER_H__ */