blob: 5b6ed55be207b787234b0316c8cb958c3a4c5de3 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Manuel Bottini87350f42020-09-15 13:03:34 +01002 * Copyright (c) 2017-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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_NEDIRECTCONVOLUTIONLAYER_H
25#define ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Types.h"
28#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010029#include "arm_compute/runtime/IMemoryManager.h"
30#include "arm_compute/runtime/MemoryGroup.h"
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000031#include "arm_compute/runtime/NEON/functions/NEActivationLayer.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032#include "arm_compute/runtime/Tensor.h"
33
Georgios Pinitas658039b2017-09-15 16:30:50 +010034#include <memory>
35
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036namespace arm_compute
37{
Michalis Spyrouebcebf12020-10-21 00:04:14 +010038class NEDirectConvolutionLayerOutputStageKernel;
39class NEDirectConvolutionLayerKernel;
40class NEFillBorderKernel;
41
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042/** Function to run the direct convolution.
43 *
44 * This function calls the following NEON kernels:
45 *
46 * -# @ref NEFillBorderKernel for the input
Michalis Spyroub91e34c2017-12-20 15:50:55 +000047 * -# @ref NEDirectConvolutionLayerOutputStageKernel
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048 * -# @ref NEDirectConvolutionLayerKernel
49 */
50class NEDirectConvolutionLayer : public IFunction
51{
52public:
53 /** Constructor */
Georgios Pinitas658039b2017-09-15 16:30:50 +010054 NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Michalis Spyrouebcebf12020-10-21 00:04:14 +010055 /** Prevent instances of this class from being copied (As this class contains pointers) */
56 NEDirectConvolutionLayer(const NEDirectConvolutionLayer &) = delete;
57 /** Prevent instances of this class from being copied (As this class contains pointers) */
58 NEDirectConvolutionLayer &operator=(const NEDirectConvolutionLayer &) = delete;
59 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
60 NEDirectConvolutionLayer(NEDirectConvolutionLayer &&) = delete;
61 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
62 NEDirectConvolutionLayer &operator=(NEDirectConvolutionLayer &&) = delete;
63 /** Default destructor */
64 ~NEDirectConvolutionLayer();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065 /** Set the input, weights, biases and output tensors.
Anthony Barbierf202e502017-11-23 18:02:04 +000066 *
67 * @note: DirectConvolution only works in the following configurations:
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010068 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
69 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
Anthony Barbierf202e502017-11-23 18:02:04 +000070 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
71 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010072 * @param[in, out] input Input tensor. Data types supported: F16/F32.
Anthony Barbierf202e502017-11-23 18:02:04 +000073 * @param[in] weights Set of kernels to convolve the input volume.
74 * Supported sizes: 1x1, 3x3 and 5x5.
75 * The 3rd dimension must be the same as the input's volume 3rd dimension.
76 * Data type supported: Same as @p input.
Georgios Pinitas0223a782017-12-12 11:44:44 +000077 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
Anthony Barbierf202e502017-11-23 18:02:04 +000078 * @param[out] output Output tensor.
79 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
80 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000081 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Anthony Barbierf202e502017-11-23 18:02:04 +000082 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000083 void configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michalis Spyrouafa5d812017-11-30 14:25:57 +000084 /** Static function to check if given info will lead to a valid configuration of @ref NEDirectConvolutionLayer
85 *
86 * @note: DirectConvolution only works in the following configurations:
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010087 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
88 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
Michalis Spyrouafa5d812017-11-30 14:25:57 +000089 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
90 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010091 * @param[in] input Input tensor. Data types supported: F16/F32.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000092 * @param[in] weights Set of kernels to convolve the input volume.
93 * Supported sizes: 1x1, 3x3 and 5x5.
94 * The 3rd dimension must be the same as the input's volume 3rd dimension.
95 * Data type supported: Same as @p input.
Georgios Pinitas0223a782017-12-12 11:44:44 +000096 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000097 * @param[in] output Output tensor.
98 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
99 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000100 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000101 *
102 * @return a status
103 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000104 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &conv_info,
105 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106
107 // Inherited methods overridden:
108 void run() override;
109
110private:
Michalis Spyrouebcebf12020-10-21 00:04:14 +0100111 MemoryGroup _memory_group;
112 std::unique_ptr<NEDirectConvolutionLayerOutputStageKernel> _output_stage_kernel;
113 std::unique_ptr<NEDirectConvolutionLayerKernel> _conv_kernel;
114 std::unique_ptr<NEFillBorderKernel> _input_border_handler;
115 NEActivationLayer _activationlayer_function;
116 Tensor _accumulator;
117 bool _has_bias;
118 bool _is_activationlayer_enabled;
119 unsigned int _dim_split;
120 bool _is_padding_required;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100121};
122}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000123#endif /* ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H */