ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::ir::Model Class Reference

#include <Model.h>

Public Member Functions

 Model ()=default
 
 Model (const Model &obj)=default
 
 Model (Model &&)=default
 
Modeloperator= (const Model &)=default
 
Modeloperator= (Model &&)=default
 
 ~Model ()=default
 
void push (SubgraphIndex index, const std::shared_ptr< IGraph > &subg)
 Put subgraph in the container with a new Index for that.
 
void remove (const SubgraphIndex &index)
 Remove the subgraph that is associated with the given index.
 
const std::shared_ptr< IGraph > & at (const SubgraphIndex &index) const
 Get the subgraph that is associated with the given index.
 
std::shared_ptr< IGraph > & at (const SubgraphIndex &index)
 Get the subgraph that is associated with the given index.
 
bool exist (const SubgraphIndex &index) const
 Get the subgraph that is associated with the given index.
 
void iterate (const std::function< void(const SubgraphIndex &, const IGraph &)> &fn) const
 Iterate over the container with given function.
 
void iterate (const std::function< void(const SubgraphIndex &, IGraph &)> &fn)
 Iterate over the container with given function.
 
size_t subgraphs_count () const
 Get count of Subgraphs.
 
std::shared_ptr< IGraphprimary_subgraph () const
 Return the primary subgraph.
 
template<typename Graph , std::enable_if_t< std::is_base_of_v< IGraph, Graph >, bool > = true>
bool hasOnly ()
 Return whether the model has only typename Graph.
 
void bindKernelBuilder (const std::shared_ptr< onert::backend::custom::IKernelBuilder > &kernel_builder)
 
const std::shared_ptr< backend::custom::IKernelBuilder > & getKernelBuilder () const
 
void add_metadata (const std::string &name, std::unique_ptr< const ir::Data > data)
 
bool exists_metadata (const std::string &name) const
 
std::unique_ptr< const ir::Dataextract_metadata (const std::string name)
 

Detailed Description

Definition at line 35 of file Model.h.

Constructor & Destructor Documentation

◆ Model() [1/3]

onert::ir::Model::Model ( )
default

◆ Model() [2/3]

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

◆ Model() [3/3]

onert::ir::Model::Model ( Model &&  )
default

◆ ~Model()

onert::ir::Model::~Model ( )
default

Member Function Documentation

◆ add_metadata()

void onert::ir::Model::add_metadata ( const std::string &  name,
std::unique_ptr< const ir::Data data 
)
inline

Definition at line 172 of file Model.h.

173 {
174 _metadatas.emplace(name, std::move(data));
175 }

◆ at() [1/2]

std::shared_ptr< IGraph > & onert::ir::Model::at ( const SubgraphIndex index)
inline

Get the subgraph that is associated with the given index.

Parameters
[in]indexIndex of the subgraph to be returned
Returns
IGraph

Definition at line 78 of file Model.h.

78{ return _subgraphs.at(index); }

◆ at() [2/2]

const std::shared_ptr< IGraph > & onert::ir::Model::at ( const SubgraphIndex index) const
inline

Get the subgraph that is associated with the given index.

Parameters
[in]indexIndex of the subgraph to be returned
Returns
IGraph

Definition at line 68 of file Model.h.

69 {
70 return _subgraphs.at(index);
71 }

◆ bindKernelBuilder()

void onert::ir::Model::bindKernelBuilder ( const std::shared_ptr< onert::backend::custom::IKernelBuilder > &  kernel_builder)
inline

Definition at line 158 of file Model.h.

159 {
160 _kernel_builder = kernel_builder;
161 }

◆ exist()

bool onert::ir::Model::exist ( const SubgraphIndex index) const
inline

Get the subgraph that is associated with the given index.

Parameters
[in]indexIndex of the subgraph to be returned
Returns
true if such entry exists otherwise false

Definition at line 86 of file Model.h.

87 {
88 auto it = _subgraphs.find(index);
89 return it != _subgraphs.end();
90 }

◆ exists_metadata()

bool onert::ir::Model::exists_metadata ( const std::string &  name) const
inline

Definition at line 177 of file Model.h.

178 {
179 return _metadatas.find(name) != _metadatas.end();
180 }

◆ extract_metadata()

std::unique_ptr< const ir::Data > onert::ir::Model::extract_metadata ( const std::string  name)
inline

Definition at line 183 of file Model.h.

184 {
185 auto m = _metadatas.find(name);
186
187 if (m == _metadatas.end())
188 throw std::out_of_range{"no meatdata named " + name};
189
190 auto data = std::move(m->second);
191 _metadatas.erase(m);
192 return data;
193 }

References m.

◆ getKernelBuilder()

const std::shared_ptr< backend::custom::IKernelBuilder > & onert::ir::Model::getKernelBuilder ( ) const
inline

Definition at line 163 of file Model.h.

164 {
165 return _kernel_builder;
166 }

◆ hasOnly()

template<typename Graph , std::enable_if_t< std::is_base_of_v< IGraph, Graph >, bool > = true>
bool onert::ir::Model::hasOnly ( )
inline

Return whether the model has only typename Graph.

Template Parameters
GraphType that inherits from IGraph
Returns
true if the model has only typename Graph, otherwise false

Definition at line 142 of file Model.h.

143 {
144 for (const auto &e : _subgraphs)
145 {
146 if (std::dynamic_pointer_cast<Graph>(e.second) == nullptr)
147 return false;
148 }
149 return true;
150 }

◆ iterate() [1/2]

void onert::ir::Model::iterate ( const std::function< void(const SubgraphIndex &, const IGraph &)> &  fn) const
inline

Iterate over the container with given function.

Parameters
[in]fnFunction to be run for every container entry
Returns
N/A

Definition at line 98 of file Model.h.

99 {
100 for (const auto &[subg_idx, subg] : _subgraphs)
101 {
102 fn(subg_idx, *subg);
103 }
104 }

◆ iterate() [2/2]

void onert::ir::Model::iterate ( const std::function< void(const SubgraphIndex &, IGraph &)> &  fn)
inline

Iterate over the container with given function.

Parameters
[in]fnFunction to be run for every container entry
Returns
N/A

Definition at line 112 of file Model.h.

113 {
114 for (const auto &[subg_idx, subg] : _subgraphs)
115 {
116 fn(subg_idx, *subg);
117 }
118 }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ primary_subgraph()

std::shared_ptr< IGraph > onert::ir::Model::primary_subgraph ( ) const
inline

Return the primary subgraph.

Returns
std::shared_ptr<IGraph> Primary subgraph

Definition at line 132 of file Model.h.

132{ return _subgraphs.at(SubgraphIndex{0}); }
::onert::util::Index< uint16_t, SubgraphIndexTag > SubgraphIndex
Definition Index.h:39

◆ push()

void onert::ir::Model::push ( SubgraphIndex  index,
const std::shared_ptr< IGraph > &  subg 
)
inline

Put subgraph in the container with a new Index for that.

Parameters
[in]subgSubgraph to be pushed
[in]indexIndex of subgraph to be pushed
Returns
Created

Definition at line 52 of file Model.h.

52{ _subgraphs[index] = subg; }
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

◆ remove()

void onert::ir::Model::remove ( const SubgraphIndex index)
inline

Remove the subgraph that is associated with the given index.

Parameters
[in]indexIndex of the subgraph to be removed
Returns
N/A

Definition at line 60 of file Model.h.

60{ _subgraphs.erase(index); }

◆ subgraphs_count()

size_t onert::ir::Model::subgraphs_count ( ) const
inline

Get count of Subgraphs.

Returns
count of Subgraphs

Definition at line 125 of file Model.h.

125{ return _subgraphs.size(); }

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