Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 Arm Limited. |
| 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 | */ |
| 24 | #ifndef ARM_COMPUTE_CL_TRANSPOSED_CONVOLUTION_H |
| 25 | #define ARM_COMPUTE_CL_TRANSPOSED_CONVOLUTION_H |
| 26 | |
| 27 | #include "src/gpu/cl/ClCompileContext.h" |
| 28 | #include "src/gpu/cl/IClKernel.h" |
| 29 | #include "src/gpu/cl/IClOperator.h" |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | namespace opencl |
| 33 | { |
| 34 | /** Basic function to simulate a directly convolution layer. This function calls the following OpenCL kernels: |
| 35 | * |
| 36 | * -# @ref opencl::ClTransposedConvolution |
| 37 | */ |
| 38 | class ClTransposedConvolution : public IClOperator |
| 39 | { |
| 40 | public: |
| 41 | /** Default constructor */ |
| 42 | ClTransposedConvolution() = default; |
| 43 | /** Default Destructor */ |
| 44 | ~ClTransposedConvolution() = default; |
| 45 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 46 | ClTransposedConvolution(const ClTransposedConvolution &) = delete; |
| 47 | /** Default move constructor */ |
| 48 | ClTransposedConvolution(ClTransposedConvolution &&) = default; |
| 49 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 50 | ClTransposedConvolution &operator=(const ClTransposedConvolution &) = delete; |
| 51 | /** Default move assignment operator */ |
| 52 | ClTransposedConvolution &operator=(ClTransposedConvolution &&) = default; |
| 53 | |
| 54 | /** Set the input, weights, biases and output tensors. |
| 55 | * |
| 56 | * @note: Only NHWC data layout is supported |
| 57 | * |
| 58 | * @param[in] compile_context The compile context to be used. |
| 59 | * @param[in] input Input tensor info with dimensions [IFM, width, height, batch] |
Gunes Bayir | a0ae8d2 | 2022-12-12 17:47:49 +0000 | [diff] [blame] | 60 | * Data types supported: F16/F32/QASYMM8/QASYMM8_SIGNED. |
Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 61 | * @param[in] weights Weight tensor info with dimensions [IFM, width, height, OFM]. |
| 62 | * Data type supported: Same as @p input |
| 63 | * @param[in] biases (Optional) Biases tensor info. Biases are 1D tensor with dimension [OFM]. |
Gunes Bayir | a0ae8d2 | 2022-12-12 17:47:49 +0000 | [diff] [blame] | 64 | * Data type supported: Should match @p input data type if floating point, otherwise S32. |
Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 65 | * @param[out] output Output tensor info with dimensions [OFM, width, height, batch] |
| 66 | * The 1st dimension must be equal to the 4th dimension of the @p weights tensor. |
| 67 | * Data types supported: Same as @p input. |
| 68 | * @param[in] deconv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 69 | * |
| 70 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 71 | void configure(const CLCompileContext &compile_context, |
| 72 | const ITensorInfo *input, |
| 73 | const ITensorInfo *weights, |
| 74 | const ITensorInfo *biases, |
| 75 | ITensorInfo *output, |
| 76 | const PadStrideInfo &deconv_info); |
Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 77 | /** Static function to check if given info will lead to a valid configuration |
| 78 | * |
| 79 | * Similar to ClTransposedConvolution::configure() |
| 80 | * |
| 81 | * @return a status |
| 82 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 83 | static Status validate(const ITensorInfo *input, |
| 84 | const ITensorInfo *weights, |
| 85 | const ITensorInfo *biases, |
| 86 | const ITensorInfo *output, |
| 87 | const PadStrideInfo &deconv_info); |
Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 88 | |
| 89 | // Inherited method overridden |
| 90 | void run(ITensorPack &tensors) override; |
| 91 | |
| 92 | private: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 93 | std::unique_ptr<IClKernel> _transposed_conv_kernel{nullptr}; |
Gunes Bayir | ec0113d | 2022-11-09 09:26:27 +0000 | [diff] [blame] | 94 | }; |
| 95 | } // namespace opencl |
| 96 | } // namespace arm_compute |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 97 | #endif /* ARM_COMPUTE_CL_TRANSPOSED_CONVOLUTION_H */ |