blob: 04ba3dd6b7c70c3280173fa84adc1bfdc6a2b3a6 [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
Georgios Pinitasff421f22017-10-04 16:53:58 +010027#include "arm_compute/graph/GraphContext.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010028#include "arm_compute/graph/INode.h"
Georgios Pinitas6f669f02017-09-26 12:32:57 +010029#include "arm_compute/graph/SubTensor.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010030#include "arm_compute/graph/Tensor.h"
31#include "arm_compute/graph/Types.h"
Georgios Pinitas6f669f02017-09-26 12:32:57 +010032#include "arm_compute/runtime/IFunction.h"
33
34#include <memory>
Anthony Barbier2a07e182017-08-04 18:20:27 +010035
36namespace arm_compute
37{
38namespace graph
39{
40/** Convolution layer node */
Georgios Pinitas6f669f02017-09-26 12:32:57 +010041class ConvolutionLayer final : public INode
Anthony Barbier2a07e182017-08-04 18:20:27 +010042{
43public:
44 /** Default Constructor
45 *
46 * @param[in] conv_width Convolution width
47 * @param[in] conv_height Convolution height
48 * @param[in] ofm Output feature map
49 * @param[in] weights Weights of the convolution layer
50 * @param[in] biases Bias of the convolution layer
51 * @param[in] conv_info Convolution information
Georgios Pinitas6f669f02017-09-26 12:32:57 +010052 * @param[in] num_groups (Optional) Number of groups, default = 1
53 * @param[in] weights_info (Optional) Weights information
Anthony Barbier2a07e182017-08-04 18:20:27 +010054 */
55 template <typename AccessorTypeWeights, typename AccessorTypeBiases>
Georgios Pinitas6f669f02017-09-26 12:32:57 +010056 ConvolutionLayer(unsigned int conv_width,
57 unsigned int conv_height,
58 unsigned int ofm,
59 AccessorTypeWeights &&weights,
60 AccessorTypeBiases &&biases,
61 const PadStrideInfo conv_info,
62 unsigned int num_groups = 1,
63 const WeightsInfo weights_info = WeightsInfo())
64 : _conv_width(conv_width),
65 _conv_height(conv_height),
66 _ofm(ofm),
67 _weights(std::move(weights)),
68 _biases(std::move(biases)),
69 _conv_info(std::move(conv_info)),
70 _num_groups(num_groups),
71 _weights_info(std::move(weights_info)),
72 _is(nullptr),
73 _os(nullptr),
74 _ws(nullptr),
75 _bs(nullptr)
Anthony Barbier2a07e182017-08-04 18:20:27 +010076 {
77 }
78
79 // Inherited methods overriden:
Georgios Pinitasff421f22017-10-04 16:53:58 +010080 std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensor *input, ITensor *output) override;
Anthony Barbier2a07e182017-08-04 18:20:27 +010081
82private:
Georgios Pinitas6f669f02017-09-26 12:32:57 +010083 /** Instantiates a non-grouped convolution
84 *
Michalis Spyroue4720822017-10-02 17:44:52 +010085 * @param[in] input Input tensor
86 * @param[in] output Output tensor
Georgios Pinitas6f669f02017-09-26 12:32:57 +010087 * @param[in] conv_method_hint Hint that specifies which convolution layer method to use
88 *
89 * @return Convolution function
90 */
Michalis Spyroue4720822017-10-02 17:44:52 +010091 std::unique_ptr<arm_compute::IFunction> instantiate_convolution(ITensor *input, ITensor *output, ConvolutionMethodHint conv_method_hint);
Georgios Pinitas6f669f02017-09-26 12:32:57 +010092 /** Instantiates a grouped convolution
93 *
Michalis Spyroue4720822017-10-02 17:44:52 +010094 * @param[in] input Input tensor
95 * @param[in] output Output tensor
Georgios Pinitas6f669f02017-09-26 12:32:57 +010096 * @param[in] conv_method_hint Hint that specifies which convolution layer method to use
97 *
98 * @return Grouped Convolution function
99 */
Michalis Spyroue4720822017-10-02 17:44:52 +0100100 std::unique_ptr<arm_compute::IFunction> instantiate_grouped_convolution(ITensor *input, ITensor *output, ConvolutionMethodHint conv_method_hint);
Georgios Pinitas6f669f02017-09-26 12:32:57 +0100101
102private:
103 unsigned int _conv_width; /**< Convolution width */
104 unsigned int _conv_height; /**< Convolution height */
105 unsigned int _ofm; /**< Output feature maps */
106 Tensor _weights; /**< Weights tensor */
107 Tensor _biases; /**< Biases tensor */
108 const PadStrideInfo _conv_info; /**< Convolution layer information */
109 unsigned int _num_groups; /**< Number of groups */
110 const WeightsInfo _weights_info; /**< Convolution layer weights information */
111
112 std::unique_ptr<SubTensor[]> _is; /**< Input tensor sub-tensors used for grouped convolution */
113 std::unique_ptr<SubTensor[]> _os; /**< Output tensor sub-tensors used for grouped convolution */
114 std::unique_ptr<SubTensor[]> _ws; /**< Weights tensor sub-tensors used for grouped convolution */
115 std::unique_ptr<SubTensor[]> _bs; /**< Biases tensor sub-tensors used for grouped convolution */
Anthony Barbier2a07e182017-08-04 18:20:27 +0100116};
117} // namespace graph
118} // namespace arm_compute
119#endif /* __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ */