ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 36 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 32 of file StaticTensorManager.cc.

35 : _nonconst_mgr{new MemoryManager()}, _tensors{reg},
36 _dynamic_tensor_manager{dynamic_tensor_manager},
37 _shared_memory_operand_indexes{shared_memory_operand_indexes}
38{
39 // DO NOTHING
40}
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 42 of file StaticTensorManager.cc.

46 : _nonconst_mgr{new MemoryManager(planner_id)}, _tensors{reg},
47 _dynamic_tensor_manager{dynamic_tensor_manager},
48 _shared_memory_operand_indexes{shared_memory_operand_indexes}
49{
50 // DO NOTHING
51}

◆ ~StaticTensorManager()

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

Member Function Documentation

◆ allocateNonconsts()

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

Definition at line 53 of file StaticTensorManager.cc.

54{
55 _nonconst_mgr->allocate();
56
57 for (auto &&[ind, tensor] : _tensors->native_tensors())
58 {
59 const auto adjusted_ind = adjustWithMemorySourceOperand(ind);
60 if (!_as_constants[adjusted_ind] && !tensor->is_dynamic())
61 {
62 auto *buffer = _nonconst_mgr->getBuffer(adjusted_ind);
63 tensor->setBuffer(buffer);
64
65 VERBOSE(CPU_StaticTensorManager)
66 << "TENSOR " << ind << " : " << static_cast<void *>(buffer) << std::endl;
67 }
68 }
69}
#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 73 of file StaticTensorManager.cc.

75{
76 assert(!_tensors->getNativeTensor(ind));
77 if (as_const)
78 {
79 auto tensor = std::make_unique<ExternalTensor>(tensor_info);
80 _tensors->setNativeTensor(ind, std::move(tensor));
81 }
82 else
83 {
84 auto tensor =
85 std::make_unique<Tensor>(tensor_info, _dynamic_tensor_manager->dynamic_mem_mgr().get());
86 _tensors->setNativeTensor(ind, std::move(tensor));
87 }
88 _as_constants[ind] = as_const;
89}
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 91 of file StaticTensorManager.cc.

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

References size.

◆ deallocateNonconsts()

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

Definition at line 71 of file StaticTensorManager.cc.

71{ _nonconst_mgr->deallocate(); }

◆ iterate()

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

Definition at line 140 of file StaticTensorManager.cc.

141{
142 for (const auto &it : _tensors->native_tensors())
143 fn(it.first);
144}

◆ releasePlan()

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

Definition at line 114 of file StaticTensorManager.cc.

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

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