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