ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::util::ObjectManager< Index, Object > Class Template Reference

Class that owns objects and maps them with indices as a handle for them. More...

#include <ObjectManager.h>

Public Member Functions

 ObjectManager ()
 
template<class... Args>
Index emplace (Args &&...args)
 Create an object with args and put it in the container with a newly assigned Index.
 
Index push (std::unique_ptr< Object > &&object, Index index)
 Put the object in the container with given index.
 
Index push (std::unique_ptr< Object > &&object)
 Put the object in the container with a newly assigned index.
 
Index set (Index index, std::unique_ptr< Object > &&object)
 Set the object in the container with given index.
 
void remove (const Index &index)
 Remove the object that is associated with the given index.
 
const Objectat (const Index &index) const
 Get the object that is associated with the given index.
 
Objectat (const Index &index)
 Get the object that is associated with the given index.
 
const ObjectgetRawPtr (const Index &index) const
 Get the object that is associated with the given index.
 
ObjectgetRawPtr (const Index &index)
 Get the object that is associated with the given index.
 
bool exist (const Index &index) const
 Get the object that is associated with the given index.
 
size_t size () const
 Return the number of objects that the manager contains.
 
void iterate (const std::function< void(const Index &, const Object &)> &fn) const
 Iterate over the container with given function.
 
void iterate (const std::function< void(const Index &, Object &)> &fn)
 Iterate over the container with given function.
 

Protected Attributes

std::unordered_map< Index, std::unique_ptr< Object > > _objects
 
uint32_t _next_index
 

Detailed Description

template<typename Index, typename Object>
class onert::util::ObjectManager< Index, Object >

Class that owns objects and maps them with indices as a handle for them.

Definition at line 37 of file ObjectManager.h.

Constructor & Destructor Documentation

◆ ObjectManager()

template<typename Index , typename Object >
onert::util::ObjectManager< Index, Object >::ObjectManager ( )
inline

Definition at line 40 of file ObjectManager.h.

Member Function Documentation

◆ at() [1/2]

template<typename Index , typename Object >
Object & onert::util::ObjectManager< Index, Object >::at ( const Index index)
inline

Get the object that is associated with the given index.

If such object does not exist, it will throw std::out_of_range

Parameters
[in]indexIndex of the object to be returned
Returns
Object

Definition at line 130 of file ObjectManager.h.

130{ return *(_objects.at(index)); }
std::unordered_map< Index, std::unique_ptr< Object > > _objects

References onert::util::ObjectManager< Index, Object >::_objects.

◆ at() [2/2]

template<typename Index , typename Object >
const Object & onert::util::ObjectManager< Index, Object >::at ( const Index index) const
inline

Get the object that is associated with the given index.

If such object does not exist, it will throw std::out_of_range

Parameters
[in]indexIndex of the object to be returned
Returns
Object

Definition at line 121 of file ObjectManager.h.

121{ return *(_objects.at(index)); }

References onert::util::ObjectManager< Index, Object >::_objects.

Referenced by onert::ir::train::TrainableGraph::btopolSortOperations(), onert::exec::DataflowExecutor::calculateRank(), onert::compiler::pass::ConstantOutputPass::callback(), onert::compiler::pass::PermutationInsertionPass::callback(), onert::compiler::pass::ConstantInsertionPass::callback(), onert::compiler::pass::ConstantLoweringPass::callback(), onert::compiler::train::pass::TrainableConstantInsertionPass::callback(), onert::ir::train::TrainableGraph::changeBackwardShape(), onert::ir::Graph::changeShape(), onert::backend::acl_common::AclConstantInitializer::copyInputInitialize(), onert::ir::train::TrainableGraph::disableBackward(), onert::ir::train::TrainableGraph::enableBackward(), onert::backend::acl_cl::KernelGenerator::generate(), onert::backend::acl_neon::KernelGenerator::generate(), onert::backend::ruy::KernelGenerator::generate(), onert::backend::builtin::KernelGenerator::generate(), onert::backend::trix::KernelGenerator::generate(), onert::exec::TracingObserver::handleJobBegin(), onert::exec::ProfileObserver::handleJobEnd(), onert::exec::TracingObserver::handleJobEnd(), onert::exec::MinMaxRecorder::handleJobEnd(), onert::compiler::StaticShapeInferer::infer(), onert::backend::cl_common::BackendContext< T_TensorBuilder, T_ConstantInitializer, T_KernelGenerator >::initConsts(), onert::backend::basic::initConsts(), onert::backend::basic::initSharedMemoryConsts(), onert::backend::acl_common::kernelGenFullyConnected(), onert::backend::acl_common::kernelGenLSTM(), onert::backend::acl_common::kernelGenPool2D(), onert::loader::BaseLoader< LoaderDomain >::loadOperand(), onert::ir::train::TrainableGraph::operation(), onert::backend::train::TensorPlanner::planBackPropTensors(), onert::backend::train::TensorPlanner::planGradientTensors(), onert::backend::train::TensorPlanner::planNonConstTensors(), onert::backend::cl_common::BackendContext< T_TensorBuilder, T_ConstantInitializer, T_KernelGenerator >::planTensors(), onert::ir::Graph::replaceOperation(), onert::backend::acl_common::AclConstantInitializer::run(), onert::compiler::train::pass::LossInsertionPass::run(), onert::compiler::pass::OddOutputPass::run(), onert::ir::Graph::setOperandValue(), onert::ir::Graph::topolSortOperations(), onert::ir::train::TrainableGraph::truncateBackwardOrder(), onert::backend::acl_common::AclConstantInitializer::visit(), onert::backend::acl_common::AclSubTensorAnalyzer::visit(), onert::backend::acl_cl::ConstantInitializer::visit(), onert::backend::acl_cl::ConstantInitializer::visit(), onert::backend::acl_neon::ConstantInitializer::visit(), onert::backend::train::KernelGenerator::visit(), onert::backend::train::KernelGenerator::visit(), onert::backend::train::KernelGenerator::visit(), onert::ir::OperationValidator::visit(), onert::ir::OperationValidator::visit(), and onert::ir::train::UseDefGenerator::visit().

◆ emplace()

template<typename Index , typename Object >
template<class... Args>
Index onert::util::ObjectManager< Index, Object >::emplace ( Args &&...  args)
inline

Create an object with args and put it in the container with a newly assigned Index.

Parameters
[in]argsArguments for creating Operand object
Returns
Created index that is associated to the object if successful, Undefined index otherwise

Definition at line 49 of file ObjectManager.h.

50 {
51 auto index = generateIndex();
52 if (!index.valid())
53 return index;
54 _objects.emplace(index, std::make_unique<Object>(std::forward<Args>(args)...));
55 return index;
56 }
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References onert::util::ObjectManager< Index, Object >::_objects.

Referenced by onert::ir::Graph::addOperand(), and onert::compiler::pass::ConstantInsertionPass::callback().

◆ exist()

template<typename Index , typename Object >
bool onert::util::ObjectManager< Index, Object >::exist ( const Index index) const
inline

Get the object that is associated with the given index.

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

Definition at line 169 of file ObjectManager.h.

170 {
171 auto it = _objects.find(index);
172 return it != _objects.end();
173 }

References onert::util::ObjectManager< Index, Object >::_objects.

Referenced by onert::ir::train::TrainableGraph::changeBackwardShape(), onert::ir::Graph::changeShape(), onert::ir::Graph::replaceOperation(), and onert::ir::Graph::setOperandValue().

◆ getRawPtr() [1/2]

template<typename Index , typename Object >
Object * onert::util::ObjectManager< Index, Object >::getRawPtr ( const Index index)
inline

Get the object that is associated with the given index.

If such object does not exist, it will return nullptr

Parameters
[in]indexIndex of the object to be returned
Returns
Object The found object

Definition at line 158 of file ObjectManager.h.

159 {
160 return const_cast<Object *>(
161 const_cast<const ObjectManager<Index, Object> *>(this)->getRawPtr(index));
162 }
const Object * getRawPtr(const Index &index) const
Get the object that is associated with the given index.

References onert::util::ObjectManager< Index, Object >::getRawPtr().

◆ getRawPtr() [2/2]

template<typename Index , typename Object >
const Object * onert::util::ObjectManager< Index, Object >::getRawPtr ( const Index index) const
inline

Get the object that is associated with the given index.

If such object does not exist, it will return nullptr

Parameters
[in]indexIndex of the object to be returned
Returns
Object

Definition at line 139 of file ObjectManager.h.

140 {
141 auto itr = _objects.find(index);
142 if (itr == _objects.end())
143 return nullptr;
144 else
145 {
146 assert(itr->second != nullptr);
147 return itr->second.get();
148 }
149 }

References onert::util::ObjectManager< Index, Object >::_objects.

Referenced by onert::util::ObjectManager< Index, Object >::getRawPtr().

◆ iterate() [1/2]

template<typename Index , typename Object >
void onert::util::ObjectManager< Index, Object >::iterate ( const std::function< void(const Index &, const Object &)> &  fn) const
inline

◆ iterate() [2/2]

template<typename Index , typename Object >
void onert::util::ObjectManager< Index, Object >::iterate ( const std::function< void(const Index &, Object &)> &  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 199 of file ObjectManager.h.

200 {
201 // TODO Remove this workaround
202 // This implementation is a workaround in case of adding operands while iteration
203 std::list<Index> l;
204
205 for (const auto &e : _objects)
206 {
207 l.push_back(e.first);
208 }
209
210 for (const auto &index : l)
211 {
212 fn(index, *_objects[index]);
213 }
214 }

References onert::util::ObjectManager< Index, Object >::_objects.

◆ push() [1/2]

template<typename Index , typename Object >
Index onert::util::ObjectManager< Index, Object >::push ( std::unique_ptr< Object > &&  object)
inline

Put the object in the container with a newly assigned index.

It fails when it cannot generate a valid index.

Parameters
[in]objectObject to be pushed
Returns
The newly assigned index if successful, an Undefined index otherwise

Definition at line 82 of file ObjectManager.h.

83 {
84 auto gen_index = generateIndex();
85 if (gen_index.valid())
86 _objects.emplace(gen_index, std::move(object));
87 return gen_index;
88 }

References onert::util::ObjectManager< Index, Object >::_objects.

◆ push() [2/2]

template<typename Index , typename Object >
Index onert::util::ObjectManager< Index, Object >::push ( std::unique_ptr< Object > &&  object,
Index  index 
)
inline

Put the object in the container with given index.

It fails when the given index is already taken or index is Undefined.

Parameters
[in]objectObject to be pushed
[in]indexIndex associated with the object
Returns
index if successful, an Undefined index otherwise

Definition at line 67 of file ObjectManager.h.

68 {
69 auto gen_index = tryIndex(index);
70 if (gen_index.valid())
71 _objects.emplace(gen_index, std::move(object));
72 return gen_index;
73 }

References onert::util::ObjectManager< Index, Object >::_objects.

Referenced by onert::ir::train::TrainableGraph::addBackwardOperand(), onert::ir::Graph::addOperand(), onert::ir::Graph::addOperation(), onert::ir::Graph::addOperation(), and onert::compiler::pass::ConstantOutputPass::callback().

◆ remove()

template<typename Index , typename Object >
void onert::util::ObjectManager< Index, Object >::remove ( const Index index)
inline

Remove the object that is associated with the given index.

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

Definition at line 111 of file ObjectManager.h.

111{ _objects.erase(index); }

References onert::util::ObjectManager< Index, Object >::_objects.

Referenced by onert::ir::Graph::removeOperand(), and onert::compiler::pass::UnusedOperandEliminationPass::run().

◆ set()

template<typename Index , typename Object >
Index onert::util::ObjectManager< Index, Object >::set ( Index  index,
std::unique_ptr< Object > &&  object 
)
inline

Set the object in the container with given index.

If the index is Undefined, it will fail. If the index is already taken, it will overwrite the content.

Parameters
[in]objectObject to be pushed
[in]indexIndex associated with the object
Returns
index if successful, an Undefined index otherwise

Definition at line 99 of file ObjectManager.h.

100 {
101 if (index.valid())
102 _objects[index] = std::move(object);
103 return index;
104 }

References onert::util::ObjectManager< Index, Object >::_objects.

Referenced by onert::ir::Graph::replaceOperation().

◆ size()

template<typename Index , typename Object >
size_t onert::util::ObjectManager< Index, Object >::size ( ) const
inline

Return the number of objects that the manager contains.

Returns
size_t Number of objects

Definition at line 179 of file ObjectManager.h.

179{ return _objects.size(); }

References onert::util::ObjectManager< Index, Object >::_objects.

Referenced by nnfw_session::train_get_traininfo().

Field Documentation

◆ _next_index

template<typename Index , typename Object >
uint32_t onert::util::ObjectManager< Index, Object >::_next_index
protected

Definition at line 249 of file ObjectManager.h.

◆ _objects


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