blob: fcd097bdaa326fcf6b3e2cf107d7272672fec782 [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
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_GRAPH_CONVOLUTION_LAYER_H__
25#define __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__
26
27#include "arm_compute/graph/INode.h"
Georgios Pinitas6f669f02017-09-26 12:32:57 +010028#include "arm_compute/graph/SubTensor.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010029#include "arm_compute/graph/Tensor.h"
30#include "arm_compute/graph/Types.h"
Georgios Pinitas6f669f02017-09-26 12:32:57 +010031#include "arm_compute/runtime/IFunction.h"
32
33#include <memory>
Anthony Barbier2a07e182017-08-04 18:20:27 +010034
35namespace arm_compute
36{
37namespace graph
38{
39/** Convolution layer node */
Georgios Pinitas6f669f02017-09-26 12:32:57 +010040class ConvolutionLayer final : public INode
Anthony Barbier2a07e182017-08-04 18:20:27 +010041{
42public:
43 /** Default Constructor
44 *
45 * @param[in] conv_width Convolution width
46 * @param[in] conv_height Convolution height
47 * @param[in] ofm Output feature map
48 * @param[in] weights Weights of the convolution layer
49 * @param[in] biases Bias of the convolution layer
50 * @param[in] conv_info Convolution information
Georgios Pinitas6f669f02017-09-26 12:32:57 +010051 * @param[in] num_groups (Optional) Number of groups, default = 1
52 * @param[in] weights_info (Optional) Weights information
Anthony Barbier2a07e182017-08-04 18:20:27 +010053 */
54 template <typename AccessorTypeWeights, typename AccessorTypeBiases>
Georgios Pinitas6f669f02017-09-26 12:32:57 +010055 ConvolutionLayer(unsigned int conv_width,
56 unsigned int conv_height,
57 unsigned int ofm,
58 AccessorTypeWeights &&weights,
59 AccessorTypeBiases &&biases,
60 const PadStrideInfo conv_info,
61 unsigned int num_groups = 1,
62 const WeightsInfo weights_info = WeightsInfo())
63 : _conv_width(conv_width),
64 _conv_height(conv_height),
65 _ofm(ofm),
66 _weights(std::move(weights)),
67 _biases(std::move(biases)),
68 _conv_info(std::move(conv_info)),
69 _num_groups(num_groups),
70 _weights_info(std::move(weights_info)),
71 _is(nullptr),
72 _os(nullptr),
73 _ws(nullptr),
74 _bs(nullptr)
Anthony Barbier2a07e182017-08-04 18:20:27 +010075 {
76 }
77
78 // Inherited methods overriden:
79 std::unique_ptr<arm_compute::IFunction> instantiate_node(Hint hint, ITensor *input, ITensor *output) override;
80 void print_info() override;
81
82private:
Georgios Pinitas6f669f02017-09-26 12:32:57 +010083 /** Instantiates a non-grouped convolution
84 *
85 * @param[in] conv_method_hint Hint that specifies which convolution layer method to use
86 *
87 * @return Convolution function
88 */
89 std::unique_ptr<arm_compute::IFunction> instantiate_convolution(ConvolutionMethodHint conv_method_hint);
90 /** Instantiates a grouped convolution
91 *
92 * @param[in] conv_method_hint Hint that specifies which convolution layer method to use
93 *
94 * @return Grouped Convolution function
95 */
96 std::unique_ptr<arm_compute::IFunction> instantiate_grouped_convolution(ConvolutionMethodHint conv_method_hint);
97
98private:
99 unsigned int _conv_width; /**< Convolution width */
100 unsigned int _conv_height; /**< Convolution height */
101 unsigned int _ofm; /**< Output feature maps */
102 Tensor _weights; /**< Weights tensor */
103 Tensor _biases; /**< Biases tensor */
104 const PadStrideInfo _conv_info; /**< Convolution layer information */
105 unsigned int _num_groups; /**< Number of groups */
106 const WeightsInfo _weights_info; /**< Convolution layer weights information */
107
108 std::unique_ptr<SubTensor[]> _is; /**< Input tensor sub-tensors used for grouped convolution */
109 std::unique_ptr<SubTensor[]> _os; /**< Output tensor sub-tensors used for grouped convolution */
110 std::unique_ptr<SubTensor[]> _ws; /**< Weights tensor sub-tensors used for grouped convolution */
111 std::unique_ptr<SubTensor[]> _bs; /**< Biases tensor sub-tensors used for grouped convolution */
Anthony Barbier2a07e182017-08-04 18:20:27 +0100112};
113} // namespace graph
114} // namespace arm_compute
115#endif /* __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ */