e76b721ea218169b74ca119f3cd31159c4b20f35
[platform/core/ml/nnfw.git] / runtime / onert / core / src / compiler / ExecutorFactory.h
1 /*
2  * Copyright (c) 2019 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_COMPILER_EXECUTOR_FACTORY_H__
18 #define __ONERT_COMPILER_EXECUTOR_FACTORY_H__
19
20 #include <unordered_map>
21
22 #include "backend/ITensor.h"
23 #include "exec/IExecutor.h"
24 #include "compiler/LoweredGraph.h"
25 #include "TensorRegistries.h"
26
27 namespace onert
28 {
29 namespace compiler
30 {
31
32 class ExecutorFactory
33 {
34 public:
35   static ExecutorFactory &get();
36
37 public:
38   exec::IExecutor *create(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
39                           const compiler::CompilerOptions &options,
40                           const std::shared_ptr<exec::ExecutorMap> &executor_map);
41
42 private:
43   ExecutorFactory();
44
45 private:
46   static void initializeBackendContext(compiler::LoweredGraph *lowered_graph);
47   static void runTensorRegistration(compiler::LoweredGraph *lowered_graph,
48                                     const std::vector<ir::OpSequenceIndex> &order);
49   static std::vector<backend::ITensor *>
50   initializeModelIOTensors(compiler::LoweredGraph &lowered_graph,
51                            const ir::OperandIndexSequence &indices);
52   static void prepareMigrantTensors(compiler::LoweredGraph &lowered_graph);
53   static exec::IExecutor *
54   createLinearExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
55                        const compiler::CompilerOptions &options,
56                        const std::shared_ptr<exec::ExecutorMap> &executor_map);
57   static exec::IExecutor *
58   createDataflowExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
59                          const compiler::CompilerOptions &options,
60                          const std::shared_ptr<exec::ExecutorMap> &executor_map, bool parallel);
61
62 private:
63   std::unordered_map<std::string, std::function<exec::IExecutor *(
64                                       std::unique_ptr<compiler::LoweredGraph>,
65                                       const compiler::CompilerOptions &options,
66                                       const std::shared_ptr<exec::ExecutorMap> &executor_map)>>
67       _map;
68 };
69
70 } // namespace compiler
71 } // namespace onert
72
73 #endif // __ONERT_COMPILER_EXECUTOR_FACTORY_H__