Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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_CLCONVOLUTIONLAYER_H__ |
| 25 | #define __ARM_COMPUTE_CLCONVOLUTIONLAYER_H__ |
| 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | |
Isabella Gottardi | f07d28d | 2018-02-06 14:52:43 +0000 | [diff] [blame] | 29 | #include "arm_compute/runtime/CL/functions/CLDirectConvolutionLayer.h" |
| 30 | #include "arm_compute/runtime/CL/functions/CLGEMMConvolutionLayer.h" |
Georgios Pinitas | baf174e | 2017-09-08 19:47:30 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/IMemoryManager.h" |
| 32 | |
| 33 | #include <memory> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
Gian Marco | 20d7848 | 2018-01-11 15:10:58 +0000 | [diff] [blame] | 37 | /** Basic function to compute the convolution layer. This function calls the following OpenCL kernels/functions: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | * |
Isabella Gottardi | f07d28d | 2018-02-06 14:52:43 +0000 | [diff] [blame] | 39 | * -# @ref CLGEMMConvolutionLayer |
| 40 | * -# @ref CLDirectConvolutionLayer |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | */ |
| 42 | class CLConvolutionLayer : public IFunction |
| 43 | { |
| 44 | public: |
| 45 | /** Default constructor */ |
Georgios Pinitas | baf174e | 2017-09-08 19:47:30 +0100 | [diff] [blame] | 46 | CLConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | /** Set the input and output tensors. |
| 48 | * |
| 49 | * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM], |
| 50 | * while every optional dimension from 4 and above represent a batch of inputs. |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 51 | * Data types supported: QS8/QASYMM8/QS16/F16/F32. |
| 52 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input. |
| 53 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. |
| 54 | * Data type supported: Should match @p input data type, except for input of QASYMM8 type where biases should be of S32 type. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 55 | * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. |
| 56 | * Data types supported: Same as @p input. |
| 57 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
Isabella Gottardi | f07d28d | 2018-02-06 14:52:43 +0000 | [diff] [blame] | 58 | * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. Data type supported: Same as @p input. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | */ |
Isabella Gottardi | f07d28d | 2018-02-06 14:52:43 +0000 | [diff] [blame] | 60 | void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info = WeightsInfo()); |
| 61 | /** Static function to check if given info will lead to a valid configuration of @ref CLConvolutionLayer |
| 62 | * |
| 63 | * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM], |
| 64 | * while every optional dimension from 4 and above represent a batch of inputs. |
| 65 | * Data types supported: QS8/QASYMM8/QS16/F16/F32. |
| 66 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input. |
| 67 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported:Same as @p input. |
| 68 | * @param[in] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. |
| 69 | * Data types supported: Same as @p input. |
| 70 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 71 | * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. Data type supported: Same as @p input. |
| 72 | * |
| 73 | * @return a status |
| 74 | */ |
| 75 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 76 | const WeightsInfo &weights_info = WeightsInfo()); |
| 77 | /** Static function to check if given info will return the convolution called by @ref CLConvolutionLayer |
| 78 | * |
| 79 | * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM], |
| 80 | * while every optional dimension from 4 and above represent a batch of inputs. |
| 81 | * Data types supported: QS8/QASYMM8/QS16/F16/F32. |
| 82 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input. |
| 83 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported:Same as @p input. |
| 84 | * @param[in] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. |
| 85 | * Data types supported: Same as @p input. |
| 86 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 87 | * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. Data type supported: Same as @p input. |
| 88 | * @param[in] gpu_target Specifies the @p GPUTarget. |
| 89 | * |
| 90 | * @return a status |
| 91 | */ |
| 92 | static ConvolutionMethod get_convolution_method(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 93 | const WeightsInfo &weights_info, const GPUTarget gpu_target); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 94 | |
| 95 | // Inherited methods overridden: |
| 96 | void run() override; |
| 97 | |
| 98 | private: |
Isabella Gottardi | f07d28d | 2018-02-06 14:52:43 +0000 | [diff] [blame] | 99 | std::shared_ptr<IMemoryManager> _memory_manager; |
| 100 | std::unique_ptr<IFunction> _function; /**< Function to run */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | }; |
| 102 | } |
| 103 | #endif /* __ARM_COMPUTE_CLCONVOLUTIONLAYER_H__ */ |