Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 1 | /* |
| 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_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 Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/CL/functions/CLDepthwiseConvolutionLayer.h" |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/CL/functions/CLDirectConvolutionLayer.h" |
| 32 | #include "arm_compute/runtime/IFunction.h" |
| 33 | |
| 34 | #include <cstdint> |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | class ICLTensor; |
| 39 | |
| 40 | /** Basic function to execute depthwise convolution. This function calls the following OpenCL kernels and function: |
| 41 | * |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 42 | * -# @ref CLDepthwiseConvolutionLayer |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 43 | * -# @ref CLDirectConvolutionLayer |
| 44 | * |
| 45 | */ |
| 46 | class CLDepthwiseSeparableConvolutionLayer : public IFunction |
| 47 | { |
| 48 | public: |
| 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 Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 56 | * @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 Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 58 | * @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 Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 60 | * @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 Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 62 | * @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 Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 67 | 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 Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 70 | |
| 71 | // Inherited methods overriden: |
| 72 | void run() override; |
| 73 | |
| 74 | private: |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 75 | CLDepthwiseConvolutionLayer _depthwise_conv; |
| 76 | CLDirectConvolutionLayer _pointwise_conv; |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 77 | }; |
| 78 | } |
| 79 | #endif /*__ARM_COMPUTE_CL_DEPTHWISE_SEPARABLE_CONVOLUTION_H__ */ |