blob: 659594fe110d2d1f5c54c4515c6a27b62f4b3cc3 [file] [log] [blame]
Michalis Spyrou7362f0d2017-10-18 17:58:22 +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_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 Spyrou7362f0d2017-10-18 17:58:22 +010031#include "arm_compute/core/NEON/kernels/NEDirectConvolutionLayerBiasAccumulateKernel.h"
32#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 *
57 * @param[in, out] input Source tensor. Data type supported: 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:
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000070 NEDepthwiseConvolutionLayer3x3Kernel _kernel;
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010071 NEDirectConvolutionLayerBiasAccumulateKernel _bias_kernel;
72 NEFillBorderKernel _border_handler;
73 bool _has_bias;
74};
Michalis Spyroub7b31532017-11-23 12:10:21 +000075
Giorgio Arena39725282017-12-12 15:04:43 +000076/** Basic function to execute a generic depthwise convolution. This function calls the following NEON kernels:
Michalis Spyroub7b31532017-11-23 12:10:21 +000077 *
78 * -# @ref NEDepthwiseIm2ColKernel
79 * -# @ref NEDepthwiseWeightsReshapeKernel
80 * -# @ref NEGEMMMatrixVectorMultiplyKernel
81 * -# @ref NEFillBorderKernel (if pad_x or pad_y > 0)
82 *
83 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000084class NEDepthwiseConvolutionLayer : public IFunction
Michalis Spyroub7b31532017-11-23 12:10:21 +000085{
86public:
87 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000088 NEDepthwiseConvolutionLayer();
Michalis Spyroub7b31532017-11-23 12:10:21 +000089 /** Initialize the function's source, destination, weights and convolution information.
90 *
91 * @param[in, out] input Source tensor. Data type supported: F32. (Written to only for border filling).
92 * @param[out] output Destination tensor. Data type supported: same as @p input.
93 * @param[in] weights Weights tensor. These are 3D tensors with shape [kernel_x, kernel_y, IFM]. Data type supported: Same as @p input.
94 * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
95 * Data type supported: Same as @p input.
96 * @param[in] conv_info Padding and stride information to use for the convolution.
97 */
98 void configure(ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info);
99
100 // Inherited methods overriden:
101 void run() override;
102
103private:
104 NEDepthwiseIm2ColKernel _im2col_kernel;
105 NEDepthwiseWeightsReshapeKernel _weights_reshape_kernel;
106 NEGEMMMatrixVectorMultiplyKernel _v2mm_kernel;
107 NEDepthwiseVectorToTensorKernel _vector_to_tensor_kernel;
108 Tensor _input_reshaped;
109 Tensor _weights_reshaped;
110 Tensor _v2mm_output;
111};
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100112}
113#endif /* __ARM_COMPUTE_NEDEPTHWISECONVOLUTION_H__ */