Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2020 Jijoong Moon <jijoong.moon@samsung.com>
4 : *
5 : * @file concat_layer.h
6 : * @date 27 Oct 2020
7 : * @see https://github.com/nnstreamer/nntrainer
8 : * @author Jijoong Moon <jijoong.moon@samsung.com>
9 : * @bug No known bugs except for NYI items
10 : * @brief This is Concat Layer Class for Neural Network
11 : *
12 : */
13 :
14 : #ifndef __CONCAT_LAYER_H__
15 : #define __CONCAT_LAYER_H__
16 : #ifdef __cplusplus
17 :
18 : #include <common_properties.h>
19 : #include <layer_devel.h>
20 : #include <tensor_dim.h>
21 : namespace nntrainer {
22 :
23 : /**
24 : * @class Concat Layer
25 : * @brief Concat Layer
26 : */
27 : class ConcatLayer : public Layer {
28 : public:
29 : /**
30 : * @brief Constructor of Concat Layer
31 : */
32 : ConcatLayer();
33 :
34 : /**
35 : * @brief Destructor of Concat Layer
36 : */
37 267 : ~ConcatLayer() = default;
38 :
39 : /**
40 : * @brief Move constructor of ConcatLayer.
41 : * @param[in] ConcatLayer &&
42 : */
43 : ConcatLayer(ConcatLayer &&rhs) noexcept = default;
44 :
45 : /**
46 : * @brief Move assignment operator.
47 : * @parma[in] rhs ConcatLayer to be moved.
48 : */
49 : ConcatLayer &operator=(ConcatLayer &&rhs) = default;
50 :
51 : /**
52 : * @copydoc Layer::finalize(InitLayerContext &context)
53 : */
54 : void finalize(InitLayerContext &context) override;
55 :
56 : /**
57 : * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
58 : */
59 : void forwarding(RunLayerContext &context, bool training) override;
60 :
61 : /**
62 : * @copydoc Layer::incremental_forwarding(RunLayerContext &context, unsigned
63 : * int from, unsigned int to, bool training)
64 : */
65 : void incremental_forwarding(RunLayerContext &context, unsigned int from,
66 : unsigned int to, bool training) override;
67 :
68 : /**
69 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
70 : */
71 : void calcDerivative(RunLayerContext &context) override;
72 :
73 : /**
74 : * @copydoc Layer::getType()
75 : */
76 2270 : const std::string getType() const override { return ConcatLayer::type; };
77 :
78 : /**
79 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
80 : * method)
81 : */
82 : void exportTo(Exporter &exporter,
83 : const ml::train::ExportMethods &method) const override;
84 :
85 : /**
86 : * @copydoc Layer::supportBackwarding()
87 : */
88 254 : bool supportBackwarding() const override { return true; }
89 :
90 : /**
91 : * @copydoc Layer::setProperty(const PropertyType type, const std::string
92 : * &value)
93 : */
94 : void setProperty(const std::vector<std::string> &values) override;
95 :
96 : /**
97 : * @copydoc Layer::setBatch(RunLayerContext &context, unsigned int batch)
98 : */
99 29 : void setBatch(RunLayerContext &context, unsigned int batch) override {
100 29 : setBatch(batch);
101 29 : }
102 :
103 : static constexpr const char *type = "concat";
104 :
105 : private:
106 : unsigned int leading_helper_dim; /**< batch dimension of helper dimension not
107 : containing the actual batch */
108 : std::vector<TensorDim>
109 : input_reshape_helper; /** helper dimension to reshape inputs */
110 : TensorDim output_reshape_helper; /** helper dimension to reshape outputs */
111 : std::tuple<props::ConcatDimension> concat_props;
112 :
113 : /**
114 : * @brief set batch for the internal variables
115 : *
116 : * @param batch update batch size
117 : */
118 137 : void setBatch(unsigned int batch) {
119 407 : for (auto &irh : input_reshape_helper)
120 270 : irh.batch(batch * leading_helper_dim);
121 137 : output_reshape_helper.batch(batch * leading_helper_dim);
122 137 : }
123 : };
124 :
125 : } // namespace nntrainer
126 :
127 : #endif /* __cplusplus */
128 : #endif /* __CONCAT_LAYER_H__ */
|