Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / backend / builtin / 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_BUTIN_TRAIN_KERNEL_GENERATOR_H__
18 #define __ONERT_BACKEND_BUTIN_TRAIN_KERNEL_GENERATOR_H__
19
20 #include "../ExternalContext.h"
21 #include "../train/TensorRegistry.h"
22 #include "../../../compiler/train/TensorRegistries.h"
23
24 #include <backend/train/KernelGeneratorBase.h>
25 #include <exec/train/TrainableFnSequence.h>
26 #include <ir/train/TrainableGraph.h>
27
28 namespace onert
29 {
30 namespace backend
31 {
32 namespace builtin
33 {
34 namespace train
35 {
36
37 class KernelGenerator : public backend::train::KernelGeneratorBase
38 {
39 public:
40   KernelGenerator(const ir::train::TrainableGraph &tgraph,
41                   const std::shared_ptr<TensorRegistry> &tensor_reg,
42                   const std::shared_ptr<ExternalContext> &external_context);
43
44   std::unique_ptr<exec::train::TrainableFnSequence> generate(ir::OperationIndex ind) override;
45
46   void setTensorRegistries(const compiler::train::TensorRegistries &tensor_registries)
47   {
48     _tensor_registries = tensor_registries;
49   }
50
51   void setWholeGraphOutputs(const ir::OperandIndexSequence &outputs)
52   {
53     _whole_graph_outputs = outputs;
54   }
55
56 private:
57   void visit(const ir::train::operation::Permute &) override;
58
59 private:
60   backend::ITensor *getTensor(const ir::OperandIndex &index);
61   backend::ITensor *getDerivativeTensor(const ir::OperandIndex &index);
62
63 private:
64   std::shared_ptr<TensorRegistry> _tensor_reg;
65   compiler::train::TensorRegistries _tensor_registries;
66   const std::shared_ptr<ExternalContext> _external_context;
67   ir::OperandIndexSequence _whole_graph_outputs;
68 };
69
70 } // namespace train
71 } // namespace builtin
72 } // namespace backend
73 } // namespace onert
74
75 #endif // __ONERT_BACKEND_BUTIN_TRAIN_KERNEL_GENERATOR_H__