blob: 70352fdfaa33f99ee0e81af9af11724e3034b051 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Sheri Zhangac6499a2021-02-10 15:32:38 +00002 * Copyright (c) 2017-2021 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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H
25#define ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Types.h"
28#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010029#include "arm_compute/runtime/IMemoryManager.h"
30#include "arm_compute/runtime/MemoryGroup.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
Georgios Pinitas658039b2017-09-15 16:30:50 +010032#include <memory>
33
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034namespace arm_compute
35{
Manuel Bottini327225d2021-04-13 13:09:30 +010036class ITensor;
37class ITensorInfo;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038/** Function to run the direct convolution.
39 *
Manuel Bottini327225d2021-04-13 13:09:30 +010040 * This function calls the following:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041 *
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010042 * -# @ref cpu::CpuDirectConv2d
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 */
44class NEDirectConvolutionLayer : public IFunction
45{
46public:
47 /** Constructor */
Georgios Pinitas658039b2017-09-15 16:30:50 +010048 NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Michalis Spyrouebcebf12020-10-21 00:04:14 +010049 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 NEDirectConvolutionLayer(const NEDirectConvolutionLayer &) = delete;
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 NEDirectConvolutionLayer &operator=(const NEDirectConvolutionLayer &) = delete;
53 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
54 NEDirectConvolutionLayer(NEDirectConvolutionLayer &&) = delete;
55 /** Prevent instances of this class from being moved (As this class contains non movable objects) */
56 NEDirectConvolutionLayer &operator=(NEDirectConvolutionLayer &&) = delete;
57 /** Default destructor */
58 ~NEDirectConvolutionLayer();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 /** Set the input, weights, biases and output tensors.
Anthony Barbierf202e502017-11-23 18:02:04 +000060 *
Sheri Zhanga47dcc22021-04-22 14:41:12 +010061 * Valid data layouts:
62 * - NHWC
63 * - NCHW
64 *
65 * Valid data type configurations:
66 * |src0 |src1 |src2 |dst |
67 * |:------|:------|:------|:------|
68 * |F16 |F16 |F16 |F16 |
69 * |F32 |F32 |F32 |F32 |
70 *
Anthony Barbierf202e502017-11-23 18:02:04 +000071 * @note: DirectConvolution only works in the following configurations:
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010072 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
73 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
Anthony Barbierf202e502017-11-23 18:02:04 +000074 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
75 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010076 * @param[in, out] input Input tensor. Data types supported: F16/F32.
Anthony Barbierf202e502017-11-23 18:02:04 +000077 * @param[in] weights Set of kernels to convolve the input volume.
78 * Supported sizes: 1x1, 3x3 and 5x5.
79 * The 3rd dimension must be the same as the input's volume 3rd dimension.
80 * Data type supported: Same as @p input.
Georgios Pinitas0223a782017-12-12 11:44:44 +000081 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
Anthony Barbierf202e502017-11-23 18:02:04 +000082 * @param[out] output Output tensor.
83 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
84 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000085 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Anthony Barbierf202e502017-11-23 18:02:04 +000086 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000087 void configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Michalis Spyrouafa5d812017-11-30 14:25:57 +000088 /** Static function to check if given info will lead to a valid configuration of @ref NEDirectConvolutionLayer
89 *
90 * @note: DirectConvolution only works in the following configurations:
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010091 * 1x1 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
92 * 3x3 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F16/F32
Michalis Spyrouafa5d812017-11-30 14:25:57 +000093 * 5x5 convolution with stride_x = 1/2/3, stride_y = 1/2/3 data type = F32
94 *
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010095 * @param[in] input Input tensor. Data types supported: F16/F32.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000096 * @param[in] weights Set of kernels to convolve the input volume.
97 * Supported sizes: 1x1, 3x3 and 5x5.
98 * The 3rd dimension must be the same as the input's volume 3rd dimension.
99 * Data type supported: Same as @p input.
Georgios Pinitas0223a782017-12-12 11:44:44 +0000100 * @param[in] bias Set of biases. Can be nullptr. Data type supported: Same as @p input.
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000101 * @param[in] output Output tensor.
102 * The 3rd dimensions must be equal to the 4th dimension of the @p kernels tensor. Data types supported: Same as @p input.
103 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000104 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Michalis Spyrouafa5d812017-11-30 14:25:57 +0000105 *
106 * @return a status
107 */
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000108 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &conv_info,
109 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100110
111 // Inherited methods overridden:
112 void run() override;
113
114private:
Manuel Bottini327225d2021-04-13 13:09:30 +0100115 struct Impl;
116 std::shared_ptr<IMemoryManager> _memory_manager;
117 std::unique_ptr<Impl> _impl;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100118};
Manuel Bottini327225d2021-04-13 13:09:30 +0100119} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000120#endif /* ARM_COMPUTE_NEDIRECTCONVOLUTIONLAYER_H */