Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / compiler / train / TrainableOperationConverter.cc
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "TrainableOperationConverter.h"
18
19 #include "ir/train/Operations.Include.h"
20 #include "util/Utils.h"
21
22 namespace onert
23 {
24 namespace compiler
25 {
26 namespace train
27 {
28
29 TrainableOperationConverter::TrainableOperationConverter(
30   ir::train::TrainableGraph &tgraph, const compiler::train::TrainingInfo *training_info)
31   : UntrainableOperationConverter{tgraph}, _training_info{training_info}
32 {
33   // Avoid unused-private-field error
34   UNUSED_RELEASE(_training_info);
35 }
36
37 void TrainableOperationConverter::visit(const ir::operation::Conv2D &node)
38 {
39   _return_op = std::make_unique<ir::train::operation::Conv2D>(node);
40 }
41
42 void TrainableOperationConverter::visit(const ir::operation::ElementwiseActivation &node)
43 {
44   if (node.param().op_type == ir::operation::ElementwiseActivation::Type::RELU)
45   {
46     _return_op = std::make_unique<ir::train::operation::ElementwiseActivation>(node);
47   }
48   else
49   {
50     UntrainableOperationConverter::visit(node);
51   }
52 }
53
54 void TrainableOperationConverter::visit(const ir::operation::FullyConnected &node)
55 {
56   _return_op = std::make_unique<ir::train::operation::FullyConnected>(node);
57 }
58
59 void TrainableOperationConverter::visit(const ir::operation::Loss &node)
60 {
61   _return_op = std::make_unique<ir::train::operation::Loss>(node);
62 }
63
64 void TrainableOperationConverter::visit(const ir::operation::Permute &node)
65 {
66   _return_op = std::make_unique<ir::train::operation::Permute>(node);
67 }
68
69 void TrainableOperationConverter::visit(const ir::operation::Pool2D &node)
70 {
71   _return_op = std::make_unique<ir::train::operation::Pool2D>(node);
72 }
73
74 void TrainableOperationConverter::visit(const ir::operation::Reshape &node)
75 {
76   _return_op = std::make_unique<ir::train::operation::Reshape>(node);
77 }
78
79 void TrainableOperationConverter::visit(const ir::operation::Softmax &node)
80 {
81   _return_op = std::make_unique<ir::train::operation::Softmax>(node);
82 }
83
84 } // namespace train
85 } // namespace compiler
86 } // namespace onert