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 add_layer.cpp
6 : * @date 7 Oct 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 add layer class (operation layer)
11 : *
12 : */
13 :
14 : #include "common_properties.h"
15 : #include <add_layer.h>
16 : #include <nntrainer_error.h>
17 : #include <nntrainer_log.h>
18 : #include <node_exporter.h>
19 : #include <util_func.h>
20 :
21 : #include <layer_context.h>
22 :
23 : namespace nntrainer {
24 :
25 12 : void AddLayer::finalize(InitLayerContext &context) {
26 12 : context.setOutputDimensions({context.getInputDimensions()[0]});
27 12 : }
28 :
29 6 : void AddLayer::forwarding_operation(const Tensor &input0, const Tensor &input1,
30 : Tensor &hidden) {
31 6 : input0.add(input1, hidden);
32 6 : }
33 :
34 3 : void AddLayer::calcDerivative(RunLayerContext &context) {
35 6 : context.getOutgoingDerivative(0).copy(
36 6 : context.getIncomingDerivative(SINGLE_INOUT_IDX));
37 :
38 6 : context.getOutgoingDerivative(1).copy(
39 6 : context.getIncomingDerivative(SINGLE_INOUT_IDX));
40 3 : }
41 :
42 90 : void AddLayer::setProperty(const std::vector<std::string> &values) {
43 90 : auto remain_props = loadProperties(values, add_props);
44 88 : if (!remain_props.empty()) {
45 : std::string msg = "[AddLayer] Unknown Layer Properties count " +
46 4 : std::to_string(values.size());
47 8 : throw exception::not_supported(msg);
48 : }
49 88 : }
50 : } /* namespace nntrainer */
|