Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / train / KernelGenerator.h
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 #ifndef __ONERT_BACKEND_TRAIN_KERNEL_GENERATOR_H__
18 #define __ONERT_BACKEND_TRAIN_KERNEL_GENERATOR_H__
19
20 #include "ExternalContext.h"
21 #include "backend/basic/TensorRegistry.h"
22 #include "TensorBuilder.h"
23 #include "Tensor.h"
24
25 #include <backend/train/KernelGeneratorBase.h>
26 #include <exec/train/IGradientApplier.h>
27 #include <exec/train/optimizer/Optimizer.h>
28 #include <ir/Operands.h>
29 #include <ir/Operations.h>
30
31 namespace onert
32 {
33 namespace backend
34 {
35 namespace train
36 {
37
38 // TODO Unify TensorRegistry
39 class KernelGenerator : public backend::train::KernelGeneratorBase
40 {
41 public:
42   KernelGenerator(const ir::train::TrainableGraph &tgraph,
43                   const std::shared_ptr<TensorRegistry> &tensor_reg,
44                   const std::shared_ptr<ExternalContext> &external_context,
45                   std::shared_ptr<exec::train::optimizer::Optimizer> optimizer);
46
47   std::unique_ptr<exec::train::TrainableFnSequence> generate(ir::OperationIndex op_ind) override;
48
49   void visit(const ir::train::operation::Conv2D &) override;
50   void visit(const ir::train::operation::ElementwiseActivation &) override;
51   void visit(const ir::train::operation::FullyConnected &) override;
52   void visit(const ir::train::operation::Loss &) override;
53   void visit(const ir::train::operation::Reshape &node) override;
54
55 private:
56   ir::Layout _current_layout;
57   std::shared_ptr<TensorRegistry> _tensor_reg;
58   const std::shared_ptr<ExternalContext> _external_context;
59   std::shared_ptr<exec::train::optimizer::Optimizer> _optimizer;
60   std::vector<std::unique_ptr<exec::train::IGradientApplier>> _update_funcs;
61 };
62
63 } // namespace train
64 } // namespace backend
65 } // namespace onert
66
67 #endif // __ONERT_BACKEND_TRAIN_KERNEL_GENERATOR_H__