Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2025 SeungBaek Hong <sb92.hong@samsung.com>
4 : *
5 : * @file cast_layer.h
6 : * @date 04 April 2025
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 cast layer class (operation layer)
11 : *
12 : */
13 :
14 : #ifndef __CAST_LAYER_H__
15 : #define __CAST_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 Cast Layer
26 : * @brief Cast Layer
27 : */
28 : class CastLayer : public UnaryOperationLayer {
29 : public:
30 : /**
31 : * @brief Constructor of Cast Layer
32 : */
33 36 : CastLayer() :
34 : UnaryOperationLayer(),
35 36 : cast_props(props::Print(), props::TensorDataType()),
36 72 : support_backwarding(true) {}
37 :
38 : /**
39 : * @brief Destructor of Cast Layer
40 : */
41 36 : ~CastLayer(){};
42 :
43 : /**
44 : * @brief Move constructor of Cast Layer.
45 : * @param[in] CastLayer &&
46 : */
47 : CastLayer(CastLayer &&rhs) noexcept = default;
48 :
49 : /**
50 : * @brief Move assignment operator.
51 : * @parma[in] rhs CastLayer to be moved.
52 : */
53 : CastLayer &operator=(CastLayer &&rhs) = default;
54 :
55 : /**
56 : * @copydoc Layer::finalize(InitLayerContext &context)
57 : */
58 : void finalize(InitLayerContext &context) final;
59 :
60 : /**
61 : * @brief forwarding operation for cast
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 4 : bool supportBackwarding() const final { return support_backwarding; };
77 :
78 : /**
79 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
80 : * method)
81 : */
82 0 : void exportTo(Exporter &exporter,
83 0 : const ml::train::ExportMethods &method) const final {}
84 :
85 : /**
86 : * @copydoc Layer::setProperty(const std::vector<std::string> &values)
87 : */
88 : void setProperty(const std::vector<std::string> &values) final;
89 :
90 : /**
91 : * @copydoc Layer::getType()
92 : */
93 42 : const std::string getType() const final { return CastLayer::type; };
94 :
95 : std::tuple<props::Print, props::TensorDataType> cast_props;
96 : bool support_backwarding;
97 :
98 : static constexpr const char *type = "cast";
99 : };
100 :
101 : } // namespace nntrainer
102 :
103 : #endif /* __cplusplus */
104 : #endif /* __CAST_LAYER_H__ */
|