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.cpp
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 : #include "base_properties.h"
15 : #include "common_properties.h"
16 : #include <cast_layer.h>
17 : #include <nntrainer_error.h>
18 : #include <nntrainer_log.h>
19 : #include <node_exporter.h>
20 : #include <util_func.h>
21 :
22 : #include <layer_context.h>
23 : namespace nntrainer {
24 :
25 8 : void CastLayer::finalize(InitLayerContext &context) {
26 : props::TensorDataType dtype =
27 8 : std::get<props::TensorDataType>(cast_props).get();
28 8 : TensorDim out_dim = TensorDim(context.getInputDimensions()[0]);
29 8 : out_dim.setDataType(dtype);
30 8 : context.setOutputDimensions({out_dim});
31 8 : }
32 :
33 0 : void CastLayer::forwarding_operation(const Tensor &input, Tensor &output) {
34 : // Casting type is performed in copyData function
35 0 : output.copyData(input);
36 0 : }
37 :
38 0 : void CastLayer::calcDerivative(RunLayerContext &context) {
39 0 : context.getOutgoingDerivative(SINGLE_INOUT_IDX)
40 0 : .copyData(context.getIncomingDerivative(SINGLE_INOUT_IDX));
41 0 : }
42 :
43 66 : void CastLayer::setProperty(const std::vector<std::string> &values) {
44 66 : auto remain_props = loadProperties(values, cast_props);
45 64 : if (!remain_props.empty()) {
46 : std::string msg = "[CastLayer] Unknown Layer Properties count " +
47 4 : std::to_string(remain_props.size());
48 8 : throw exception::not_supported(msg);
49 : }
50 64 : }
51 :
52 : } /* namespace nntrainer */
|