blob: eb12fe4ccae8ba4731099ac18642d83ac1ec8709 [file] [log] [blame]
Giorgio Arena93a690e2017-08-01 16:09:33 +01001/*
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +00002 * Copyright (c) 2017-2018 ARM Limited.
Giorgio Arena93a690e2017-08-01 16:09:33 +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 */
Giorgio Arena9fe41442017-08-23 16:36:24 +010024#ifndef __ARM_COMPUTE_CLDEPTHWISECONVOLUTION_H__
25#define __ARM_COMPUTE_CLDEPTHWISECONVOLUTION_H__
Giorgio Arena93a690e2017-08-01 16:09:33 +010026
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000027#include "arm_compute/core/CL/kernels/CLDepthwiseConvolutionLayer3x3Kernel.h"
Giorgio Arena9fe41442017-08-23 16:36:24 +010028#include "arm_compute/core/CL/kernels/CLDepthwiseIm2ColKernel.h"
29#include "arm_compute/core/CL/kernels/CLDepthwiseVectorToTensorKernel.h"
30#include "arm_compute/core/CL/kernels/CLDepthwiseWeightsReshapeKernel.h"
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +000031#include "arm_compute/core/CL/kernels/CLDirectConvolutionLayerOutputStageKernel.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010032#include "arm_compute/core/CL/kernels/CLFillBorderKernel.h"
Giorgio Arena9fe41442017-08-23 16:36:24 +010033#include "arm_compute/core/CL/kernels/CLGEMMMatrixVectorMultiplyKernel.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010034#include "arm_compute/core/Types.h"
35#include "arm_compute/runtime/CL/CLTensor.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010036#include "arm_compute/runtime/IFunction.h"
37
Giorgio Arena93a690e2017-08-01 16:09:33 +010038namespace arm_compute
39{
40class ICLTensor;
41
Giorgio Arena9fe41442017-08-23 16:36:24 +010042/** Basic function to execute a depthwise convolution for kernel size 3x3xC. This function calls the following OpenCL kernels:
Giorgio Arena93a690e2017-08-01 16:09:33 +010043 *
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000044 * -# @ref CLDepthwiseConvolutionLayer3x3Kernel
Giorgio Arena9fe41442017-08-23 16:36:24 +010045 * -# @ref CLFillBorderKernel (if pad_x or pad_y > 0)
Giorgio Arena93a690e2017-08-01 16:09:33 +010046 *
47 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000048class CLDepthwiseConvolutionLayer3x3 : public IFunction
Giorgio Arena93a690e2017-08-01 16:09:33 +010049{
50public:
51 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000052 CLDepthwiseConvolutionLayer3x3();
Giorgio Arena93a690e2017-08-01 16:09:33 +010053 /** Initialize the function's source, destination, conv and border_size.
54 *
Michele Di Giorgio933fe862018-02-19 15:42:12 +000055 * @param[in, out] input Source tensor. Data type supported: QASYMM8/F16/F32. (Written to only for border filling).
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010056 * @param[in] weights Weights tensor. A 3D tensor with shape [3, 3, IFM]. Data type supported: Same as @p input.
57 * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
58 * Data type supported: Same as @p input.
Giorgio Arena82afedf2017-11-15 13:36:15 +000059 * @param[out] output Destination tensor. Data type supported: same as @p input.
Giorgio Arena9fe41442017-08-23 16:36:24 +010060 * @param[in] conv_info Padding and stride information to use for the convolution.
Giorgio Arena99ac60b2018-02-16 15:17:23 +000061 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU for 3x3 QASYMM8 supported.
Giorgio Arena93a690e2017-08-01 16:09:33 +010062 */
Giorgio Arena99ac60b2018-02-16 15:17:23 +000063 void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, ActivationLayerInfo act_info = ActivationLayerInfo());
Giorgio Arena93a690e2017-08-01 16:09:33 +010064
65 // Inherited methods overriden:
66 void run() override;
67
68private:
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000069 CLDepthwiseConvolutionLayer3x3Kernel _kernel;
70 CLFillBorderKernel _border_handler;
Giorgio Arena9fe41442017-08-23 16:36:24 +010071};
72
73/** Basic function to execute a generic depthwise convolution. This function calls the following OpenCL kernels:
74 *
75 * -# @ref CLDepthwiseIm2ColKernel
76 * -# @ref CLGEMMMatrixVectorMultiplyKernel
77 * -# @ref CLDepthwiseWeightsReshapeKernel
78 * -# @ref CLFillBorderKernel (if pad_x or pad_y > 0)
79 *
80 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000081class CLDepthwiseConvolutionLayer : public IFunction
Giorgio Arena9fe41442017-08-23 16:36:24 +010082{
83public:
84 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000085 CLDepthwiseConvolutionLayer();
Giorgio Arena9fe41442017-08-23 16:36:24 +010086 /** Initialize the function's source, destination, weights and convolution information.
87 *
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +000088 * @param[in, out] input Source tensor. Data type supported: QASYMM8/F32. (Written to only for border filling).
Giorgio Arena9fe41442017-08-23 16:36:24 +010089 * @param[in] weights Weights tensor. These are 3D tensors with shape [kernel_x, kernel_y, IFM]. Data type supported: Same as @p input.
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010090 * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +000091 * Data type supported: Same as @p input, S32 when input is QASYMM8.
Giorgio Arena82afedf2017-11-15 13:36:15 +000092 * @param[out] output Destination tensor. Data type supported: same as @p input.
Giorgio Arena9fe41442017-08-23 16:36:24 +010093 * @param[in] conv_info Padding and stride information to use for the convolution.
94 */
Giorgio Arena82afedf2017-11-15 13:36:15 +000095 void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info);
Giorgio Arena9fe41442017-08-23 16:36:24 +010096
97 // Inherited methods overriden:
98 void run() override;
99
100private:
Georgios Pinitasde5a1cc2018-02-02 12:52:07 +0000101 CLDepthwiseIm2ColKernel _im2col_kernel;
102 CLDepthwiseWeightsReshapeKernel _weights_reshape_kernel;
103 CLGEMMMatrixVectorMultiplyKernel _v2mm_kernel;
104 CLDepthwiseVectorToTensorKernel _vector_to_tensor_kernel;
105 CLDirectConvolutionLayerOutputStageKernel _output_stage_kernel;
106 CLFillBorderKernel _v2mm_input_fill_border;
107 CLFillBorderKernel _v2mm_weights_fill_border;
108 CLTensor _input_reshaped;
109 CLTensor _weights_reshaped;
110 CLTensor _v2mm_output;
111 CLTensor _output_reshaped;
112 bool _is_quantized;
Giorgio Arena93a690e2017-08-01 16:09:33 +0100113};
114}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100115#endif /*__ARM_COMPUTE_CLDEPTHWISECONVOLUTION_H__ */