2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "ModuleLoader.h"
19 #include "GraphLoader.h"
21 namespace luci_interpreter
24 void ModuleLoader::load(RuntimeModule *runtime_module, SimpleMemoryManager *memory_manager,
25 const char *model_data_raw, bool dealloc_input)
27 const circle::Model *model = circle::GetModel(model_data_raw);
29 CircleReader &reader = runtime_module->getCircleReader();
30 if (!reader.parse(model))
31 assert(false && "Error during parse");
33 for (size_t i = 0; i < reader.num_subgraph(); ++i)
35 if (!reader.select_subgraph(i))
36 assert(false && "Error during select subgraph");
37 runtime_module->addGraph(memory_manager);
39 #ifndef USE_STATIC_ALLOC
40 auto *runtime_graph = runtime_module->getRuntimeGraphAt(i);
41 // For Dynamic memory manager we can use inplace optimization
42 GraphLoader::checkInplaceOps(&reader, runtime_graph);
43 #endif // USE_STATIC_ALLOC
46 // For Dynamic Memory manager we build memory allocate/deallocate plan and then configure kernels.
47 // For Static Memory manager we only configure kernels.
48 for (size_t i = 0; i < reader.num_subgraph(); ++i)
50 auto *runtime_graph = runtime_module->getRuntimeGraphAt(i);
51 #ifdef USE_STATIC_ALLOC
52 runtime_graph->configure_kernels();
54 runtime_graph->configure(dealloc_input);
55 #endif // USE_STATIC_ALLOC
58 // Select main subgraph
59 reader.select_subgraph(0);
62 } // namespace luci_interpreter