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 (uint32_t index) const
 Get pkg_input at index.
 
IODescinput (uint32_t index)
 Get pkg_input at index.
 
void addInput (const IODesc &input)
 Add input at the end.
 
const IODescoutput (uint32_t index) const
 Get pkg_output at index.
 
IODescoutput (uint32_t 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 outputSize () const
 Get model output size.
 
const OperandInfoinputInfo (uint32_t index) const
 Get model input info.
 
const OperandInfooutputInfo (uint32_t index) const
 Get model output info.
 
void changeInputShape (uint32_t index, const ir::Shape &new_shape)
 
void replaceModel (std::shared_ptr< Model > model)
 Replace model.
 

Detailed Description

Definition at line 81 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 91 of file NNPkg.h.

91{ _models[ModelIndex{0}] = model; }
const std::shared_ptr< Model > & model(const ModelIndex &index) const
Get model at index.
Definition NNPkg.h:115
::onert::util::Index< uint16_t, ModelIndexTag > ModelIndex
Definition Index.h:44

References model().

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 172 of file NNPkg.h.

173 {
174 std::cout << from << " -> " << to << std::endl;
175 _edges.edges.insert(ModelEdge{from, to});
176 }
ModelEdgeSet edges
Definition NNPkg.h:78

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 143 of file NNPkg.h.

143{ _edges.pkg_inputs.push_back(input); }
const IODesc & input(uint32_t index) const
Get pkg_input at index.
Definition NNPkg.h:130
std::vector< ir::IODesc > pkg_inputs
Definition NNPkg.h:76

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 164 of file NNPkg.h.

164{ _edges.pkg_outputs.push_back(output); }
const IODesc & output(uint32_t index) const
Get pkg_output at index.
Definition NNPkg.h:151
std::vector< ir::IODesc > pkg_outputs
Definition NNPkg.h:77

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

◆ changeInputShape()

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

Definition at line 268 of file NNPkg.h.

269 {
270 if (_models.size() == 1)
271 {
272 auto graph = primary_model()->primary_subgraph();
273 auto const operand_index = graph->getInputs().at(index);
274 graph->changeShape(operand_index, new_shape);
275 return;
276 }
277
278 auto const &desc = input(index);
279 auto graph = model(std::get<ModelIndex>(desc))->primary_subgraph();
280 auto const operand_index = graph->getInputs().at(std::get<IOIndex>(desc).value());
281 graph->changeShape(operand_index, new_shape);
282 }
std::shared_ptr< Model > primary_model() const
Definition NNPkg.h:92

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

◆ input() [1/2]

IODesc & onert::ir::NNPkg::input ( uint32_t  index)
inline

Get pkg_input at index.

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

Definition at line 137 of file NNPkg.h.

137{ return _edges.pkg_inputs[index]; }
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 ( uint32_t  index) const
inline

Get pkg_input at index.

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

Definition at line 130 of file NNPkg.h.

130{ return _edges.pkg_inputs[index]; }

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

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

◆ inputInfo()

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

Get model input info.

Definition at line 235 of file NNPkg.h.

236 {
237 if (_models.size() == 1)
238 {
239 auto const graph = primary_model()->primary_subgraph();
240 auto const operand_index = graph->getInputs().at(index);
241 return graph->operands().at(operand_index).info();
242 }
243
244 auto const &desc = input(index);
245 auto const graph = model(std::get<ModelIndex>(desc))->primary_subgraph();
246 auto const operand_index = graph->getInputs().at(std::get<IOIndex>(desc).value());
247 return graph->operands().at(operand_index).info();
248 }

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

◆ inputSize()

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

Get model input size.

Definition at line 217 of file NNPkg.h.

218 {
219 return _models.size() == 1 ? primary_model()->primary_subgraph()->getInputs().size()
220 : _edges.pkg_inputs.size();
221 }

References onert::ir::ModelEdges::pkg_inputs, and 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 122 of file NNPkg.h.

122{ 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 115 of file NNPkg.h.

115{ 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 107 of file NNPkg.h.

107{ return _models.size(); }

◆ model_edges()

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

Get model edge set.

Returns
Edge set reference

Definition at line 181 of file NNPkg.h.

181{ 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 ( uint32_t  index)
inline

Get pkg_output at index.

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

Definition at line 158 of file NNPkg.h.

158{ return _edges.pkg_outputs[index]; }

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

◆ output() [2/2]

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

Get pkg_output at index.

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

Definition at line 151 of file NNPkg.h.

151{ return _edges.pkg_outputs[index]; }

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

Referenced by addOutput(), and outputInfo().

◆ outputInfo()

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

Get model output info.

Definition at line 253 of file NNPkg.h.

254 {
255 if (_models.size() == 1)
256 {
257 auto const graph = primary_model()->primary_subgraph();
258 auto const operand_index = graph->getOutputs().at(index);
259 return graph->operands().at(operand_index).info();
260 }
261
262 auto const &desc = output(index);
263 auto const graph = model(std::get<ModelIndex>(desc))->primary_subgraph();
264 auto const operand_index = graph->getOutputs().at(std::get<IOIndex>(desc).value());
265 return graph->operands().at(operand_index).info();
266 }

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

◆ outputSize()

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

Get model output size.

Definition at line 226 of file NNPkg.h.

227 {
228 return _models.size() == 1 ? primary_model()->primary_subgraph()->getOutputs().size()
229 : _edges.pkg_outputs.size();
230 }

References onert::ir::ModelEdges::pkg_outputs, and 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 100 of file NNPkg.h.

100{ _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 291 of file NNPkg.h.

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

References model().

◆ verify()

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

Verify NNPkg.

Definition at line 187 of file NNPkg.h.

188 {
189 // Verify edges information
190 //
191 // Only duplicates of nnpkg output and Edge `from` are possible.
192 // | Whether duplicates are possible | Edge `to` | Edge `from` |
193 // | nnpkg input (input of subgraph) | X (*1) | X (*2) |
194 // | nnpkg output (output of subgraph) | X (*2) | O |
195 // *1. The subjects who determine values of each buffer are different.
196 // - nnpkg input : user input
197 // - Edge `to` : output of another subgraph
198 // *2. `IOIndex` of inputs and outputs of subgraph is distinct.
199 //
200 for (const auto &edge : _edges.edges)
201 {
202 if (std::find(_edges.pkg_inputs.begin(), _edges.pkg_inputs.end(), edge.to) !=
203 _edges.pkg_inputs.end())
204 {
205 throw std::runtime_error{
206 "Invalid edge information. NNPkg inputs and Edge `to` cannot be duplicated"};
207 }
208 }
209 }

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


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