ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ModuleLoader.cpp
Go to the documentation of this file.
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
21namespace luci_interpreter
22{
23
24void ModuleLoader::load(RuntimeModule *runtime_module, SimpleMemoryManager *memory_manager,
25 const char *model_data_raw, bool dealloc_input)
26{
27 const circle::Model *model = circle::GetModel(model_data_raw);
28
29 CircleReader &reader = runtime_module->getCircleReader();
30 if (!reader.parse(model))
31 assert(false && "Error during parse");
32
33 for (size_t i = 0; i < reader.num_subgraph(); ++i)
34 {
35 if (!reader.select_subgraph(i))
36 assert(false && "Error during select subgraph");
37 runtime_module->addGraph(memory_manager);
38
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
44 }
45
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)
49 {
50 auto *runtime_graph = runtime_module->getRuntimeGraphAt(i);
51#ifdef USE_STATIC_ALLOC
52 runtime_graph->configure_kernels();
53#else
54 runtime_graph->configure(dealloc_input);
55#endif // USE_STATIC_ALLOC
56 }
57
58 // Select main subgraph
59 reader.select_subgraph(0);
60}
61
62} // namespace luci_interpreter
Loads Circle file and provides helpers to access attributes.
bool select_subgraph(uint32_t subgraph)
bool parse(const circle::Model *model)
uint32_t num_subgraph() const
static void checkInplaceOps(CircleReader *reader, RuntimeGraph *runtime_graph)
void configure(bool dealloc_input)
BaseRuntimeGraph * getRuntimeGraphAt(uint32_t pos)
RuntimeGraph * addGraph(IMemoryManager *memory_manager)