blob: 7df765988fbfb37746dd28b0a314de23753a08e6 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Gian Marco20d78482018-01-11 15:10:58 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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_CLCONVOLUTIONLAYER_H__
25#define __ARM_COMPUTE_CLCONVOLUTIONLAYER_H__
26
Isabella Gottardif07d28d2018-02-06 14:52:43 +000027#include "arm_compute/runtime/CL/functions/CLDirectConvolutionLayer.h"
28#include "arm_compute/runtime/CL/functions/CLGEMMConvolutionLayer.h"
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000029#include "arm_compute/runtime/IFunction.h"
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010030#include "arm_compute/runtime/IMemoryManager.h"
31
32#include <memory>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
34namespace arm_compute
35{
Gian Marco20d78482018-01-11 15:10:58 +000036/** Basic function to compute the convolution layer. This function calls the following OpenCL kernels/functions:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037 *
Isabella Gottardif07d28d2018-02-06 14:52:43 +000038 * -# @ref CLGEMMConvolutionLayer
39 * -# @ref CLDirectConvolutionLayer
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040 */
41class CLConvolutionLayer : public IFunction
42{
43public:
44 /** Default constructor */
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010045 CLConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046 /** Set the input and output tensors.
47 *
48 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
49 * while every optional dimension from 4 and above represent a batch of inputs.
Chunosov5124be52017-11-22 20:42:13 +070050 * Data types supported: QS8/QASYMM8/QS16/F16/F32.
51 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
52 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
53 * Data type supported: Should match @p input data type, except for input of QASYMM8 type where biases should be of S32 type.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
55 * Data types supported: Same as @p input.
56 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
Isabella Gottardif07d28d2018-02-06 14:52:43 +000057 * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. Data type supported: Same as @p input.
Alex Gilday7da29b62018-03-23 14:16:00 +000058 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000059 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 */
Alex Gilday7da29b62018-03-23 14:16:00 +000061 void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info = WeightsInfo(),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000062 const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo());
Isabella Gottardif07d28d2018-02-06 14:52:43 +000063 /** Static function to check if given info will lead to a valid configuration of @ref CLConvolutionLayer
64 *
65 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
66 * while every optional dimension from 4 and above represent a batch of inputs.
67 * Data types supported: QS8/QASYMM8/QS16/F16/F32.
68 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
69 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported:Same as @p input.
70 * @param[in] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
71 * Data types supported: Same as @p input.
72 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
73 * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. Data type supported: Same as @p input.
Alex Gilday7da29b62018-03-23 14:16:00 +000074 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000075 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Isabella Gottardif07d28d2018-02-06 14:52:43 +000076 *
77 * @return a status
78 */
79 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000080 const WeightsInfo &weights_info = WeightsInfo(), const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo());
Isabella Gottardif07d28d2018-02-06 14:52:43 +000081 /** Static function to check if given info will return the convolution called by @ref CLConvolutionLayer
82 *
83 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
84 * while every optional dimension from 4 and above represent a batch of inputs.
85 * Data types supported: QS8/QASYMM8/QS16/F16/F32.
86 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
87 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported:Same as @p input.
88 * @param[in] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
89 * Data types supported: Same as @p input.
90 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
91 * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. Data type supported: Same as @p input.
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000092 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Isabella Gottardif07d28d2018-02-06 14:52:43 +000093 * @param[in] gpu_target Specifies the @p GPUTarget.
Alex Gilday7da29b62018-03-23 14:16:00 +000094 * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Isabella Gottardif07d28d2018-02-06 14:52:43 +000095 *
96 * @return a status
97 */
98 static ConvolutionMethod get_convolution_method(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000099 const WeightsInfo &weights_info, const ActivationLayerInfo &act_info, const GPUTarget gpu_target, const Size2D &dilation = Size2D(1U, 1U));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100 // Inherited methods overridden:
101 void run() override;
102
103private:
Isabella Gottardif07d28d2018-02-06 14:52:43 +0000104 std::shared_ptr<IMemoryManager> _memory_manager;
105 std::unique_ptr<IFunction> _function; /**< Function to run */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106};
107}
108#endif /* __ARM_COMPUTE_CLCONVOLUTIONLAYER_H__ */