Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2024 SeungBaek Hong <sb92.hong@samsung.com>
4 : *
5 : * @file pow_layer.h
6 : * @date 20 Nov 2024
7 : * @see https://github.com/nnstreamer/nntrainer
8 : * @author SeungBaek Hong <sb92.hong@samsung.com>
9 : * @bug No known bugs except for NYI items
10 : * @brief This is pow layer class (operation layer)
11 : *
12 : */
13 :
14 : #ifndef __POW_LAYER_H__
15 : #define __POW_LAYER_H__
16 : #ifdef __cplusplus
17 :
18 : #include <common_properties.h>
19 : #include <layer_devel.h>
20 : #include <operation_layer.h>
21 :
22 : namespace nntrainer {
23 :
24 : /**
25 : * @class Pow Layer
26 : * @brief Pow Layer
27 : */
28 : class PowLayer : public UnaryOperationLayer {
29 : public:
30 : /**
31 : * @brief Constructor of Pow Layer
32 : */
33 40 : PowLayer() :
34 : UnaryOperationLayer(),
35 40 : pow_props(props::Print(), props::InPlaceProp(), props::Exponent()),
36 80 : support_backwarding(true) {}
37 :
38 : /**
39 : * @brief Destructor of Pow Layer
40 : */
41 40 : ~PowLayer(){};
42 :
43 : /**
44 : * @brief Move constructor of Pow Layer.
45 : * @param[in] PowLayer &&
46 : */
47 : PowLayer(PowLayer &&rhs) noexcept = default;
48 :
49 : /**
50 : * @brief Move assignment operator.
51 : * @parma[in] rhs PowLayer to be moved.
52 : */
53 : PowLayer &operator=(PowLayer &&rhs) = default;
54 :
55 : /**
56 : * @copydoc Layer::finalize(InitLayerContext &context)
57 : */
58 : void finalize(InitLayerContext &context) final;
59 :
60 : /**
61 : * @brief forwarding operation for pow
62 : *
63 : * @param input input tensor
64 : * @param hidden tensor to store the result value
65 : */
66 : void forwarding_operation(const Tensor &input, Tensor &hidden) final;
67 :
68 : /**
69 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
70 : */
71 : void calcDerivative(RunLayerContext &context) final;
72 :
73 : /**
74 : * @copydoc bool supportBackwarding() const
75 : */
76 14 : bool supportBackwarding() const final { return support_backwarding; };
77 :
78 : /**
79 : * @brief Initialize the in-place settings of the layer
80 : * @return InPlaceType
81 : */
82 2 : InPlaceType initializeInPlace() final {
83 2 : if (std::get<props::InPlaceProp>(pow_props).empty() ||
84 0 : !std::get<props::InPlaceProp>(pow_props).get()) {
85 2 : is_inplace = false;
86 2 : support_backwarding = true;
87 : } else {
88 0 : is_inplace = true;
89 0 : support_backwarding = false;
90 : }
91 :
92 2 : if (!supportInPlace())
93 : return InPlaceType::NONE;
94 : else
95 0 : return InPlaceType::NON_RESTRICTING;
96 : }
97 :
98 : /**
99 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
100 : * method)
101 : */
102 2 : void exportTo(Exporter &exporter,
103 2 : const ml::train::ExportMethods &method) const final {}
104 :
105 : /**
106 : * @copydoc Layer::setProperty(const std::vector<std::string> &values)
107 : */
108 : void setProperty(const std::vector<std::string> &values) final;
109 :
110 : /**
111 : * @copydoc Layer::getType()
112 : */
113 130 : const std::string getType() const final { return PowLayer::type; };
114 :
115 : std::tuple<props::Print, props::InPlaceProp, props::Exponent> pow_props;
116 : bool support_backwarding; /**< support backwarding */
117 :
118 : static constexpr const char *type = "pow";
119 : };
120 :
121 : } // namespace nntrainer
122 :
123 : #endif /* __cplusplus */
124 : #endif /* __POW_LAYER_H__ */
|