blob: a4a55d10f8735aa513c9c9c6f52bb067982f096a [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Isabella Gottardi3f217ec2018-02-12 14:59:19 +00002 * Copyright (c) 2017-2018 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 */
24#ifndef __ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H__
25#define __ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H__
26
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/NEON/kernels/NEDirectConvolutionLayerKernel.h"
Michalis Spyroub91e34c2017-12-20 15:50:55 +000028#include "arm_compute/core/NEON/kernels/NEDirectConvolutionLayerOutputStageKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/NEON/kernels/NEFillBorderKernel.h"
30#include "arm_compute/core/Types.h"
31#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010032#include "arm_compute/runtime/IMemoryManager.h"
33#include "arm_compute/runtime/MemoryGroup.h"
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000034#include "arm_compute/runtime/NEON/functions/NEActivationLayer.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035#include "arm_compute/runtime/Tensor.h"
36
Georgios Pinitas658039b2017-09-15 16:30:50 +010037#include <memory>
38
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039namespace arm_compute
40{
41/** Function to run the direct convolution.
42 *
43 * This function calls the following NEON kernels:
44 *
45 * -# @ref NEFillBorderKernel for the input
Michalis Spyroub91e34c2017-12-20 15:50:55 +000046 * -# @ref NEDirectConvolutionLayerOutputStageKernel
Anthony Barbier6ff3b192017-09-04 18:44:23 +010047 * -# @ref NEDirectConvolutionLayerKernel
48 */
49class NEDirectConvolutionLayer : public IFunction
50{
51public:
52 /** Constructor */
Georgios Pinitas658039b2017-09-15 16:30:50 +010053 NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054 /** Set the input, weights, biases and output tensors.
Anthony Barbierf202e502017-11-23 18:02:04 +000055 *
56 * @note: DirectConvolution only works in the following configurations:
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010057 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
58 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
Anthony Barbierf202e502017-11-23 18:02:04 +000059 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
60 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010061 * @param[in, out] input Input tensor. Data types supported: F16/F32.
Anthony Barbierf202e502017-11-23 18:02:04 +000062 * @param[in] weights Set of kernels to convolve the input volume.
63 * Supported sizes: 1x1, 3x3 and 5x5.
64 * The 3rd dimension must be the same as the input's volume 3rd dimension.
65 * Data type supported: Same as @p input.
Georgios Pinitas0223a782017-12-12 11:44:44 +000066 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
Anthony Barbierf202e502017-11-23 18:02:04 +000067 * @param[out] output Output tensor.
68 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
69 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000070 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Anthony Barbierf202e502017-11-23 18:02:04 +000071 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000072 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 +000073 /** Static function to check if given info will lead to a valid configuration of @ref NEDirectConvolutionLayer
74 *
75 * @note: DirectConvolution only works in the following configurations:
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010076 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
77 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
Michalis Spyrouafa5d812017-11-30 14:25:57 +000078 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
79 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010080 * @param[in] input Input tensor. Data types supported: F16/F32.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000081 * @param[in] weights Set of kernels to convolve the input volume.
82 * Supported sizes: 1x1, 3x3 and 5x5.
83 * The 3rd dimension must be the same as the input's volume 3rd dimension.
84 * Data type supported: Same as @p input.
Georgios Pinitas0223a782017-12-12 11:44:44 +000085 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000086 * @param[in] output Output tensor.
87 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
88 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000089 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000090 *
91 * @return a status
92 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000093 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &conv_info,
94 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095
96 // Inherited methods overridden:
97 void run() override;
98
99private:
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000100 MemoryGroup _memory_group;
101 NEDirectConvolutionLayerOutputStageKernel _output_stage_kernel;
102 NEDirectConvolutionLayerKernel _conv_kernel;
103 NEFillBorderKernel _input_border_handler;
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000104 NEActivationLayer _activationlayer_function;
Michalis Spyroub91e34c2017-12-20 15:50:55 +0000105 Tensor _accumulator;
106 bool _has_bias;
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000107 bool _is_activationlayer_enabled;
Giorgio Arenac0f54432018-03-16 14:02:34 +0000108 unsigned int _dim_split;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100109};
110}
111#endif /* __ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H__ */