blob: 7cf5f64115b0bffe453838f1db95173c541f25b5 [file] [log] [blame]
Giorgio Arena93a690e2017-08-01 16:09:33 +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 */
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 Arena9fe41442017-08-23 16:36:24 +010027#include "arm_compute/core/CL/kernels/CLDepthwiseConvolution3x3Kernel.h"
28#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"
Giorgio Arena93a690e2017-08-01 16:09:33 +010031#include "arm_compute/core/CL/kernels/CLFillBorderKernel.h"
Giorgio Arena9fe41442017-08-23 16:36:24 +010032#include "arm_compute/core/CL/kernels/CLGEMMMatrixVectorMultiplyKernel.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010033#include "arm_compute/core/Types.h"
34#include "arm_compute/runtime/CL/CLTensor.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010035#include "arm_compute/runtime/IFunction.h"
36
Giorgio Arena93a690e2017-08-01 16:09:33 +010037namespace arm_compute
38{
39class ICLTensor;
40
Giorgio Arena9fe41442017-08-23 16:36:24 +010041/** 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 +010042 *
Giorgio Arena9fe41442017-08-23 16:36:24 +010043 * -# @ref CLDepthwiseConvolution3x3Kernel
44 * -# @ref CLFillBorderKernel (if pad_x or pad_y > 0)
Giorgio Arena93a690e2017-08-01 16:09:33 +010045 *
46 */
Giorgio Arena9fe41442017-08-23 16:36:24 +010047class CLDepthwiseConvolution3x3 : public IFunction
Giorgio Arena93a690e2017-08-01 16:09:33 +010048{
49public:
50 /** Default constructor */
Giorgio Arena9fe41442017-08-23 16:36:24 +010051 CLDepthwiseConvolution3x3();
Giorgio Arena93a690e2017-08-01 16:09:33 +010052 /** Initialize the function's source, destination, conv and border_size.
53 *
Giorgio Arena9fe41442017-08-23 16:36:24 +010054 * @param[in, out] input Source tensor. Data type supported: F32. (Written to only for border filling).
55 * @param[out] output Destination tensor. Data type supported: same as @p input.
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 Arena9fe41442017-08-23 16:36:24 +010059 * @param[in] conv_info Padding and stride information to use for the convolution.
Giorgio Arena93a690e2017-08-01 16:09:33 +010060 */
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010061 void configure(ICLTensor *input, ICLTensor *output, const ICLTensor *weights, const ICLTensor *biases, const PadStrideInfo &conv_info);
Giorgio Arena93a690e2017-08-01 16:09:33 +010062
63 // Inherited methods overriden:
64 void run() override;
65
66private:
Giorgio Arena9fe41442017-08-23 16:36:24 +010067 CLDepthwiseConvolution3x3Kernel _kernel;
68 CLFillBorderKernel _border_handler;
69};
70
71/** Basic function to execute a generic depthwise convolution. This function calls the following OpenCL kernels:
72 *
73 * -# @ref CLDepthwiseIm2ColKernel
74 * -# @ref CLGEMMMatrixVectorMultiplyKernel
75 * -# @ref CLDepthwiseWeightsReshapeKernel
76 * -# @ref CLFillBorderKernel (if pad_x or pad_y > 0)
77 *
78 */
79class CLDepthwiseConvolution : public IFunction
80{
81public:
82 /** Default constructor */
83 CLDepthwiseConvolution();
84 /** Initialize the function's source, destination, weights and convolution information.
85 *
86 * @param[in, out] input Source tensor. Data type supported: F32. (Written to only for border filling).
87 * @param[out] output Destination tensor. Data type supported: same as @p input.
88 * @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 +010089 * @param[in] biases (Optional) Biases tensor. A 1D tensor with shape [IFM]. Must be nullptr if not needed.
90 * Data type supported: Same as @p input.
Giorgio Arena9fe41442017-08-23 16:36:24 +010091 * @param[in] conv_info Padding and stride information to use for the convolution.
92 */
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010093 void configure(ICLTensor *input, ICLTensor *output, const ICLTensor *weights, const ICLTensor *biases, const PadStrideInfo &conv_info);
Giorgio Arena9fe41442017-08-23 16:36:24 +010094
95 // Inherited methods overriden:
96 void run() override;
97
98private:
99 CLDepthwiseIm2ColKernel _im2col_kernel;
100 CLDepthwiseWeightsReshapeKernel _weights_reshape_kernel;
101 CLGEMMMatrixVectorMultiplyKernel _v2mm_kernel;
102 CLDepthwiseVectorToTensorKernel _vector_to_tensor_kernel;
103 CLFillBorderKernel _v2mm_input_fill_border;
104 CLFillBorderKernel _v2mm_weights_fill_border;
105 CLTensor _input_reshaped;
106 CLTensor _weights_reshaped;
107 CLTensor _v2mm_output;
Giorgio Arena93a690e2017-08-01 16:09:33 +0100108};
109}
Giorgio Arena9fe41442017-08-23 16:36:24 +0100110#endif /*__ARM_COMPUTE_CLDEPTHWISECONVOLUTION_H__ */