blob: 09a54968bbe181c791eab297a9348fee4a8c0df8 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 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_NEDIRECTCONVOLUTIONLAYER_H__
25#define __ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H__
26
27#include "arm_compute/core/NEON/kernels/NEDirectConvolutionLayerBiasAccumulateKernel.h"
28#include "arm_compute/core/NEON/kernels/NEDirectConvolutionLayerKernel.h"
29#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"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034#include "arm_compute/runtime/Tensor.h"
35
Georgios Pinitas658039b2017-09-15 16:30:50 +010036#include <memory>
37
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038namespace arm_compute
39{
40/** Function to run the direct convolution.
41 *
42 * This function calls the following NEON kernels:
43 *
44 * -# @ref NEFillBorderKernel for the input
45 * -# @ref NEDirectConvolutionLayerBiasAccumulateKernel
46 * -# @ref NEDirectConvolutionLayerKernel
47 */
48class NEDirectConvolutionLayer : public IFunction
49{
50public:
51 /** Constructor */
Georgios Pinitas658039b2017-09-15 16:30:50 +010052 NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 /** Set the input, weights, biases and output tensors.
Anthony Barbierf202e502017-11-23 18:02:04 +000054 *
55 * @note: DirectConvolution only works in the following configurations:
56 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = QS8/QS16/F16/F32
57 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = QS8/F16/F32
58 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
59 *
60 * @param[in, out] input Input tensor. Data types supported: QS8/QS16/F16/F32.
61 * @param[in] weights Set of kernels to convolve the input volume.
62 * Supported sizes: 1x1, 3x3 and 5x5.
63 * The 3rd dimension must be the same as the input's volume 3rd dimension.
64 * Data type supported: Same as @p input.
Georgios Pinitas0223a782017-12-12 11:44:44 +000065 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
Anthony Barbierf202e502017-11-23 18:02:04 +000066 * @param[out] output Output tensor.
67 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
68 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
69 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 void configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &conv_info);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000071 /** Static function to check if given info will lead to a valid configuration of @ref NEDirectConvolutionLayer
72 *
73 * @note: DirectConvolution only works in the following configurations:
74 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = QS8/QS16/F16/F32
75 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = QS8/F16/F32
76 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
77 *
78 * @param[in] input Input tensor. Data types supported: QS8/QS16/F16/F32.
79 * @param[in] weights Set of kernels to convolve the input volume.
80 * Supported sizes: 1x1, 3x3 and 5x5.
81 * The 3rd dimension must be the same as the input's volume 3rd dimension.
82 * Data type supported: Same as @p input.
Georgios Pinitas0223a782017-12-12 11:44:44 +000083 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000084 * @param[in] output Output tensor.
85 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
86 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
87 *
88 * @return a status
89 */
90 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &conv_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010091
92 // Inherited methods overridden:
93 void run() override;
94
95private:
Georgios Pinitas658039b2017-09-15 16:30:50 +010096 MemoryGroup _memory_group;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010097 NEDirectConvolutionLayerBiasAccumulateKernel _accumulate_bias_kernel;
98 NEDirectConvolutionLayerKernel _conv_kernel;
99 NEFillBorderKernel _input_border_handler;
100 Tensor _accumulator;
Georgios Pinitas0223a782017-12-12 11:44:44 +0000101 bool _has_bias;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102};
103}
104#endif /* __ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H__ */