ONE - On-device Neural Engine
Loading...
Searching...
No Matches
RuntimeModule.h
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#ifndef LUCI_INTERPRETER_CORE_RUNTIMEMODULE_H
18#define LUCI_INTERPRETER_CORE_RUNTIMEMODULE_H
19
20#include "core/RuntimeGraph.h"
22
23#ifdef ENABLE_TRAINING
25#include "TrainingGraph.h"
26#include "core/RuntimeGraph.h"
27#endif // ENABLE_TRAINING
28
29#include <memory>
30#include <vector>
31
32namespace luci_interpreter
33{
34
35#ifdef USE_STATIC_ALLOC
36using BaseRuntimeGraph = StaticRuntimeGraph;
37using MemoryManager = StaticMemoryManager;
38#else
41#endif // USE_STATIC_ALLOC
42
43#ifdef ENABLE_TRAINING
44namespace training
45{
46
47class TrainingModule;
48
49} // namespace training
50#endif // ENABLE_TRAINING
51
52class RuntimeModule
53{
54public:
55 RuntimeModule() = default;
56
57#ifdef ENABLE_TRAINING
58 friend class training::TrainingModule;
59#endif // ENABLE_TRAINING
60
61 void addGraph(MemoryManager *memory_manager)
62 {
63 _graphs.emplace_back(memory_manager, &_circle_reader, this,
64 _circle_reader.get_current_subgraph_index());
65 }
66
67 BaseRuntimeGraph *getRuntimeGraphAt(uint32_t pos) { return &_graphs.at(pos); }
68
69 void execute() { getMainGraph()->execute(); }
70
71 CircleReader &getCircleReader() { return _circle_reader; }
72
73 BaseRuntimeGraph *getMainGraph() const { return const_cast<BaseRuntimeGraph *>(&_graphs[0]); }
74
75 void selectSubgraph(uint32_t index) { _circle_reader.select_subgraph(index); }
76
77private:
78 std::vector<BaseRuntimeGraph> _graphs;
79
80 CircleReader _circle_reader;
81
82#ifdef ENABLE_TRAINING
83 std::unique_ptr<training::TrainableWeightStorage> _storage;
84#endif // ENABLE_TRAINING
85};
86
87} // namespace luci_interpreter
88
89#endif // LUCI_INTERPRETER_CORE_RUNTIMEMODULE_H
Loads Circle file and provides helpers to access attributes.
bool select_subgraph(uint32_t subgraph)
BaseRuntimeGraph * getRuntimeGraphAt(uint32_t pos)
BaseRuntimeGraph * getMainGraph() const
void selectSubgraph(uint32_t index)
void addGraph(MemoryManager *memory_manager)
RuntimeGraph BaseRuntimeGraph
SimpleMemoryManager MemoryManager