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

#include <StaticTensorManager.h>

Public Member Functions

 StaticTensorManager (const std::shared_ptr< TensorRegistry > &reg, DynamicTensorManager *dynamic_tensor_manager, const ir::OperandIndexMap< ir::OperandIndex > &shared_memory_operand_indexes)
 
 StaticTensorManager (const std::shared_ptr< TensorRegistry > &reg, const std::string planner_id, DynamicTensorManager *dynamic_tensor_manager, const ir::OperandIndexMap< ir::OperandIndex > &shared_memory_operand_indexes)
 
virtual ~StaticTensorManager ()=default
 
void allocateNonconsts (void)
 
void deallocateNonconsts (void)
 
void buildTensor (const ir::OperandIndex &ind, const ir::OperandInfo &tensor_info, bool as_const)
 
void claimPlan (const ir::OperandIndex &ind, uint32_t size)
 
void releasePlan (const ir::OperandIndex &ind)
 
void iterate (const std::function< void(const ir::OperandIndex &)> &fn)
 

Detailed Description

Definition at line 32 of file StaticTensorManager.h.

Constructor & Destructor Documentation

◆ StaticTensorManager() [1/2]

onert::backend::basic::StaticTensorManager::StaticTensorManager ( const std::shared_ptr< TensorRegistry > &  reg,
DynamicTensorManager dynamic_tensor_manager,
const ir::OperandIndexMap< ir::OperandIndex > &  shared_memory_operand_indexes 
)

Definition at line 28 of file StaticTensorManager.cc.

31 : _nonconst_mgr{new MemoryManager()}, _tensors{reg},
32 _dynamic_tensor_manager{dynamic_tensor_manager},
33 _shared_memory_operand_indexes{shared_memory_operand_indexes}
34{
35 // DO NOTHING
36}
SimpleMemoryManager MemoryManager

◆ StaticTensorManager() [2/2]

onert::backend::basic::StaticTensorManager::StaticTensorManager ( const std::shared_ptr< TensorRegistry > &  reg,
const std::string  planner_id,
DynamicTensorManager dynamic_tensor_manager,
const ir::OperandIndexMap< ir::OperandIndex > &  shared_memory_operand_indexes 
)

Definition at line 38 of file StaticTensorManager.cc.

42 : _nonconst_mgr{new MemoryManager(planner_id)}, _tensors{reg},
43 _dynamic_tensor_manager{dynamic_tensor_manager},
44 _shared_memory_operand_indexes{shared_memory_operand_indexes}
45{
46 // DO NOTHING
47}

◆ ~StaticTensorManager()

virtual onert::backend::basic::StaticTensorManager::~StaticTensorManager ( )
virtualdefault

Member Function Documentation

◆ allocateNonconsts()

void onert::backend::basic::StaticTensorManager::allocateNonconsts ( void  )

Definition at line 49 of file StaticTensorManager.cc.

50{
51 _nonconst_mgr->allocate();
52
53 for (auto &&[ind, tensor] : _tensors->native_tensors())
54 {
55 const auto adjusted_ind = adjustWithMemorySourceOperand(ind);
56 if (!_as_constants[adjusted_ind] && !tensor->is_dynamic())
57 {
58 auto *buffer = _nonconst_mgr->getBuffer(adjusted_ind);
59 tensor->setBuffer(buffer);
60
61 VERBOSE(CPU_StaticTensorManager)
62 << "TENSOR " << ind << " : " << static_cast<void *>(buffer) << std::endl;
63 }
64 }
65}
#define VERBOSE(name, lv)
Definition Log.h:71

References VERBOSE.

◆ buildTensor()

void onert::backend::basic::StaticTensorManager::buildTensor ( const ir::OperandIndex ind,
const ir::OperandInfo tensor_info,
bool  as_const 
)

Definition at line 69 of file StaticTensorManager.cc.

71{
72 assert(!_tensors->getNativeTensor(ind));
73 if (as_const)
74 {
75 auto tensor = std::make_unique<ExternalTensor>(tensor_info);
76 _tensors->setNativeTensor(ind, std::move(tensor));
77 }
78 else
79 {
80 auto tensor =
81 std::make_unique<Tensor>(tensor_info, _dynamic_tensor_manager->dynamic_mem_mgr().get());
82 _tensors->setNativeTensor(ind, std::move(tensor));
83 }
84 _as_constants[ind] = as_const;
85}
std::shared_ptr< DynamicMemoryManager > dynamic_mem_mgr()

References onert::backend::basic::DynamicTensorManager::dynamic_mem_mgr().

◆ claimPlan()

void onert::backend::basic::StaticTensorManager::claimPlan ( const ir::OperandIndex ind,
uint32_t  size 
)

Definition at line 87 of file StaticTensorManager.cc.

88{
89 assert(_tensors->getNativeTensor(ind));
90
91 // This method is called only when a tensor has proper shape
92 assert(!_tensors->getNativeTensor(ind)->is_dynamic());
93
94 const auto claim_ind = adjustWithMemorySourceOperand(ind);
95 if (_as_constants[claim_ind])
96 {
97 return;
98 }
99 if (isSharedMemoryOperand(claim_ind))
100 {
101 ++_source_operand_inds_ref_counter[claim_ind];
102 if (_source_operand_inds_ref_counter[claim_ind] > 1)
103 {
104 return; // claimPlan should be called only for the first usage
105 }
106 }
107 _nonconst_mgr->claimPlan(claim_ind, size);
108}
int32_t size[5]
Definition Slice.cpp:35

References size.

◆ deallocateNonconsts()

void onert::backend::basic::StaticTensorManager::deallocateNonconsts ( void  )

Definition at line 67 of file StaticTensorManager.cc.

67{ _nonconst_mgr->deallocate(); }

◆ iterate()

void onert::backend::basic::StaticTensorManager::iterate ( const std::function< void(const ir::OperandIndex &)> &  fn)

Definition at line 136 of file StaticTensorManager.cc.

137{
138 for (const auto &it : _tensors->native_tensors())
139 fn(it.first);
140}

◆ releasePlan()

void onert::backend::basic::StaticTensorManager::releasePlan ( const ir::OperandIndex ind)

Definition at line 110 of file StaticTensorManager.cc.

111{
112 assert(_tensors->getNativeTensor(ind));
113
114 // This method is called only when a tensor has proper shape
115 assert(!_tensors->getNativeTensor(ind)->is_dynamic());
116
117 const auto release_ind = adjustWithMemorySourceOperand(ind);
118 if (_as_constants[release_ind])
119 {
120 return;
121 }
122 if (isSharedMemoryOperand(release_ind))
123 {
124 if (_source_operand_inds_ref_counter[release_ind] > 0) // sanity check
125 {
126 --_source_operand_inds_ref_counter[release_ind];
127 }
128 if (_source_operand_inds_ref_counter[release_ind] > 0)
129 {
130 return; // releasePlan should be called only for the first usage
131 }
132 }
133 _nonconst_mgr->releasePlan(release_ind);
134}

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