blob: e3b7d91187054bb9da554e8c23601c96cb333cd9 [file] [log] [blame]
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +00001/*
Michele Di Giorgiobd2c8e12021-01-19 15:29:02 +00002 * Copyright (c) 2017-2021 Arm Limited.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +00003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEGEMMCONVOLUTIONLAYER_H
25#define ARM_COMPUTE_NEGEMMCONVOLUTIONLAYER_H
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000026
27#include "arm_compute/runtime/IFunction.h"
28
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000029#include "arm_compute/core/Types.h"
Michalis Spyrou1a569a32019-09-10 17:20:34 +010030#include "arm_compute/runtime/IWeightsManager.h"
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000031#include "arm_compute/runtime/MemoryGroup.h"
Gian Marco Iodice597a8562018-08-01 15:06:06 +010032#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000033#include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h"
34#include "arm_compute/runtime/NEON/functions/NEGEMMLowpOutputStage.h"
Gian Marco Iodicedb9d46d2018-08-08 12:29:38 +010035#include "arm_compute/runtime/NEON/functions/NEReshapeLayer.h"
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000036#include "arm_compute/runtime/Tensor.h"
37
38#include <memory>
39
40namespace arm_compute
41{
42class ITensor;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010043class NEWeightsReshapeKernel;
Manuel Bottini90028992021-06-30 18:29:18 +010044namespace cpu
45{
46namespace kernels
47{
48class CpuIm2ColKernel;
Manuel Bottini24b89202021-07-01 18:13:33 +010049class CpuCol2ImKernel;
Manuel Bottini90028992021-06-30 18:29:18 +010050} // namespace kernels
51} // namespace cpu
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000052
Gian Marco Iodice597a8562018-08-01 15:06:06 +010053/** Function to reshape the weights. This function calls the following kernel:
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000054 * -# @ref NEWeightsReshapeKernel
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000055 */
56class NEConvolutionLayerReshapeWeights : public IFunction
57{
58public:
59 /** Constructor */
Pablo Marquez Tello383de022021-03-18 11:31:13 +000060 NEConvolutionLayerReshapeWeights() noexcept;
Michalis Spyrou1a569a32019-09-10 17:20:34 +010061 /** Prevent instances of this class from being copied (As this class contains pointers) */
62 NEConvolutionLayerReshapeWeights(const NEConvolutionLayerReshapeWeights &) = delete;
Michalis Spyrou770dfeb2020-11-04 18:55:34 +000063 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
64 NEConvolutionLayerReshapeWeights(NEConvolutionLayerReshapeWeights &&) = delete;
Michalis Spyrou1a569a32019-09-10 17:20:34 +010065 /** Prevent instances of this class from being copied (As this class contains pointers) */
66 NEConvolutionLayerReshapeWeights &operator=(const NEConvolutionLayerReshapeWeights &) = delete;
Michalis Spyrou770dfeb2020-11-04 18:55:34 +000067 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
68 NEConvolutionLayerReshapeWeights &operator=(NEConvolutionLayerReshapeWeights &&) = delete;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010069 /** Default destructor */
70 ~NEConvolutionLayerReshapeWeights();
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000071 /** Set the input and output tensors.
72 *
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000073 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010074 * Data type supported: All.
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +000075 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010076 * Data type supported: same as @p weights.
77 * @warning Appending biases to weights reshaped matrix is not supported for quantized asymmetric types.
78 * @param[out] output Destination tensor. Data types supported: same as @p weights.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000079 */
Gian Marco Iodice597a8562018-08-01 15:06:06 +010080 void configure(const ITensor *weights, const ITensor *biases, ITensor *output);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000081 /** Static function to check if given info will lead to a valid configuration of @ref NEConvolutionLayerReshapeWeights
82 *
Georgios Pinitasc7b183a2020-03-06 18:12:09 +000083 * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010084 * Data type supported: All.
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +000085 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
Michele Di Giorgiof9b595a2020-07-03 13:34:52 +010086 * Data type supported: same as @p weights.
87 * @warning Appending biases to weights reshaped matrix is not supported for quantized asymmetric types.
88 * @param[in] output Destination tensor. Data types supported: same as @p weights.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000089 *
90 * @return an error status
91 */
Gian Marco Iodice597a8562018-08-01 15:06:06 +010092 static Status validate(const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000093
94 // Inherited methods overridden:
95 void run() override;
96
97private:
Michalis Spyrouebcebf12020-10-21 00:04:14 +010098 std::unique_ptr<NEWeightsReshapeKernel> _weights_reshape_kernel;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000099};
100
Michalis Spyrou1a569a32019-09-10 17:20:34 +0100101namespace weights_transformations
102{
103/** Basic function to manage the reshape weights generated from @ref NEConvolutionLayerReshapeWeights */
104class NEConvolutionLayerReshapeWeightsTransform : public ITransformWeights
105{
106public:
Michalis Spyrouebcebf12020-10-21 00:04:14 +0100107 /** Constructor */
108 NEConvolutionLayerReshapeWeightsTransform() = default;
109 /** Prevent instances of this class from being copied (As this class contains pointers) */
110 NEConvolutionLayerReshapeWeightsTransform(const NEConvolutionLayerReshapeWeightsTransform &) = delete;
111 /** Prevent instances of this class from being copied (As this class contains pointers) */
112 NEConvolutionLayerReshapeWeightsTransform &operator=(const NEConvolutionLayerReshapeWeightsTransform &) = delete;
113 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
114 NEConvolutionLayerReshapeWeightsTransform(NEConvolutionLayerReshapeWeightsTransform &&) = delete;
115 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
116 NEConvolutionLayerReshapeWeightsTransform &operator=(NEConvolutionLayerReshapeWeightsTransform &&) = delete;
117 /** Default destructor */
118 ~NEConvolutionLayerReshapeWeightsTransform() = default;
Michalis Spyrou1a569a32019-09-10 17:20:34 +0100119 void configure(const ITensor *input, const ITensor *biases)
120 {
121 _bias_bit = (biases != nullptr) ? 1 : 0;
122 _func.configure(input, biases, &_output);
123 }
124
125 void run() override
126 {
127 _output.allocator()->allocate();
128 _func.run();
129 _reshape_run = true;
130 }
131
132 ITensor *get_weights() override
133 {
134 return &_output;
135 }
136
137 void release() override
138 {
139 _output.allocator()->free();
140 }
141
142 uint32_t uid() override
143 {
144 return ((0x8) | (_bias_bit << 7));
145 }
146
147 bool is_reshape_run()
148 {
149 return _reshape_run;
150 }
151
152private:
153 Tensor _output{};
154 NEConvolutionLayerReshapeWeights _func{};
155 int32_t _bias_bit{ 0 };
156};
157} // namespace weights_transformations
158
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000159/** Basic function to compute the convolution layer. This function calls the following kernels/functions:
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100160 *
Manuel Bottini90028992021-06-30 18:29:18 +0100161 * -# @ref cpu::kernels::CpuIm2ColKernel
Michele Di Giorgioa602f032020-03-12 19:34:33 +0000162 * -# @ref NEGEMM (if the data type is BFLOAT16/FP16/FP32)
Georgios Pinitas6e1791b2019-12-02 19:01:25 +0000163 * -# @ref NEGEMMLowpMatrixMultiplyCore (if the data type is QASYMM8/QASYMM8_SIGNED)
Manuel Bottiniae58bdf2021-06-17 17:18:45 +0100164 * -# @ref NEGEMMLowpOutputStage (if the data type is QASYMM8/QASYMM8_SIGNED)
Michele Di Giorgiobd2c8e12021-01-19 15:29:02 +0000165 * -# @ref NEArithmeticAddition (if biases != nullptr and we have a 1x1 convolution with the NHWC data layout)
Manuel Bottini24b89202021-07-01 18:13:33 +0100166 * -# @ref cpu::kernels::CpuCol2ImKernel (if NCHW data layout)
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100167 *
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000168 */
169class NEGEMMConvolutionLayer : public IFunction
170{
171public:
172 /** Constructor */
Michalis Spyrou1a569a32019-09-10 17:20:34 +0100173 NEGEMMConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager = nullptr, IWeightsManager *weights_manager = nullptr);
Georgios Pinitas1562be32018-03-08 19:09:19 +0000174 /** Prevent instances of this class from being copied (As this class contains pointers) */
175 NEGEMMConvolutionLayer(const NEGEMMConvolutionLayer &) = delete;
Michalis Spyrou770dfeb2020-11-04 18:55:34 +0000176 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
177 NEGEMMConvolutionLayer(NEGEMMConvolutionLayer &&) = delete;
Georgios Pinitas1562be32018-03-08 19:09:19 +0000178 /** Prevent instances of this class from being copied (As this class contains pointers) */
179 NEGEMMConvolutionLayer &operator=(const NEGEMMConvolutionLayer &) = delete;
Michalis Spyrou770dfeb2020-11-04 18:55:34 +0000180 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
181 NEGEMMConvolutionLayer &operator=(NEGEMMConvolutionLayer &&) = delete;
Michalis Spyrouebcebf12020-10-21 00:04:14 +0100182 /** Default destructor */
183 ~NEGEMMConvolutionLayer();
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000184 /** Set the input and output tensors.
185 *
Teresa Charlin62687422021-04-28 10:58:49 +0100186 * Valid data layouts:
187 * - NHWC
188 * - NCHW
189 *
190 * Valid data type configurations:
191 * |src0 |src1 |src2 |dst |
192 * |:--------------|:------------------|:--------|:--------------|
193 * |F16 |F16 |F16 |F16 |
194 * |F32 |F32 |F32 |F32 |
195 * |BFLOAT16 |BFLOAT16 |BFLOAT16 |BFLOAT16 |
196 * |QASYMM8 |QASYMM8 |S32 |QASYMM8 |
197 * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |QASYMM8 |
198 * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED |
199 * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |QASYMM8_SIGNED |
200 *
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000201 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
202 * while every optional dimension from 4 and above represent a batch of inputs.
Georgios Pinitasc7b183a2020-03-06 18:12:09 +0000203 * Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
204 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
205 * Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000206 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
Georgios Pinitas6e1791b2019-12-02 19:01:25 +0000207 * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000208 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
209 * Data types supported: Same as @p input.
210 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
211 * @param[in] weights_info Specifies if the weights tensor has been reshaped with NEWeightsReshapeKernel. If this is not part of the fully connected layer the weights
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100212 * tensor has also been transposed with cpu::kernels::CpuGemmTranspose1xWKernel. Data type supported: Same as @p input.
Alex Gilday7da29b62018-03-23 14:16:00 +0000213 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000214 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +0100215 * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000216 */
Alex Gilday7da29b62018-03-23 14:16:00 +0000217 void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info = WeightsInfo(),
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +0100218 const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000219 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMConvolutionLayer
220 *
Georgios Pinitas6e1791b2019-12-02 19:01:25 +0000221 * @param[in] input Source tensor info. 3 lower dimensions represent a single input [width, height, IFM],
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000222 * while every optional dimension from 4 and above represent a batch of inputs.
Georgios Pinitasc7b183a2020-03-06 18:12:09 +0000223 * Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
224 * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM].
225 * Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32.
Georgios Pinitas6e1791b2019-12-02 19:01:25 +0000226 * @param[in] biases Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
227 * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type.
228 * @param[in] output Destination tensor info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000229 * Data types supported: Same as @p input.
230 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
231 * @param[in] weights_info Specifies if the weights tensor has been reshaped with NEWeightsReshapeKernel. If this is not part of the fully connected layer the weights
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100232 * tensor has also been transposed with cpu::kernels::CpuGemmTranspose1xWKernel. Data type supported: Same as @p input.
Alex Gilday7da29b62018-03-23 14:16:00 +0000233 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000234 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +0100235 * @param[in] num_groups (Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000236 *
237 * @return a status
238 */
239 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +0100240 const WeightsInfo &weights_info = WeightsInfo(), const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), unsigned int num_groups = 1);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000241
242 // Inherited methods overridden:
243 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +0100244 void prepare() override;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000245
246private:
247 /** Configures the appropriate matrix multiply routine
248 *
Georgios Pinitasc7b183a2020-03-06 18:12:09 +0000249 * @param[in] input Input tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
250 * @param[in] weights Weights tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32.
George Wort2d7e6832019-02-22 16:37:41 +0000251 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
Georgios Pinitas6e1791b2019-12-02 19:01:25 +0000252 * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type.
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100253 * @param[out] output Output tensor. Data types supported: Same as @p input,
Georgios Pinitas6e1791b2019-12-02 19:01:25 +0000254 * except for input of QASYMM8/QASYMM8_SIGNED type where output should be of S32 type.
George Wort2d7e6832019-02-22 16:37:41 +0000255 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100256 * @param[in] gemm_3d_depth (Optional) Depth of GEMM 3D (Defaults to 1)
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000257 */
George Wort2d7e6832019-02-22 16:37:41 +0000258 void configure_mm(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const ActivationLayerInfo &act_info = ActivationLayerInfo(), int gemm_3d_depth = 1);
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100259 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMConvolutionLayer matrix multiply routines
260 *
Georgios Pinitasc7b183a2020-03-06 18:12:09 +0000261 * @param[in] input Input tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
262 * @param[in] weights Weights tensor info. Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL/BFLOAT16/F16/F32.
Georgios Pinitas6e1791b2019-12-02 19:01:25 +0000263 * @param[in] biases Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
264 * Data type supported: Should match @p input data type, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type.
265 * @param[in] output Output tensor info. Data types supported: Same as @p input,
266 * except for input of QASYMM8/QASYMM8_SIGNED type where output should be of S32 type.
George Wort2d7e6832019-02-22 16:37:41 +0000267 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100268 * @param[in] gemm_3d_depth (Optional) Depth of GEMM 3D (Defaults to 1)
269 * @param[in] skip_im2col (Optional) Flag which specifies if im2col has to be skipped. i.e. 1x1 convolution with NHWC data layout. (Default to false)
270 *
271 * @return a status
272 */
George Wort2d7e6832019-02-22 16:37:41 +0000273 static Status validate_mm(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo(),
274 int gemm_3d_depth = 1, bool skip_im2col = false);
Gian Marco Iodicedb9d46d2018-08-08 12:29:38 +0100275 /** Static function to check if GEMM3D is supported in @ref NEGEMM or in @ref NEGEMMLowpMatrixMultiplyCore
276 *
Georgios Pinitasc7b183a2020-03-06 18:12:09 +0000277 * @param[in] input_info Input tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
278 * @param[in] weights_info Weights tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32.
George Wort2d7e6832019-02-22 16:37:41 +0000279 * @param[in] act_info Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Gian Marco Iodicedb9d46d2018-08-08 12:29:38 +0100280 * @param[in] gemm_3d_depth Depth of GEMM 3D
281 * @param[in] skip_im2col Flag which specifies if im2col has to be skipped. i.e. 1x1 convolution with NHWC data layout
282 *
283 * @return a status
284 */
Giorgio Arena7a669a82019-11-13 17:07:13 +0000285 static Status validate_gemm3d(const ITensorInfo *input_info, const ITensorInfo *weights_info, const ActivationLayerInfo &act_info, int gemm_3d_depth, bool skip_im2col);
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000286
287private:
Michalis Spyrou1a569a32019-09-10 17:20:34 +0100288 MemoryGroup _memory_group;
289 IWeightsManager *_weights_manager;
290 NEConvolutionLayerReshapeWeights _reshape_weights;
291 weights_transformations::NEConvolutionLayerReshapeWeightsTransform _reshape_weights_managed;
Manuel Bottini90028992021-06-30 18:29:18 +0100292 std::unique_ptr<cpu::kernels::CpuIm2ColKernel> _im2col_kernel;
Michalis Spyrou1a569a32019-09-10 17:20:34 +0100293 NEGEMM _mm_gemm;
294 NEGEMMLowpMatrixMultiplyCore _mm_gemmlowp;
Manuel Bottini24b89202021-07-01 18:13:33 +0100295 std::unique_ptr<cpu::kernels::CpuCol2ImKernel> _col2im_kernel;
Michalis Spyrou1a569a32019-09-10 17:20:34 +0100296 NEReshapeLayer _reshape_layer;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000297
Manuel Bottini90028992021-06-30 18:29:18 +0100298 const ITensor *_input;
Georgios Pinitas1562be32018-03-08 19:09:19 +0000299 const ITensor *_original_weights;
Manuel Bottini24b89202021-07-01 18:13:33 +0100300 ITensor *_original_output;
Georgios Pinitas1562be32018-03-08 19:09:19 +0000301
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100302 Tensor _im2col_output;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000303 Tensor _weights_reshaped;
304 Tensor _gemm_output;
Georgios Pinitas2ee98012021-02-15 20:42:39 +0000305 Tensor _gemm_output_3d;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000306 Tensor _tmp_output;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000307
Michalis Spyroue2503892018-04-23 15:17:31 +0100308 DataLayout _data_layout;
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100309
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100310 bool _skip_im2col;
311 bool _skip_col2im;
312 bool _is_quantized;
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100313 bool _is_prepared;
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +0000314};
Georgios Pinitas041f36d2018-09-18 18:38:37 +0100315} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000316#endif /* ARM_COMPUTE_NECONVOLUTIONGEMMLAYER_H */