Imported Upstream version 1.7.0
[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 "ir/LoweredGraph.h"
25
26 namespace onert
27 {
28 namespace compiler
29 {
30
31 class ExecutorFactory
32 {
33 public:
34   static ExecutorFactory &get();
35
36 public:
37   exec::IExecutor *create(std::unique_ptr<ir::LoweredGraph> lowered_graph,
38                           const compiler::CompilerOptions &options,
39                           const std::shared_ptr<exec::ExecutorMap> &executor_map);
40
41 private:
42   ExecutorFactory();
43
44 private:
45   static void initializeBackendContext(ir::LoweredGraph *lowered_graph);
46   static void runTensorRegistration(ir::LoweredGraph *lowered_graph,
47                                     const std::vector<ir::OpSequenceIndex> &order);
48   static std::vector<std::shared_ptr<backend::ITensor>>
49   initializeModelIOTensors(ir::LoweredGraph &lowered_graph,
50                            const ir::OperandIndexSequence &indices);
51   static exec::IExecutor *
52   createLinearExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
53                        const compiler::CompilerOptions &options,
54                        const std::shared_ptr<exec::ExecutorMap> &executor_map);
55   static exec::IExecutor *
56   createDataflowExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
57                          const compiler::CompilerOptions &options,
58                          const std::shared_ptr<exec::ExecutorMap> &executor_map, bool parallel);
59
60 private:
61   std::unordered_map<
62       std::string, std::function<exec::IExecutor *(
63                        std::unique_ptr<ir::LoweredGraph>, const compiler::CompilerOptions &options,
64                        const std::shared_ptr<exec::ExecutorMap> &executor_map)>>
65       _map;
66 };
67
68 } // namespace compiler
69 } // namespace onert
70
71 #endif // __ONERT_COMPILER_EXECUTOR_FACTORY_H__