blob: 682effe84baaea1a862ca5c522d9069a2a4f2e7c [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"
Georgios Pinitas4074c992018-01-30 18:13:46 +000035#include "arm_compute/runtime/CPP/functions/CPPPermute.h"
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010036#include "arm_compute/runtime/IFunction.h"
37#include "arm_compute/runtime/IMemoryManager.h"
38#include "arm_compute/runtime/MemoryGroup.h"
39#include "arm_compute/runtime/Tensor.h"
40
41namespace arm_compute
42{
43class ITensor;
44
45/** Basic function to execute a depthwise convolution for kernel size 3x3xC. This function calls the following NEON kernels:
46 *
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000047 * -# @ref NEDepthwiseConvolutionLayer3x3
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010048 * -# @ref NEFillBorderKernel (if pad_x or pad_y > 0)
49 *
50 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000051class NEDepthwiseConvolutionLayer3x3 : public IFunction
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010052{
53public:
54 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000055 NEDepthwiseConvolutionLayer3x3();
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010056 /** Initialize the function's source, destination, kernels and border_size.
57 *
Georgios Pinitasd05dce42018-01-22 16:29:17 +000058 * @param[in, out] input Source tensor. Data type supported: QASYMM8/F32. (Written to only for border filling).
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010059 * @param[in] weights Weights tensor. These are 3D tensors with shape [3, 3, IFM]. Data type supported: Same as @p input.
60 * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
61 * Data type supported: Same as @p input.
Giorgio Arena82afedf2017-11-15 13:36:15 +000062 * @param[out] output Destination tensor. Data type supported: same as @p input.
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010063 * @param[in] conv_info Padding and stride information to use for the convolution.
64 */
Giorgio Arena82afedf2017-11-15 13:36:15 +000065 void configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info);
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010066
67 // Inherited methods overriden:
68 void run() override;
69
70private:
Georgios Pinitas4074c992018-01-30 18:13:46 +000071 NEDepthwiseConvolutionLayer3x3Kernel _dwc_kernel;
Michalis Spyroub91e34c2017-12-20 15:50:55 +000072 NEDirectConvolutionLayerOutputStageKernel _output_stage_kernel;
73 NEFillBorderKernel _border_handler;
Georgios Pinitas4074c992018-01-30 18:13:46 +000074 CPPPermute _permute_input;
75 CPPPermute _permute_weights;
76 CPPPermute _permute_output;
Georgios Pinitasf72f9362018-01-12 16:29:45 +000077 Tensor _accumulator;
Georgios Pinitas4074c992018-01-30 18:13:46 +000078 Tensor _input_nhwc;
79 Tensor _weights_hwio;
80 Tensor _output_nhwc;
Michalis Spyroub91e34c2017-12-20 15:50:55 +000081 bool _has_bias;
Georgios Pinitasf72f9362018-01-12 16:29:45 +000082 bool _is_quantized;
Georgios Pinitas4074c992018-01-30 18:13:46 +000083 bool _is_optimized;
84 bool _are_weights_reshaped;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010085};
Michalis Spyroub7b31532017-11-23 12:10:21 +000086
Giorgio Arena39725282017-12-12 15:04:43 +000087/** Basic function to execute a generic depthwise convolution. This function calls the following NEON kernels:
Michalis Spyroub7b31532017-11-23 12:10:21 +000088 *
89 * -# @ref NEDepthwiseIm2ColKernel
90 * -# @ref NEDepthwiseWeightsReshapeKernel
91 * -# @ref NEGEMMMatrixVectorMultiplyKernel
92 * -# @ref NEFillBorderKernel (if pad_x or pad_y > 0)
93 *
94 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000095class NEDepthwiseConvolutionLayer : public IFunction
Michalis Spyroub7b31532017-11-23 12:10:21 +000096{
97public:
98 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000099 NEDepthwiseConvolutionLayer();
Michalis Spyroub7b31532017-11-23 12:10:21 +0000100 /** Initialize the function's source, destination, weights and convolution information.
101 *
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000102 * @param[in, out] input Source tensor. Data type supported: QASYMM8/F32. (Written to only for border filling).
Michalis Spyroub7b31532017-11-23 12:10:21 +0000103 * @param[out] output Destination tensor. Data type supported: same as @p input.
104 * @param[in] weights Weights tensor. These are 3D tensors with shape [kernel_x, kernel_y, IFM]. Data type supported: Same as @p input.
105 * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
106 * Data type supported: Same as @p input.
107 * @param[in] conv_info Padding and stride information to use for the convolution.
108 */
109 void configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info);
110
111 // Inherited methods overriden:
112 void run() override;
113
114private:
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000115 NEDepthwiseIm2ColKernel _im2col_kernel;
116 NEDepthwiseWeightsReshapeKernel _weights_reshape_kernel;
117 NEGEMMMatrixVectorMultiplyKernel _v2mm_kernel;
118 NEDepthwiseVectorToTensorKernel _vector_to_tensor_kernel;
119 NEDirectConvolutionLayerOutputStageKernel _output_stage_kernel;
120 NEFillBorderKernel _v2mm_input_fill_border;
121 NEFillBorderKernel _v2mm_weights_fill_border;
122 Tensor _input_reshaped;
123 Tensor _weights_reshaped;
124 Tensor _v2mm_output;
125 Tensor _output_reshaped;
126 bool _is_quantized;
Michalis Spyroub7b31532017-11-23 12:10:21 +0000127};
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100128}
129#endif /* __ARM_COMPUTE_NEDEPTHWISECONVOLUTION_H__ */