1 /* 2 * Copyright (c) 2017-2019 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_GCDIRECTCONVOLUTIONLAYERKERNEL_H 25 #define ARM_COMPUTE_GCDIRECTCONVOLUTIONLAYERKERNEL_H 26 27 #include "arm_compute/core/GLES_COMPUTE/IGCKernel.h" 28 #include "arm_compute/core/GLES_COMPUTE/OpenGLES.h" 29 30 namespace arm_compute 31 { 32 class IGCTensor; 33 34 /** Interface for the direct convolution kernel. 35 */ 36 template <unsigned int kernel_size> 37 class GCDirectConvolutionLayerKernel : public IGCKernel 38 { 39 public: 40 /** Default constructor */ 41 GCDirectConvolutionLayerKernel(); 42 /** Prevent instances of this class from being copied (As this class contains pointers) */ 43 GCDirectConvolutionLayerKernel(const GCDirectConvolutionLayerKernel &) = delete; 44 /** Prevent instances of this class from being copied (As this class contains pointers) */ 45 GCDirectConvolutionLayerKernel &operator=(const GCDirectConvolutionLayerKernel &) = delete; 46 /** Allow instances of this class to be moved */ 47 GCDirectConvolutionLayerKernel(GCDirectConvolutionLayerKernel &&) = default; 48 /** Allow instances of this class to be moved */ 49 GCDirectConvolutionLayerKernel &operator=(GCDirectConvolutionLayerKernel &&) = default; 50 /** Default destructor */ 51 ~GCDirectConvolutionLayerKernel() = default; 52 /** Set the input and output of the kernel. 53 * 54 * @param[in] input The input tensor to convert. 3 lower dimensions represent a single input [width, height, IFM], 55 * while every optional dimension from 4 and above represent a batch of inputs. Data types supported: F16/F32 56 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input. 57 * @param[in] bias Biases tensor. Shared bias supported. Biases are 1D tensor with dimensions [OFM]. Data type supported:Same as @p input. 58 * @param[out] output The output tensor. First 2 lower dimensions represent a transform of each 3D input, 59 * while every dimension above represents a batch. Data types supported: Same as @p input 60 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. 61 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. 62 */ 63 void configure(const IGCTensor *input, const IGCTensor *weights, const IGCTensor *bias, IGCTensor *output, 64 const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 65 66 // Inherited methods overridden: 67 BorderSize border_size() const override; 68 69 // Inherited methods overridden: 70 void run(const Window &window) override; 71 72 private: 73 const IGCTensor *_input; 74 const IGCTensor *_bias; 75 const IGCTensor *_weights; 76 IGCTensor *_output; 77 BorderSize _border_size; 78 int _conv_stride_x; 79 int _conv_stride_y; 80 int _conv_pad_x; 81 int _conv_pad_y; 82 gles::NDRange _lws; 83 }; 84 85 /** Interface for the 1x1 direct convolution kernel */ 86 using GCDirectConvolutionLayer1x1Kernel = GCDirectConvolutionLayerKernel<1>; 87 /** Interface for the 3x3 direct convolution kernel */ 88 using GCDirectConvolutionLayer3x3Kernel = GCDirectConvolutionLayerKernel<3>; 89 /** Interface for the 5x5 direct convolution kernel */ 90 using GCDirectConvolutionLayer5x5Kernel = GCDirectConvolutionLayerKernel<5>; 91 } 92 #endif /*ARM_COMPUTE_GCDIRECTCONVOLUTIONLAYERKERNEL_H */ 93