ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 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.

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

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

175 {
176 std::cout << from << " -> " << to << std::endl;
177 _edges.edges.insert(ModelEdge{from, to});
178 }
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 145 of file NNPkg.h.

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

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

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

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

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

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

139{ 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 132 of file NNPkg.h.

132{ 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 237 of file NNPkg.h.

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

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

◆ inputSize()

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

Get model input size.

Definition at line 219 of file NNPkg.h.

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

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

124{ 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 117 of file NNPkg.h.

117{ 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 109 of file NNPkg.h.

109{ return _models.size(); }

◆ model_edges()

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

Get model edge set.

Returns
Edge set reference

Definition at line 183 of file NNPkg.h.

183{ 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 160 of file NNPkg.h.

160{ 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 153 of file NNPkg.h.

153{ 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 255 of file NNPkg.h.

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

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

◆ outputSize()

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

Get model output size.

Definition at line 228 of file NNPkg.h.

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

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

102{ _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 293 of file NNPkg.h.

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

References model().

◆ verify()

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

Verify NNPkg.

Definition at line 189 of file NNPkg.h.

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

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


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