ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert_micro::core::OMRuntimeModule Class Reference

#include <OMRuntimeModule.h>

Public Member Functions

 OMRuntimeModule ()=default
 
 OMRuntimeModule (const OMRuntimeModule &)=delete
 
 OMRuntimeModule (OMRuntimeModule &&)=delete
 
OMRuntimeModuleoperator= (const OMRuntimeModule &)=delete
 
OMRuntimeModule && operator= (const OMRuntimeModule &&)=delete
 
 ~OMRuntimeModule ()=default
 
OMStatus importModel (const char *model_ptr, const OMConfig &config)
 
OMStatus run (const OMConfig &config)
 
OMStatus reset ()
 
uint32_t getNumberOfInputs ()
 
uint32_t getNumberOfOutputs ()
 
uint32_t getInputSizeAt (uint32_t position)
 
uint32_t getOutputSizeAt (uint32_t position)
 
void * getInputDataAt (uint32_t position)
 
void * getOutputDataAt (uint32_t position)
 
OMStatus getRuntimeGraphAt (uint32_t pos, OMRuntimeGraph **runtime_graph)
 
OMStatus allocateInputs ()
 

Protected Attributes

std::vector< OMRuntimeGraph_graphs
 

Detailed Description

Definition at line 32 of file OMRuntimeModule.h.

Constructor & Destructor Documentation

◆ OMRuntimeModule() [1/3]

onert_micro::core::OMRuntimeModule::OMRuntimeModule ( )
default

◆ OMRuntimeModule() [2/3]

onert_micro::core::OMRuntimeModule::OMRuntimeModule ( const OMRuntimeModule )
delete

◆ OMRuntimeModule() [3/3]

onert_micro::core::OMRuntimeModule::OMRuntimeModule ( OMRuntimeModule &&  )
delete

◆ ~OMRuntimeModule()

onert_micro::core::OMRuntimeModule::~OMRuntimeModule ( )
default

Member Function Documentation

◆ allocateInputs()

OMStatus OMRuntimeModule::allocateInputs ( )

Definition at line 143 of file OMRuntimeModule.cpp.

144{
145 assert(_graphs.size() > 0);
146 if (_graphs.size() == 0)
147 return ModelNotImport;
148 return _graphs.at(0).allocateGraphInputs();
149}
std::vector< OMRuntimeGraph > _graphs
@ ModelNotImport
Definition OMStatus.h:31

References _graphs, and onert_micro::ModelNotImport.

Referenced by onert_micro::OMInterpreter::allocateInputs(), and onert_micro::OMTrainingInterpreter::allocateInputs().

◆ getInputDataAt()

void * OMRuntimeModule::getInputDataAt ( uint32_t  position)

Definition at line 41 of file OMRuntimeModule.cpp.

42{
43 return _graphs.at(0).getInputDataAt(position);
44}

References _graphs.

Referenced by onert_micro::OMInterpreter::getInputDataAt(), and onert_micro::OMTrainingInterpreter::getInputDataAt().

◆ getInputSizeAt()

uint32_t OMRuntimeModule::getInputSizeAt ( uint32_t  position)

Definition at line 31 of file OMRuntimeModule.cpp.

32{
33 return _graphs.at(0).getInputSizeAt(position);
34}

References _graphs.

Referenced by onert_micro::OMInterpreter::getInputSizeAt(), and onert_micro::OMTrainingInterpreter::getInputSizeAt().

◆ getNumberOfInputs()

uint32_t OMRuntimeModule::getNumberOfInputs ( )

Definition at line 27 of file OMRuntimeModule.cpp.

27{ return _graphs.at(0).getNumberOfInputs(); }

References _graphs.

Referenced by onert_micro::OMInterpreter::getNumberOfInputs().

◆ getNumberOfOutputs()

uint32_t OMRuntimeModule::getNumberOfOutputs ( )

Definition at line 29 of file OMRuntimeModule.cpp.

29{ return _graphs.at(0).getNumberOfOutputs(); }

References _graphs.

Referenced by onert_micro::OMInterpreter::getNumberOfOutputs().

◆ getOutputDataAt()

void * OMRuntimeModule::getOutputDataAt ( uint32_t  position)

Definition at line 46 of file OMRuntimeModule.cpp.

47{
48 return _graphs.at(0).getOutputDataAt(position);
49}

References _graphs.

Referenced by onert_micro::OMInterpreter::getOutputDataAt(), and onert_micro::OMTrainingInterpreter::getOutputDataAt().

◆ getOutputSizeAt()

uint32_t OMRuntimeModule::getOutputSizeAt ( uint32_t  position)

Definition at line 36 of file OMRuntimeModule.cpp.

37{
38 return _graphs.at(0).getOutputSizeAt(position);
39}

References _graphs.

Referenced by onert_micro::OMInterpreter::getOutputSizeAt(), and onert_micro::OMTrainingInterpreter::getOutputSizeAt().

◆ getRuntimeGraphAt()

OMStatus OMRuntimeModule::getRuntimeGraphAt ( uint32_t  pos,
OMRuntimeGraph **  runtime_graph 
)

Definition at line 189 of file OMRuntimeModule.cpp.

190{
191 if (pos >= _graphs.size())
192 return UnknownError;
193
194 *runtime_graph = &_graphs.at(pos);
195
196 return Ok;
197}

References _graphs, onert_micro::Ok, and onert_micro::UnknownError.

◆ importModel()

OMStatus OMRuntimeModule::importModel ( const char *  model_ptr,
const OMConfig config 
)

Definition at line 51 of file OMRuntimeModule.cpp.

52{
53 assert(model_ptr != nullptr && "Model ptr shouldn't be nullptr");
54 if (model_ptr == nullptr)
55 return UnknownError;
56
57 // 1 - parse reader
58 // 2 - load default graph
59 // 3 - optimize it until can
60 // 4 - AllocDeallocPlan creation
61 // 5 - KernelConfigure
62 // 6 - Allocate inputs
63
64 OMStatus status;
65 // First - parse reader
66 uint32_t num_subgraph = 0;
67 {
69 status = reader.parse(model_ptr);
70 if (status != Ok)
71 return status;
72 num_subgraph = reader.num_subgraph();
73 }
74
75 assert(num_subgraph >= 1);
76 if (num_subgraph == 0)
77 return UnknownError;
78
79 _graphs.resize(num_subgraph);
80
81 for (uint32_t i = 0; i < num_subgraph; ++i)
82 {
83 // Second - load default graph
85
86 OMRuntimeContext &runtime_context = graph.getRuntimeContext();
87 OMRuntimeStorage &runtime_storage = graph.getRuntimeStorage();
88 memory::OMRuntimeAllocator &runtime_allocator = graph.getRuntimeAllocator();
89
90 runtime_context.setModel(model_ptr, i);
91
92 // Parse and validate WOF file if it is exist
93 // WARNING: setWofFile method of RuntimeContext should follow after setModel.
94 if (config.wof_ptr != nullptr)
95 runtime_context.setWofFile(config.wof_ptr);
96
97 // Parse and validate Train Config File if it is exists
98 // WARNING: setTrainConfigFile method of RuntimeContext should follow after setModel.
99 if (config.train_mode and config.training_context.training_config_info_data != nullptr)
100 runtime_context.setTrainConfigFile(config.training_context.training_config_info_data);
101
102 // Third - optimize it until can
103 status = optimize::OMOptimizer::optimize(runtime_storage, runtime_context, config);
104 if (status != Ok)
105 return status;
106
107 // 4 - AllocDeallocPlan creation
108 if (not config.train_mode)
109 {
110 // Non trainable mode
111 status = import::OMExecutionPlanCreator::createExecutionPlan(runtime_storage, runtime_context,
112 runtime_allocator, config);
113 }
114 else
115 {
116 // Trainable mode
118 runtime_storage, runtime_context, runtime_allocator, config);
119 }
120 if (status != Ok)
121 return status;
122 }
123 for (uint32_t i = 0; i < num_subgraph; ++i)
124 {
125 // Second - load default graph
127
128 OMRuntimeContext &runtime_context = graph.getRuntimeContext();
129 OMRuntimeStorage &runtime_storage = graph.getRuntimeStorage();
130 memory::OMRuntimeAllocator &runtime_allocator = graph.getRuntimeAllocator();
131 // 5 - KernelConfigure
132 import::OMConfigureArgs configure_args = {runtime_storage, runtime_context, 0, config, *this};
133
135 if (status != Ok)
136 return status;
137 }
138 // Done!
139
140 return Ok;
141}
OMStatus setTrainConfigFile(char *train_config_file_ptr)
OMStatus setModel(const char *model_ptr, uint32_t graph_index)
Loads Circle file and provides helpers to access attributes.
OMStatus parse(const char *model_ptr)
static OMStatus createExecutionPlan(core::OMRuntimeStorage &runtime_storage, core::OMRuntimeContext &runtime_context, core::memory::OMRuntimeAllocator &allocator, const OMConfig &configs)
static OMStatus createForwardExecutionPlan(core::OMRuntimeStorage &runtime_storage, core::OMRuntimeContext &runtime_context, core::memory::OMRuntimeAllocator &allocator, const OMConfig &configs)
static OMStatus configureKernels(OMConfigureArgs &)
static OMStatus optimize(core::OMRuntimeStorage &storage, core::OMRuntimeContext &context, const OMConfig &configs)

References _graphs, onert_micro::import::OMKernelConfiguration::configureKernels(), onert_micro::import::OMExecutionPlanCreator::createExecutionPlan(), onert_micro::import::OMExecutionPlanCreator::createForwardExecutionPlan(), onert_micro::core::reader::OMCircleReader::num_subgraph(), onert_micro::Ok, onert_micro::optimize::OMOptimizer::optimize(), onert_micro::core::reader::OMCircleReader::parse(), onert_micro::core::OMRuntimeContext::setModel(), onert_micro::core::OMRuntimeContext::setTrainConfigFile(), onert_micro::core::OMRuntimeContext::setWofFile(), and onert_micro::UnknownError.

Referenced by onert_micro::OMInterpreter::importModel(), and onert_micro::core::OMTrainingRuntimeModule::importTrainModel().

◆ operator=() [1/2]

OMRuntimeModule && onert_micro::core::OMRuntimeModule::operator= ( const OMRuntimeModule &&  )
delete

◆ operator=() [2/2]

OMRuntimeModule & onert_micro::core::OMRuntimeModule::operator= ( const OMRuntimeModule )
delete

◆ reset()

OMStatus OMRuntimeModule::reset ( )

Definition at line 174 of file OMRuntimeModule.cpp.

175{
176 OMStatus status = Ok;
177
178 if (_graphs.empty())
179 return ModelNotImport;
180
181 for (auto &graph : _graphs)
182 {
183 graph.reset();
184 }
185
186 return status;
187}

References _graphs, onert_micro::ModelNotImport, and onert_micro::Ok.

Referenced by onert_micro::OMInterpreter::reset().

◆ run()

OMStatus OMRuntimeModule::run ( const OMConfig config)

Definition at line 151 of file OMRuntimeModule.cpp.

152{
153 OMStatus status = Ok;
154
155 if (_graphs.empty())
156 return ModelNotImport;
157
158 core::OMRuntimeGraph &main_graph = _graphs.at(0);
159
160 execute::OMExecuteArgs execute_args = {main_graph.getRuntimeStorage(),
161 main_graph.getRuntimeContext(),
162 0,
163 *this,
164 config.training_context.num_of_train_layers,
165 config.train_mode};
166
167 status = execute::OMKernelExecute::runForward(execute_args, main_graph.getRuntimeAllocator());
168 if (status != Ok)
169 return status;
170
171 return status;
172}
memory::OMRuntimeAllocator & getRuntimeAllocator()
OMRuntimeContext & getRuntimeContext()
OMRuntimeStorage & getRuntimeStorage()
static OMStatus runForward(OMExecuteArgs &, core::memory::OMRuntimeAllocator &allocator)

References _graphs, onert_micro::core::OMRuntimeGraph::getRuntimeAllocator(), onert_micro::core::OMRuntimeGraph::getRuntimeContext(), onert_micro::core::OMRuntimeGraph::getRuntimeStorage(), onert_micro::ModelNotImport, onert_micro::Ok, and onert_micro::execute::OMKernelExecute::runForward().

Referenced by onert_micro::core::OMTrainingRuntimeModule::evaluateMetric(), package.infer.session::inference(), onert_micro::OMInterpreter::run(), onert_micro::OMTrainingInterpreter::run(), and onert_micro::core::OMTrainingRuntimeModule::trainSingleStep().

Field Documentation

◆ _graphs


The documentation for this class was generated from the following files: