1 /* 2 * Copyright (c) 2019-2020 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_CLDECONVOLUTIONLAYERRESHAPEOUTPUTKERNEL_H 25 #define ARM_COMPUTE_CLDECONVOLUTIONLAYERRESHAPEOUTPUTKERNEL_H 26 27 #include "src/core/CL/ICLSimpleKernel.h" 28 29 namespace arm_compute 30 { 31 class 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 */ 44 class CLDeconvolutionReshapeOutputKernel : public ICLSimpleKernel 45 { 46 public: 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 * 62 * @param[in] input Input tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/S32/F16/F32. 63 * @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 */ 70 void configure(const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const ITensorInfo *input_info, const ITensorInfo *weights_info, const PadStrideInfo &deconv_info); 71 /** Initialise the kernel's source and destination. 72 * 73 * @param[in] compile_context The compile context to be used. 74 * @param[in] input Input tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/S32/F16/F32. 75 * @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. 76 * @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] 77 * Supported data types: same as @p input. Supported data layouts: same as @p input. 78 * @param[in] input_info Deconvolution input tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input. 79 * @param[in] weights_info Deconvolution weights tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input. 80 * @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. 81 */ 82 void configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *bias, ICLTensor *output, const ITensorInfo *input_info, const ITensorInfo *weights_info, 83 const PadStrideInfo &deconv_info); 84 85 /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionReshapeOutputKernel. 86 * 87 * @param[in] input GEMM output tensor info to be reshaped. Supported data types: QASYMM8/QASYMM8_SIGNED/S32/F16/F32. 88 * @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. 89 * @param[in] output Reshaped output tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input. 90 * @param[in] input_info Original input tensor info. Supported data types: same as @p input. Supported data layouts: same as @p input. 91 * @param[in] weights_info Original weights tensor info output. Supported data types: same as @p input. Supported data layouts: same as @p input. 92 * @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. 93 * 94 * @return a Status 95 */ 96 static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const ITensorInfo *input_info, const ITensorInfo *weights_info, const PadStrideInfo &deconv_info); 97 98 // Inherited methods overridden: 99 void run(const Window &window, cl::CommandQueue &queue) override; 100 101 private: 102 bool _add_bias; 103 const ICLTensor *_bias; 104 }; 105 } // namespace arm_compute 106 #endif /*ARM_COMPUTE_CLDECONVOLUTIONLAYERRESHAPEOUTPUTKERNEL_H */ 107