Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 1 | /* |
Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2022 Arm Limited. |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLDECONVOLUTIONLAYER_H |
| 25 | #define ARM_COMPUTE_CLDECONVOLUTIONLAYER_H |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 26 | |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/CL/functions/CLDirectDeconvolutionLayer.h" |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/CL/functions/CLGEMMDeconvolutionLayer.h" |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 29 | #include "arm_compute/runtime/IFunction.h" |
| 30 | #include "arm_compute/runtime/IMemoryManager.h" |
| 31 | |
| 32 | #include <memory> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 36 | /** Basic function to compute the deconvolution layer. This function calls the following OpenCL kernels/functions: |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 37 | * |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 38 | * -# @ref CLGEMMDeconvolutionLayer |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 39 | * -# @ref CLDirectDeconvolutionLayer |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 40 | */ |
| 41 | class CLDeconvolutionLayer : public IFunction |
| 42 | { |
| 43 | public: |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 44 | /** Default constructor */ |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 45 | CLDeconvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 46 | |
Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 47 | ~CLDeconvolutionLayer(); |
| 48 | |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 49 | /** Set the input, weights, biases and output tensors. |
| 50 | * |
Teresa Charlin | 6268742 | 2021-04-28 10:58:49 +0100 | [diff] [blame] | 51 | * Valid data layouts: |
| 52 | * - NHWC |
| 53 | * - NCHW |
| 54 | * |
| 55 | * Valid data type configurations: |
| 56 | * |src0 |src1 |src2 |dst | |
| 57 | * |:--------------|:------------------|:------|:--------------| |
| 58 | * |F16 |F16 |F16 |F16 | |
| 59 | * |F32 |F32 |F32 |F32 | |
| 60 | * |QASYMM8 |QASYMM8 |S32 |QASYMM8 | |
| 61 | * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |QASYMM8 | |
| 62 | * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED | |
| 63 | * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |QASYMM8_SIGNED | |
| 64 | * |
Sheri Zhang | a14817a | 2020-02-26 10:30:15 +0000 | [diff] [blame] | 65 | * @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_SIGNED/QASYMM8/F16/F32. |
Freddie Liardet | e92b045 | 2021-04-22 14:55:17 +0100 | [diff] [blame] | 66 | * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input or QSYMM8_PER_CHANNEL if @p input is QASYMM8/QASYMM8_SIGNED. |
| 67 | * @param[in] bias (Optional) The biases have one dimension. Data type supported: Should match @p input data type, except for input of QASYMM8 and QASYMM8_SIGNED type where biases should be of S32 type |
giuros01 | a69a88b | 2019-01-31 16:29:19 +0000 | [diff] [blame] | 68 | * @param[out] output Output tensor. The output has the same number of dimensions as the @p input. |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 69 | * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo. |
Manuel Bottini | d87aded | 2021-07-16 10:23:31 +0100 | [diff] [blame] | 70 | * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref opencl::kernels::ClWeightsReshapeKernel. |
giuros01 | a69a88b | 2019-01-31 16:29:19 +0000 | [diff] [blame] | 71 | * |
| 72 | */ |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 73 | void configure(ICLTensor *input, ICLTensor *weights, const ICLTensor *bias, ICLTensor *output, const PadStrideInfo &deconv_info, const WeightsInfo &weights_info = WeightsInfo()); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 74 | /** Set the input, weights, biases and output tensors. |
| 75 | * |
| 76 | * @param[in] compile_context The compile context to be used. |
| 77 | * @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_SIGNED/QASYMM8/F16/F32. |
Freddie Liardet | e92b045 | 2021-04-22 14:55:17 +0100 | [diff] [blame] | 78 | * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input or QSYMM8_PER_CHANNEL if @p input is QASYMM8/QASYMM8_SIGNED. |
| 79 | * @param[in] bias (Optional) The biases have one dimension. Data type supported: Should match @p input data type, except for input of QASYMM8 and QASYMM8_SIGNED type where biases should be of S32 type |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 80 | * @param[out] output Output tensor. The output has the same number of dimensions as the @p input. |
| 81 | * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo. |
Manuel Bottini | d87aded | 2021-07-16 10:23:31 +0100 | [diff] [blame] | 82 | * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref opencl::kernels::ClWeightsReshapeKernel. |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 83 | * |
| 84 | */ |
| 85 | void configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *weights, const ICLTensor *bias, ICLTensor *output, const PadStrideInfo &deconv_info, |
| 86 | const WeightsInfo &weights_info = WeightsInfo()); |
giuros01 | a69a88b | 2019-01-31 16:29:19 +0000 | [diff] [blame] | 87 | /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionLayer |
| 88 | * |
Sheri Zhang | a14817a | 2020-02-26 10:30:15 +0000 | [diff] [blame] | 89 | * @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_SIGNED/QASYMM8/F16/F32. |
Freddie Liardet | e92b045 | 2021-04-22 14:55:17 +0100 | [diff] [blame] | 90 | * @param[in] weights The 4d weights info with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input or QSYMM8_PER_CHANNEL if @p input is QASYMM8/QASYMM8_SIGNED. |
| 91 | * @param[in] bias (Optional) The biases have one dimension. Data type supported: Should match @p input data type, except for input of QASYMM8 and QASYMM8_SIGNED type where biases should be of S32 type |
giuros01 | a69a88b | 2019-01-31 16:29:19 +0000 | [diff] [blame] | 92 | * @param[in] output Output tensor info. The output has the same number of dimensions as the @p input. |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 93 | * @param[in] deconv_info Contains padding and policies to be used in the deconvolution, this is described in @ref PadStrideInfo. |
Manuel Bottini | d87aded | 2021-07-16 10:23:31 +0100 | [diff] [blame] | 94 | * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref opencl::kernels::ClWeightsReshapeKernel. |
giuros01 | a69a88b | 2019-01-31 16:29:19 +0000 | [diff] [blame] | 95 | * |
| 96 | * @return a status |
| 97 | */ |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 98 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, ITensorInfo *output, const PadStrideInfo &deconv_info, |
| 99 | const WeightsInfo &weights_info = WeightsInfo()); |
giuros01 | a69a88b | 2019-01-31 16:29:19 +0000 | [diff] [blame] | 100 | |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 101 | static DeconvolutionMethod get_deconvolution_method(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, ITensorInfo *output, const PadStrideInfo &deconv_info, |
| 102 | const WeightsInfo &weights_info); |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 103 | // Inherited methods overridden: |
| 104 | void run() override; |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 105 | void prepare() override; |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 106 | |
| 107 | private: |
giuros01 | 4a8ec80 | 2019-03-18 13:25:05 +0000 | [diff] [blame] | 108 | std::shared_ptr<IMemoryManager> _memory_manager; |
| 109 | std::unique_ptr<IFunction> _function; |
Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 110 | |
| 111 | struct Impl; |
| 112 | std::unique_ptr<Impl> _impl; |
Michalis Spyrou | 780db4e | 2017-11-23 09:49:51 +0000 | [diff] [blame] | 113 | }; |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 114 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 115 | #endif /* ARM_COMPUTE_CLDECONVOLUTIONLAYER_H */ |