blob: 2100828f0d10f2f9ef29c09c55a40fc2da1ff138 [file] [log] [blame]
Michalis Spyrou7362f0d2017-10-18 17:58:22 +01001/*
Georgios Pinitasf72f9362018-01-12 16:29:45 +00002 * Copyright (c) 2017-2018 ARM Limited.
Michalis Spyrou7362f0d2017-10-18 17:58:22 +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_NEDEPTHWISECONVOLUTION_H__
25#define __ARM_COMPUTE_NEDEPTHWISECONVOLUTION_H__
26
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000027#include "arm_compute/core/NEON/kernels/NEDepthwiseConvolutionLayer3x3Kernel.h"
Michalis Spyroub7b31532017-11-23 12:10:21 +000028#include "arm_compute/core/NEON/kernels/NEDepthwiseIm2ColKernel.h"
29#include "arm_compute/core/NEON/kernels/NEDepthwiseVectorToTensorKernel.h"
30#include "arm_compute/core/NEON/kernels/NEDepthwiseWeightsReshapeKernel.h"
Michalis Spyroub91e34c2017-12-20 15:50:55 +000031#include "arm_compute/core/NEON/kernels/NEDirectConvolutionLayerOutputStageKernel.h"
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010032#include "arm_compute/core/NEON/kernels/NEFillBorderKernel.h"
Michalis Spyroub7b31532017-11-23 12:10:21 +000033#include "arm_compute/core/NEON/kernels/NEGEMMMatrixVectorMultiplyKernel.h"
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010034#include "arm_compute/core/Types.h"
35#include "arm_compute/runtime/IFunction.h"
36#include "arm_compute/runtime/IMemoryManager.h"
37#include "arm_compute/runtime/MemoryGroup.h"
38#include "arm_compute/runtime/Tensor.h"
39
40namespace arm_compute
41{
42class ITensor;
43
44/** Basic function to execute a depthwise convolution for kernel size 3x3xC. This function calls the following NEON kernels:
45 *
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000046 * -# @ref NEDepthwiseConvolutionLayer3x3
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010047 * -# @ref NEFillBorderKernel (if pad_x or pad_y > 0)
48 *
49 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000050class NEDepthwiseConvolutionLayer3x3 : public IFunction
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010051{
52public:
53 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000054 NEDepthwiseConvolutionLayer3x3();
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010055 /** Initialize the function's source, destination, kernels and border_size.
56 *
Georgios Pinitasf72f9362018-01-12 16:29:45 +000057 * @param[in, out] input Source tensor. Data type supported: QASYMM8, F32. (Written to only for border filling).
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010058 * @param[in] weights Weights tensor. These are 3D tensors with shape [3, 3, IFM]. Data type supported: Same as @p input.
59 * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
60 * Data type supported: Same as @p input.
Giorgio Arena82afedf2017-11-15 13:36:15 +000061 * @param[out] output Destination tensor. Data type supported: same as @p input.
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010062 * @param[in] conv_info Padding and stride information to use for the convolution.
63 */
Giorgio Arena82afedf2017-11-15 13:36:15 +000064 void configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info);
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010065
66 // Inherited methods overriden:
67 void run() override;
68
69private:
Michalis Spyroub91e34c2017-12-20 15:50:55 +000070 NEDepthwiseConvolutionLayer3x3Kernel _kernel;
71 NEDirectConvolutionLayerOutputStageKernel _output_stage_kernel;
72 NEFillBorderKernel _border_handler;
Georgios Pinitasf72f9362018-01-12 16:29:45 +000073 Tensor _accumulator;
Michalis Spyroub91e34c2017-12-20 15:50:55 +000074 bool _has_bias;
Georgios Pinitasf72f9362018-01-12 16:29:45 +000075 bool _is_quantized;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010076};
Michalis Spyroub7b31532017-11-23 12:10:21 +000077
Giorgio Arena39725282017-12-12 15:04:43 +000078/** Basic function to execute a generic depthwise convolution. This function calls the following NEON kernels:
Michalis Spyroub7b31532017-11-23 12:10:21 +000079 *
80 * -# @ref NEDepthwiseIm2ColKernel
81 * -# @ref NEDepthwiseWeightsReshapeKernel
82 * -# @ref NEGEMMMatrixVectorMultiplyKernel
83 * -# @ref NEFillBorderKernel (if pad_x or pad_y > 0)
84 *
85 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000086class NEDepthwiseConvolutionLayer : public IFunction
Michalis Spyroub7b31532017-11-23 12:10:21 +000087{
88public:
89 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000090 NEDepthwiseConvolutionLayer();
Michalis Spyroub7b31532017-11-23 12:10:21 +000091 /** Initialize the function's source, destination, weights and convolution information.
92 *
93 * @param[in, out] input Source tensor. Data type supported: F32. (Written to only for border filling).
94 * @param[out] output Destination tensor. Data type supported: same as @p input.
95 * @param[in] weights Weights tensor. These are 3D tensors with shape [kernel_x, kernel_y, IFM]. Data type supported: Same as @p input.
96 * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
97 * Data type supported: Same as @p input.
98 * @param[in] conv_info Padding and stride information to use for the convolution.
99 */
100 void configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info);
101
102 // Inherited methods overriden:
103 void run() override;
104
105private:
106 NEDepthwiseIm2ColKernel _im2col_kernel;
107 NEDepthwiseWeightsReshapeKernel _weights_reshape_kernel;
108 NEGEMMMatrixVectorMultiplyKernel _v2mm_kernel;
109 NEDepthwiseVectorToTensorKernel _vector_to_tensor_kernel;
110 Tensor _input_reshaped;
111 Tensor _weights_reshaped;
112 Tensor _v2mm_output;
113};
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100114}
115#endif /* __ARM_COMPUTE_NEDEPTHWISECONVOLUTION_H__ */