blob: a43461048aa6c473cbc486786f48b4e0cead6d2c [file] [log] [blame]
Giorgio Arena93a690e2017-08-01 16:09:33 +01001/*
Georgios Pinitas72219332018-06-05 14:56:06 +01002 * 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 */
24#ifndef __ARM_COMPUTE_CL_DEPTHWISE_SEPARABLE_CONVOLUTION_H__
25#define __ARM_COMPUTE_CL_DEPTHWISE_SEPARABLE_CONVOLUTION_H__
26
27#include "arm_compute/core/Types.h"
28#include "arm_compute/runtime/CL/CLTensor.h"
29#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000030#include "arm_compute/runtime/CL/functions/CLDepthwiseConvolutionLayer.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010031#include "arm_compute/runtime/CL/functions/CLDirectConvolutionLayer.h"
32#include "arm_compute/runtime/IFunction.h"
33
34#include <cstdint>
35
36namespace arm_compute
37{
38class ICLTensor;
39
40/** Basic function to execute depthwise convolution. This function calls the following OpenCL kernels and function:
41 *
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000042 * -# @ref CLDepthwiseConvolutionLayer
Giorgio Arena93a690e2017-08-01 16:09:33 +010043 * -# @ref CLDirectConvolutionLayer
44 *
45 */
46class CLDepthwiseSeparableConvolutionLayer : public IFunction
47{
48public:
49 /** Default constructor */
50 CLDepthwiseSeparableConvolutionLayer();
51 /** Set the input and output tensors.
52 *
53 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
54 * while every optional dimension from 4 and above represent a batch of inputs. Data types supported: F32.
55 * @param[in] depthwise_weights Depthwise convolution weights tensor. These are 3D tensors with dimensions [kernel_x, kernel_y, IFM]. Data type supported: Same as @p input.
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010056 * @param[in] depthwise_biases (Optional) Biases tensor.Biases are 1D tensor with dimensions [IFM]. Must be nullptr if not needed.
57 * Data type supported: Same as @p weights.
Giorgio Arena93a690e2017-08-01 16:09:33 +010058 * @param[out] depthwise_out Depthwise destination tensor.
59 * @param[in] pointwise_weights Pointwise convolution weights tensor. These are 4D tensors with dimensions [1, 1, IFM, OFM]. Data type supported: Same as @p input.
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010060 * @param[in] pointwise_biases (Optional) Biases tensor. Biases are 1D tensor with dimensions [OFM]. Must be nullptr if not needed.
61 * Data type supported: Same as @p weights.
Giorgio Arena93a690e2017-08-01 16:09:33 +010062 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
63 * Data types supported: Same as @p input.
64 * @param[in] depthwise_conv_info Contains padding and stride information described in @ref PadStrideInfo for depthwise convolution.
65 * @param[in] pointwise_conv_info Contains padding and stride information described in @ref PadStrideInfo for pointwise convolution.
66 */
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010067 void configure(ICLTensor *input, const ICLTensor *depthwise_weights, const ICLTensor *depthwise_biases, ICLTensor *depthwise_out,
68 const ICLTensor *pointwise_weights, const ICLTensor *pointwise_biases, ICLTensor *output,
69 const PadStrideInfo &depthwise_conv_info, const PadStrideInfo &pointwise_conv_info);
Giorgio Arena93a690e2017-08-01 16:09:33 +010070
71 // Inherited methods overriden:
72 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +010073 void prepare() override;
Giorgio Arena93a690e2017-08-01 16:09:33 +010074
75private:
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000076 CLDepthwiseConvolutionLayer _depthwise_conv;
77 CLDirectConvolutionLayer _pointwise_conv;
Giorgio Arena93a690e2017-08-01 16:09:33 +010078};
79}
80#endif /*__ARM_COMPUTE_CL_DEPTHWISE_SEPARABLE_CONVOLUTION_H__ */