Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / compiler / luci-interpreter / src / loader / ModuleLoader.cpp
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 #include "ModuleLoader.h"
18
19 #include "GraphLoader.h"
20
21 namespace luci_interpreter
22 {
23
24 ModuleLoader::ModuleLoader(const luci::Module *module, RuntimeModule *runtime_module,
25                            RuntimeToIR &runtime_to_ir,
26                            std::unordered_map<const loco::Node *, Tensor *> &node_to_tensor)
27     : _module(module), _runtime_module(runtime_module), _runtime_to_ir(runtime_to_ir),
28       _node_to_tensor(node_to_tensor)
29 {
30 }
31
32 void ModuleLoader::load()
33 {
34   // Runtime graphs have to be created in advance, because they will be needed during the loading
35   // process for control flow nodes.
36   for (size_t i = 0; i < _module->size(); ++i)
37   {
38     _graph_to_runtime_graph.emplace(_module->graph(i), _runtime_module->addGraph());
39   }
40   for (size_t i = 0; i < _module->size(); ++i)
41   {
42     const loco::Graph *graph = _module->graph(i);
43     RuntimeGraph *runtime_graph = _graph_to_runtime_graph.at(graph);
44     GraphLoader loader(graph, runtime_graph, _runtime_to_ir, _graph_to_runtime_graph,
45                        _node_to_tensor);
46     loader.loadTensors();
47     loader.initInputOutputTensors();
48     loader.loadOperators();
49   }
50 }
51
52 } // namespace luci_interpreter