Compute Library
 23.08
CLGEMMConvolutionLayer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021, 2023 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_CLGEMMCONVOLUTIONLAYER_H
25 #define ARM_COMPUTE_CLGEMMCONVOLUTIONLAYER_H
26 
34 
35 #include <memory>
36 
37 namespace arm_compute
38 {
39 // Forward declarations
40 class CLCompileContext;
41 class ICLTensor;
42 class ITensorInfo;
43 
44 /** Basic function to compute the convolution layer. This function calls the following OpenCL kernels/functions:
45  *
46  * -# @ref opencl::ClGemmConv2d
47  */
49 {
50 public:
51  /** Constructor
52  *
53  * @param[in] memory_manager (Optional) Memory manager.
54  * @param[in] weights_manager (Optional) Weights manager.
55  */
56  CLGEMMConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr, IWeightsManager *weights_manager = nullptr);
57  /** Prevent instances of this class from being copied (As this class contains pointers) */
59  /** Default move constructor */
61  /** Prevent instances of this class from being copied (As this class contains pointers) */
63  /** Default move assignment operator */
65  /**Default destructor */
67  /** Set the input and output tensors.
68  *
69  * Valid data layouts:
70  * - NHWC
71  * - NCHW
72  *
73  * Valid data type configurations:
74  * |src0 |src1 |src2 |dst |
75  * |:--------------|:------------------|:--------|:--------------|
76  * |F16 |F16 |F16 |F16 |
77  * |F32 |F32 |F32 |F32 |
78  * |QASYMM8 |QASYMM8 |S32 |QASYMM8 |
79  * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |QASYMM8 |
80  * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED |
81  * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |QASYMM8_SIGNED |
82  *
83  * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
84  * while every optional dimension from 4 and above represent a batch of inputs.
85  * Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
86  * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
87  * Data type supported: Same as @p input or QASYMM8/QSYMM8_PER_CHANNEL when @p input is QASYMM8 or QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when @p input is QASYMM8_SIGNED.
88  * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
89  * Data type supported: Should match @p input data type, except for input of quantized type where biases should be of S32 type.
90  * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
91  * Data types supported: Same as @p input.
92  * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
93  * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. If this is not part of the fully connected layer the weights
94  * tensor has also been transposed with CLGEMMReshapeRHSMatrixKernel. Data type supported: Same as @p input.
95  * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
96  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
97  * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is only supported for NCHW data layout
98  * @param[in] post_ops (Optional) A sequence of post operations that are performed after the main operation.
99  */
100  void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info = WeightsInfo(),
101  const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1,
103  /** Set the input and output tensors.
104  *
105  * @param[in] compile_context The compile context to be used.
106  * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
107  * while every optional dimension from 4 and above represent a batch of inputs.
108  * Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
109  * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
110  * Data type supported: Same as @p input or QASYMM8/QSYMM8_PER_CHANNEL when @p input is QASYMM8 or QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when @p input is QASYMM8_SIGNED.
111  * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
112  * Data type supported: Should match @p input data type, except for input of quantized type where biases should be of S32 type.
113  * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
114  * Data types supported: Same as @p input.
115  * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
116  * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. If this is not part of the fully connected layer the weights
117  * tensor has also been transposed with CLGEMMReshapeRHSMatrixKernel. Data type supported: Same as @p input.
118  * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
119  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
120  * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is only supported for NCHW data layout
121  * @param[in] post_ops (Optional) A sequence of post operations that are performed after the main operation.
122  */
123  void configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info,
125  const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1,
127  /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMConvolutionLayer.
128  *
129  * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
130  * while every optional dimension from 4 and above represent a batch of inputs.
131  * Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
132  * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
133  * Data type supported: Same as @p input or QASYMM8/QSYMM8_PER_CHANNEL when @p input is QASYMM8 or QASYMM8_SIGNED/QSYMM8_PER_CHANNEL when @p input is QASYMM8_SIGNED.
134  * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
135  * Data type supported: Should match @p input data type, except for input of quantized type where biases should be of S32 type.
136  * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
137  * Data types supported: Same as @p input.
138  * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
139  * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. If this is not part of the fully connected layer the weights
140  * tensor has also been transposed with CLGEMMReshapeRHSMatrixKernel. Data type supported: Same as @p input.
141  * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
142  * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
143  * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is only supported for NCHW data layout
144  * @param[in] post_ops (Optional) A sequence of post operations that are performed after the main operation.
145  *
146  * @return a status
147  */
148  static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
149  const WeightsInfo &weights_info = WeightsInfo(), const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1,
151 
152  // Inherited methods overridden:
153  void run() override;
154  void prepare() override;
155 
156 private:
157  struct Impl;
158  std::unique_ptr<Impl> _impl;
159 };
160 } // namespace arm_compute
161 #endif /* ARM_COMPUTE_CLGEMMCONVOLUTIONLAYER_H */
arm_compute::WeightsInfo
Convolution Layer Weights Information class.
Definition: Types.h:1611
IWeightsManager.h
arm_compute::test::validation::weights_info
weights_info
Definition: BatchNormalizationLayer.cpp:165
arm_compute::IFunction
Base class for all functions.
Definition: IFunction.h:30
ActivationLayerInfo.h
arm_compute::CLGEMMConvolutionLayer::run
void run() override
Run the kernels contained in the function.
Definition: CLGEMMConvolutionLayer.cpp:124
arm_compute::ICLTensor
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
arm_compute::Size2D
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
arm_compute::CLGEMMConvolutionLayer::configure
void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), unsigned int num_groups=1, const experimental::PostOpList< ICLTensor * > &post_ops=experimental::PostOpList< ICLTensor * > {})
Set the input and output tensors.
Definition: CLGEMMConvolutionLayer.cpp:71
arm_compute::CLGEMMConvolutionLayer::prepare
void prepare() override
Prepare the function for executing.
Definition: CLGEMMConvolutionLayer.cpp:131
arm_compute::ActivationLayerInfo
Activation Layer Information class.
Definition: ActivationLayerInfo.h:55
arm_compute::test::validation::act_info
act_info
Definition: DirectConvolutionLayer.cpp:547
arm_compute::utils::cast::U
U
Definition: SaturateCast.h:64
IMemoryManager.h
arm_compute::CLCompileContext
CLCompileContext class.
Definition: CLCompileContext.h:204
arm_compute::CLGEMMConvolutionLayer::~CLGEMMConvolutionLayer
~CLGEMMConvolutionLayer()
Default destructor.
arm_compute::CLGEMMConvolutionLayer::validate
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info=WeightsInfo(), const Size2D &dilation=Size2D(1U, 1U), const ActivationLayerInfo &act_info=ActivationLayerInfo(), unsigned int num_groups=1, const experimental::PostOpList< ITensorInfo * > &post_ops=experimental::PostOpList< ITensorInfo * > {})
Static function to check if given info will lead to a valid configuration of CLGEMMConvolutionLayer.
Definition: CLGEMMConvolutionLayer.cpp:117
arm_compute::test::validation::post_ops
experimental::PostOpList< ITensorInfo * > post_ops
Definition: ConvolutionLayer.cpp:413
arm_compute::Status
Status class.
Definition: Error.h:52
arm_compute::CLGEMMConvolutionLayer::operator=
CLGEMMConvolutionLayer & operator=(const CLGEMMConvolutionLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
CLTypes.h
IPostOp.h
arm_compute::PadStrideInfo
Definition: CoreTypes.h:138
IFunction.h
arm_compute::test::validation::num_groups
const unsigned int num_groups
Definition: Im2Col.cpp:153
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::test::validation::conv_info
const auto conv_info
Definition: ConvolutionLayer.cpp:407
CLTensor.h
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:43
arm_compute::IWeightsManager
Weights manager interface to handle weights transformations.
Definition: IWeightsManager.h:36
arm_compute::test::validation::input
auto input
Definition: LSTMLayerQuantized.cpp:486
arm_compute::CLGEMMConvolutionLayer
Basic function to compute the convolution layer.
Definition: CLGEMMConvolutionLayer.h:48
arm_compute::experimental::PostOpList
A sequence of PostOps that can be appended to the end of other operators.
Definition: IPostOp.h:119
arm_compute::CLGEMMConvolutionLayer::CLGEMMConvolutionLayer
CLGEMMConvolutionLayer(std::shared_ptr< IMemoryManager > memory_manager=nullptr, IWeightsManager *weights_manager=nullptr)
Constructor.
Definition: CLGEMMConvolutionLayer.cpp:62