Imported Upstream version 1.21.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / backend / builtin / KernelGenerator.h
1 /*
2  * Copyright (c) 2020 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_BUILTIN_KERNEL_GENERATOR_H__
18 #define __ONERT_BACKEND_BUILTIN_KERNEL_GENERATOR_H__
19
20 #include "DynamicTensorManager.h"
21 #include "ExternalContext.h"
22 #include "TensorRegistry.h"
23 #include "../../compiler/TensorRegistries.h"
24
25 #include "backend/basic/KernelGeneratorBase.h"
26 #include "exec/Executors.h"
27 #include "ir/Graph.h"
28
29 namespace onert
30 {
31 namespace backend
32 {
33 namespace builtin
34 {
35
36 class KernelGenerator : public basic::KernelGeneratorBase
37 {
38 public:
39   KernelGenerator(const ir::Graph &graph, DynamicTensorManager *dyn_tensor_manager,
40                   const std::shared_ptr<TensorRegistry> &tensor_reg,
41                   const std::shared_ptr<ExternalContext> &external_context);
42
43   void setTensorRegistries(const compiler::TensorRegistries &tensor_registries)
44   {
45     _tensor_registries = tensor_registries;
46   }
47   void setExecutors(const std::shared_ptr<exec::Executors> &executors)
48   {
49     // FIXME Using shared_ptr's raw pointer!
50     _executors = executors.get();
51   }
52
53   std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) override;
54
55 private:
56   void visit(const ir::operation::If &) override;
57   void visit(const ir::operation::Permute &) override;
58   void visit(const ir::operation::While &) override;
59
60 private:
61   backend::ITensor *getTensor(const ir::OperandIndex &index);
62   backend::IPortableTensor *getPortableTensor(const ir::OperandIndex &index);
63
64 private:
65   DynamicTensorManager *_dyn_tensor_manager;
66   std::shared_ptr<TensorRegistry> _tensor_reg;
67   compiler::TensorRegistries _tensor_registries;
68   exec::Executors *_executors;
69   const std::shared_ptr<ExternalContext> _external_context;
70 };
71
72 } // namespace builtin
73 } // namespace backend
74 } // namespace onert
75
76 #endif // __ONERT_BACKEND_BUILTIN_KERNEL_GENERATOR_H__