ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::ir::NNPkg Class Reference

#include <NNPkg.h>

Public Member Functions

 NNPkg ()=default
 
 NNPkg (const NNPkg &obj)=default
 
 NNPkg (NNPkg &&)=default
 
NNPkgoperator= (const NNPkg &)=default
 
NNPkgoperator= (NNPkg &&)=default
 
 ~NNPkg ()=default
 
 NNPkg (std::shared_ptr< Model > model)
 
std::shared_ptr< Modelprimary_model () const
 
void push (ModelIndex index, const std::shared_ptr< Model > &model)
 Put model at index.
 
size_t model_count () const
 Get the count of model.
 
const std::shared_ptr< Model > & model (const ModelIndex &index) const
 Get model at index.
 
std::shared_ptr< Model > & model (const ModelIndex &index)
 Get model at index.
 
const IODescinput (const ir::IOIndex &index) const
 Get pkg_input at index.
 
IODescinput (const ir::IOIndex &index)
 Get pkg_input at index.
 
void addInput (const IODesc &input)
 Add input at the end.
 
const IODescoutput (const ir::IOIndex &index) const
 Get pkg_output at index.
 
IODescoutput (const ir::IOIndex &index)
 Get pkg_output at index.
 
void addOutput (const IODesc &output)
 Add output at the end.
 
void addEdge (const IODesc &from, const IODesc &to)
 Add edge between models at the end.
 
const ModelEdgesmodel_edges ()
 Get model edge set.
 
void verify (void)
 Verify NNPkg.
 
uint32_t inputSize () const
 Get model input size.
 
uint32_t inputSize (SubgraphIndex subg_index) const
 
uint32_t outputSize () const
 Get model output size.
 
uint32_t outputSize (SubgraphIndex subg_index) const
 
const OperandInfoinputInfo (const ir::IOIndex &index) const
 Get model input info.
 
const OperandInfoinputInfo (SubgraphIndex subg_index, uint32_t index) const
 
const OperandInfooutputInfo (const ir::IOIndex &index) const
 Get model output info.
 
const OperandInfooutputInfo (SubgraphIndex subg_index, uint32_t index) const
 
void changeInputShape (const ir::IOIndex &index, const ir::Shape &new_shape)
 
void changeInputShape (SubgraphIndex subg_index, uint32_t index, const ir::Shape &new_shape)
 
void replaceModel (std::shared_ptr< Model > model)
 Replace model.
 

Detailed Description

Definition at line 83 of file NNPkg.h.

Constructor & Destructor Documentation

◆ NNPkg() [1/4]

onert::ir::NNPkg::NNPkg ( )
default

◆ NNPkg() [2/4]

onert::ir::NNPkg::NNPkg ( const NNPkg obj)
default

◆ NNPkg() [3/4]

onert::ir::NNPkg::NNPkg ( NNPkg &&  )
default

◆ ~NNPkg()

onert::ir::NNPkg::~NNPkg ( )
default

◆ NNPkg() [4/4]

onert::ir::NNPkg::NNPkg ( std::shared_ptr< Model model)
inline

Definition at line 93 of file NNPkg.h.

94 {
95 _models[ModelIndex{0}] = model;
96
97 // Fill pkg_inputs and pkg_outputs with primary model's inputs and outputs
98 for (uint32_t i = 0; i < model->primary_subgraph()->getInputs().size(); i++)
99 _edges.pkg_inputs.emplace_back(0, 0, IOIndex{i});
100 for (uint32_t i = 0; i < model->primary_subgraph()->getOutputs().size(); i++)
101 _edges.pkg_outputs.emplace_back(0, 0, IOIndex{i});
102 }
const std::shared_ptr< Model > & model(const ModelIndex &index) const
Get model at index.
Definition NNPkg.h:126
::onert::util::Index< uint32_t, IOIndexTag > IOIndex
Definition Index.h:36
::onert::util::Index< uint16_t, ModelIndexTag > ModelIndex
Definition Index.h:42
int32_t size[5]
Definition Slice.cpp:35
std::vector< ir::IODesc > pkg_outputs
Definition NNPkg.h:79
std::vector< ir::IODesc > pkg_inputs
Definition NNPkg.h:78

References model(), onert::ir::ModelEdges::pkg_inputs, onert::ir::ModelEdges::pkg_outputs, and size.

Member Function Documentation

◆ addEdge()

void onert::ir::NNPkg::addEdge ( const IODesc from,
const IODesc to 
)
inline

Add edge between models at the end.

Parameters
[in]fromfrom IODesc
[in]toto IODesc

Definition at line 183 of file NNPkg.h.

184 {
185 std::cout << from << " -> " << to << std::endl;
186 _edges.edges.insert(ModelEdge{from, to});
187 }
ModelEdgeSet edges
Definition NNPkg.h:80

References onert::ir::ModelEdges::edges.

◆ addInput()

void onert::ir::NNPkg::addInput ( const IODesc input)
inline

Add input at the end.

Parameters
[in]inputInput IODesc to be pushed

Definition at line 154 of file NNPkg.h.

154{ _edges.pkg_inputs.push_back(input); }
const IODesc & input(const ir::IOIndex &index) const
Get pkg_input at index.
Definition NNPkg.h:141

References input(), and onert::ir::ModelEdges::pkg_inputs.

◆ addOutput()

void onert::ir::NNPkg::addOutput ( const IODesc output)
inline

Add output at the end.

Parameters
[in]outputOutput IODesc to be pushed

Definition at line 175 of file NNPkg.h.

175{ _edges.pkg_outputs.push_back(output); }
const IODesc & output(const ir::IOIndex &index) const
Get pkg_output at index.
Definition NNPkg.h:162

References output(), and onert::ir::ModelEdges::pkg_outputs.

◆ changeInputShape() [1/2]

void onert::ir::NNPkg::changeInputShape ( const ir::IOIndex index,
const ir::Shape new_shape 
)
inline

Definition at line 314 of file NNPkg.h.

315 {
316 if (_models.size() == 1)
317 {
318 auto graph = primary_model()->primary_subgraph();
319 auto const operand_index = graph->getInputs().at(index);
320 graph->changeShape(operand_index, new_shape);
321 return;
322 }
323
324 auto const &desc = input(index);
325 auto graph = model(std::get<ModelIndex>(desc))->primary_subgraph();
326 auto const operand_index = graph->getInputs().at(std::get<IOIndex>(desc).value());
327 graph->changeShape(operand_index, new_shape);
328 }
std::shared_ptr< Model > primary_model() const
Definition NNPkg.h:103

References input(), model(), and primary_model().

◆ changeInputShape() [2/2]

void onert::ir::NNPkg::changeInputShape ( SubgraphIndex  subg_index,
uint32_t  index,
const ir::Shape new_shape 
)
inline

Definition at line 330 of file NNPkg.h.

331 {
332 // signature entry is supported for single model only
333 assert(_models.size() == 1);
334
335 auto graph = primary_model()->at(subg_index);
336 auto const operand_index = graph->getInputs().at(index);
337 graph->changeShape(operand_index, new_shape);
338 return;
339 }

References primary_model().

◆ input() [1/2]

IODesc & onert::ir::NNPkg::input ( const ir::IOIndex index)
inline

Get pkg_input at index.

Parameters
[in]indexIndex of pkg_input to be returned
Returns
IODesc at index

Definition at line 148 of file NNPkg.h.

148{ return _edges.pkg_inputs[index.value()]; }
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References onert::ir::ModelEdges::pkg_inputs.

◆ input() [2/2]

const IODesc & onert::ir::NNPkg::input ( const ir::IOIndex index) const
inline

Get pkg_input at index.

Parameters
[in]indexIndex of pkg_input to be returned
Returns
IODesc at index

Definition at line 141 of file NNPkg.h.

141{ return _edges.pkg_inputs[index.value()]; }

References onert::ir::ModelEdges::pkg_inputs.

Referenced by addInput(), changeInputShape(), and inputInfo().

◆ inputInfo() [1/2]

const OperandInfo & onert::ir::NNPkg::inputInfo ( const ir::IOIndex index) const
inline

Get model input info.

Definition at line 260 of file NNPkg.h.

261 {
262 if (_models.size() == 1)
263 {
264 auto const graph = primary_model()->primary_subgraph();
265 auto const operand_index = graph->getInputs().at(index);
266 return graph->operands().at(operand_index).info();
267 }
268
269 auto const &desc = input(index);
270 auto const graph = model(std::get<ModelIndex>(desc))->primary_subgraph();
271 auto const operand_index = graph->getInputs().at(std::get<IOIndex>(desc).value());
272 return graph->operands().at(operand_index).info();
273 }

References input(), model(), and primary_model().

◆ inputInfo() [2/2]

const OperandInfo & onert::ir::NNPkg::inputInfo ( SubgraphIndex  subg_index,
uint32_t  index 
) const
inline

Definition at line 275 of file NNPkg.h.

276 {
277 // signature entry is supported for single model only
278 assert(_models.size() == 1);
279
280 auto const graph = primary_model()->at(subg_index);
281 auto const operand_index = graph->getInputs().at(index);
282 return graph->operands().at(operand_index).info();
283 }

References primary_model().

◆ inputSize() [1/2]

uint32_t onert::ir::NNPkg::inputSize ( ) const
inline

Get model input size.

Definition at line 228 of file NNPkg.h.

229 {
230 return _models.size() == 1 ? primary_model()->primary_subgraph()->getInputs().size()
231 : _edges.pkg_inputs.size();
232 }

References onert::ir::ModelEdges::pkg_inputs, and primary_model().

◆ inputSize() [2/2]

uint32_t onert::ir::NNPkg::inputSize ( SubgraphIndex  subg_index) const
inline

Definition at line 234 of file NNPkg.h.

235 {
236 // signature entry is supported for single model only
237 assert(_models.size() == 1);
238 return primary_model()->at(subg_index)->getInputs().size();
239 }

References primary_model().

◆ model() [1/2]

std::shared_ptr< Model > & onert::ir::NNPkg::model ( const ModelIndex index)
inline

Get model at index.

Parameters
[in]indexIndex of the model to be returned
Returns
Model at index

Definition at line 133 of file NNPkg.h.

133{ return _models.at(index); }

◆ model() [2/2]

const std::shared_ptr< Model > & onert::ir::NNPkg::model ( const ModelIndex index) const
inline

Get model at index.

Parameters
[in]indexIndex of the model to be returned
Returns
Model at index

Definition at line 126 of file NNPkg.h.

126{ return _models.at(index); }

Referenced by changeInputShape(), inputInfo(), NNPkg(), outputInfo(), push(), and replaceModel().

◆ model_count()

size_t onert::ir::NNPkg::model_count ( ) const
inline

Get the count of model.

Returns
the count of models

Definition at line 118 of file NNPkg.h.

118{ return _models.size(); }

◆ model_edges()

const ModelEdges & onert::ir::NNPkg::model_edges ( )
inline

Get model edge set.

Returns
Edge set reference

Definition at line 192 of file NNPkg.h.

192{ return _edges; }

◆ operator=() [1/2]

NNPkg & onert::ir::NNPkg::operator= ( const NNPkg )
default

◆ operator=() [2/2]

NNPkg & onert::ir::NNPkg::operator= ( NNPkg &&  )
default

◆ output() [1/2]

IODesc & onert::ir::NNPkg::output ( const ir::IOIndex index)
inline

Get pkg_output at index.

Parameters
[in]indexIndex of pkg_output to be returned
Returns
IODesc at index

Definition at line 169 of file NNPkg.h.

169{ return _edges.pkg_outputs[index.value()]; }

References onert::ir::ModelEdges::pkg_outputs.

◆ output() [2/2]

const IODesc & onert::ir::NNPkg::output ( const ir::IOIndex index) const
inline

Get pkg_output at index.

Parameters
[in]indexIndex of pkg_output to be returned
Returns
IODesc at index

Definition at line 162 of file NNPkg.h.

162{ return _edges.pkg_outputs[index.value()]; }

References onert::ir::ModelEdges::pkg_outputs.

Referenced by addOutput(), and outputInfo().

◆ outputInfo() [1/2]

const OperandInfo & onert::ir::NNPkg::outputInfo ( const ir::IOIndex index) const
inline

Get model output info.

Definition at line 288 of file NNPkg.h.

289 {
290 if (_models.size() == 1)
291 {
292 auto const graph = primary_model()->primary_subgraph();
293 auto const operand_index = graph->getOutputs().at(index);
294 return graph->operands().at(operand_index).info();
295 }
296
297 auto const &desc = output(index);
298 auto const graph = model(std::get<ModelIndex>(desc))->primary_subgraph();
299 auto const operand_index = graph->getOutputs().at(std::get<IOIndex>(desc).value());
300 return graph->operands().at(operand_index).info();
301 }

References model(), output(), and primary_model().

◆ outputInfo() [2/2]

const OperandInfo & onert::ir::NNPkg::outputInfo ( SubgraphIndex  subg_index,
uint32_t  index 
) const
inline

Definition at line 303 of file NNPkg.h.

304 {
305 // signature entry is supported for single model only
306 assert(_models.size() == 1);
307
308 auto const graph = primary_model()->at(subg_index);
309
310 auto const operand_index = graph->getOutputs().at(index);
311 return graph->operands().at(operand_index).info();
312 }

References primary_model().

◆ outputSize() [1/2]

uint32_t onert::ir::NNPkg::outputSize ( ) const
inline

Get model output size.

Definition at line 244 of file NNPkg.h.

245 {
246 return _models.size() == 1 ? primary_model()->primary_subgraph()->getOutputs().size()
247 : _edges.pkg_outputs.size();
248 }

References onert::ir::ModelEdges::pkg_outputs, and primary_model().

◆ outputSize() [2/2]

uint32_t onert::ir::NNPkg::outputSize ( SubgraphIndex  subg_index) const
inline

Definition at line 250 of file NNPkg.h.

251 {
252 // signature entry is supported for single model only
253 assert(_models.size() == 1);
254 return primary_model()->at(subg_index)->getOutputs().size();
255 }

References primary_model().

◆ primary_model()

std::shared_ptr< Model > onert::ir::NNPkg::primary_model ( ) const
inline

◆ push()

void onert::ir::NNPkg::push ( ModelIndex  index,
const std::shared_ptr< Model > &  model 
)
inline

Put model at index.

Parameters
[in]modelModel to be pushed
[in]indexIndex where Model is to be pushed

Definition at line 111 of file NNPkg.h.

111{ _models[index] = model; }

References model().

◆ replaceModel()

void onert::ir::NNPkg::replaceModel ( std::shared_ptr< Model model)
inline

Replace model.

Parameters
[in]modelModel to be replaced

TODO: Support multiple models

Definition at line 348 of file NNPkg.h.

348{ _models[ModelIndex{0}] = model; }

References model().

◆ verify()

void onert::ir::NNPkg::verify ( void  )
inline

Verify NNPkg.

Definition at line 198 of file NNPkg.h.

199 {
200 // Verify edges information
201 //
202 // Only duplicates of nnpkg output and Edge `from` are possible.
203 // | Whether duplicates are possible | Edge `to` | Edge `from` |
204 // | nnpkg input (input of subgraph) | X (*1) | X (*2) |
205 // | nnpkg output (output of subgraph) | X (*2) | O |
206 // *1. The subjects who determine values of each buffer are different.
207 // - nnpkg input : user input
208 // - Edge `to` : output of another subgraph
209 // *2. `IOIndex` of inputs and outputs of subgraph is distinct.
210 //
211 for (const auto &edge : _edges.edges)
212 {
213 if (std::find(_edges.pkg_inputs.begin(), _edges.pkg_inputs.end(), edge.to) !=
214 _edges.pkg_inputs.end())
215 {
216 throw std::runtime_error{
217 "Invalid edge information. NNPkg inputs and Edge `to` cannot be duplicated"};
218 }
219 }
220 }

References onert::ir::ModelEdges::edges, and onert::ir::ModelEdges::pkg_inputs.


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