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

#include <TensorManager.h>

Public Member Functions

 TensorManager (const std::shared_ptr< TensorRegistry > &reg, uint32_t optim_vars_count)
 
virtual ~TensorManager ()=default
 
void allocateNonConstTensors ()
 
void allocateTrainableTensors ()
 
void allocateBackPropTensors ()
 
void allocateGradientTensors ()
 
void allocateDisposableBackPropTensors ()
 
void allocateLayerScopeTensors ()
 
void claimNonConstPlan (const ir::OperandIndex &ind)
 
void releaseNonConstPlan (const ir::OperandIndex &ind)
 
void claimTrainablePlan (const ir::OperandIndex &ind)
 
void releaseTrainablePlan (const ir::OperandIndex &ind)
 
void claimBackPropPlan (const ir::OperandIndex &ind)
 
void releaseBackPropPlan (const ir::OperandIndex &ind)
 
void claimGradientPlan (const ir::OperandIndex &ind)
 
void releaseGradientPlan (const ir::OperandIndex &ind)
 
void claimDisposableBackPropPlan (const DisposableTensorIndex &ind)
 
void releaseDisposableBackPropPlan (const DisposableTensorIndex &ind)
 
void claimLayerScopePlan (const LayerScopeTensorIndex &ind)
 
void releaseLayerScopePlan (const LayerScopeTensorIndex &ind)
 

Static Public Attributes

static constexpr uint64_t _align = 16
 

Detailed Description

Definition at line 30 of file TensorManager.h.

Constructor & Destructor Documentation

◆ TensorManager()

onert::backend::train::TensorManager::TensorManager ( const std::shared_ptr< TensorRegistry > &  reg,
uint32_t  optim_vars_count 
)

Definition at line 52 of file TensorManager.cc.

53 : _nonconst_mgr{new MemoryManager()},
54 _trainable_mgr{new TrainableMemoryManager(optim_vars_count)},
55 _back_prop_mgr{new MemoryManager()}, _gradient_mgr{new MemoryManager()},
56 // TODO Find a suitable planner of disposable tensors to reduce peak memory usage
57 _disposable_back_prop_mgr{new DisposableMemoryManager()},
58 _layer_scope_mgr{new LayerScopeMemoryManager()}, _tensors{reg}
59{
60 // DO NOTHING
61}
backend::basic::MemoryManager MemoryManager

◆ ~TensorManager()

virtual onert::backend::train::TensorManager::~TensorManager ( )
virtualdefault

Member Function Documentation

◆ allocateBackPropTensors()

void onert::backend::train::TensorManager::allocateBackPropTensors ( )

Definition at line 88 of file TensorManager.cc.

89{
90 allocateMemory(_back_prop_mgr.get(), _tensors->back_prop_tensors(),
91 std::string{" BACK_PROP TENSOR "});
92}

◆ allocateDisposableBackPropTensors()

void onert::backend::train::TensorManager::allocateDisposableBackPropTensors ( )

Definition at line 100 of file TensorManager.cc.

101{
102 allocateMemory(_disposable_back_prop_mgr.get(), _tensors->disposable_back_prop_tensors(),
103 std::string{"DISPOSABLE BACK_PROP TENSOR "});
104}

◆ allocateGradientTensors()

void onert::backend::train::TensorManager::allocateGradientTensors ( )

Definition at line 94 of file TensorManager.cc.

95{
96 allocateMemory(_gradient_mgr.get(), _tensors->gradient_tensors(),
97 std::string{" GRADIENT TENSOR "});
98}

◆ allocateLayerScopeTensors()

void onert::backend::train::TensorManager::allocateLayerScopeTensors ( )

Definition at line 106 of file TensorManager.cc.

107{
108 allocateMemory(_layer_scope_mgr.get(), _tensors->layerscope_tensors(),
109 std::string{" LAYERSCOPE TENSOR "});
110}

◆ allocateNonConstTensors()

void onert::backend::train::TensorManager::allocateNonConstTensors ( )

Definition at line 63 of file TensorManager.cc.

64{
65 allocateMemory(_nonconst_mgr.get(), _tensors->nonconst_tensors(),
66 std::string{" TENSOR "});
67}

◆ allocateTrainableTensors()

void onert::backend::train::TensorManager::allocateTrainableTensors ( )

Definition at line 69 of file TensorManager.cc.

70{
71 allocateMemory(_trainable_mgr.get(), _tensors->trainable_tensors(),
72 std::string{" TRAINABLE TENSOR "});
73
74 // Set buffers of optimizer variables
75 // Allocating optimizer variables has been done when calling allocate() of TrainableMemoryManager
76 for (const auto &[index, trainable_tensor] : _tensors->trainable_tensors())
77 {
78 for (uint32_t var_pos = 0; var_pos < trainable_tensor->optVars().size(); ++var_pos)
79 {
80 auto *buffer = _trainable_mgr.get()->getOptVarBuffer(index, var_pos);
81 trainable_tensor->setOptVarBuffer(buffer, var_pos);
82 VERBOSE(TensorManager) << std::string{" OPTIM_VAR TENSOR "} << index << " : "
83 << static_cast<void *>(buffer) << std::endl;
84 }
85 }
86}
#define VERBOSE(name, lv)
Definition Log.h:71
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
int32_t size[5]
Definition Slice.cpp:35

References VERBOSE.

◆ claimBackPropPlan()

void onert::backend::train::TensorManager::claimBackPropPlan ( const ir::OperandIndex ind)

Definition at line 144 of file TensorManager.cc.

145{
146 auto tensor = _tensors->getBackPropTensor(index);
147 assert(tensor && !tensor->is_dynamic());
148
149 auto size = alignedSize(tensor->total_size(), _align);
150 _back_prop_mgr->claimPlan(index, size);
151}
static constexpr uint64_t _align

References _align, and size.

◆ claimDisposableBackPropPlan()

void onert::backend::train::TensorManager::claimDisposableBackPropPlan ( const DisposableTensorIndex ind)

Definition at line 176 of file TensorManager.cc.

177{
178 const auto tensor = _tensors->getDisposableBackPropTensor(index);
179 assert(tensor && !tensor->is_dynamic());
180
181 auto size = alignedSize(tensor->total_size(), _align);
182 _disposable_back_prop_mgr->claimPlan(index, size);
183}

References _align, and size.

◆ claimGradientPlan()

void onert::backend::train::TensorManager::claimGradientPlan ( const ir::OperandIndex ind)

Definition at line 160 of file TensorManager.cc.

161{
162 auto tensor = _tensors->getGradientTensor(index);
163 assert(tensor && !tensor->is_dynamic());
164
165 auto size = alignedSize(tensor->total_size(), _align);
166 _gradient_mgr->claimPlan(index, size);
167}

References _align, and size.

◆ claimLayerScopePlan()

void onert::backend::train::TensorManager::claimLayerScopePlan ( const LayerScopeTensorIndex ind)

Definition at line 193 of file TensorManager.cc.

194{
195 const auto tensor = _tensors->getLayerScopeTensor(index);
196
197 auto size = alignedSize(tensor->total_size(), _align);
198 _layer_scope_mgr->claimPlan(index, size);
199}

References _align, and size.

◆ claimNonConstPlan()

void onert::backend::train::TensorManager::claimNonConstPlan ( const ir::OperandIndex ind)

Definition at line 112 of file TensorManager.cc.

113{
114 auto tensor = _tensors->getNonConstTensor(index);
115 assert(tensor && !tensor->is_dynamic());
116
117 auto size = alignedSize(tensor->total_size(), _align);
118 _nonconst_mgr->claimPlan(index, size);
119}

References _align, and size.

◆ claimTrainablePlan()

void onert::backend::train::TensorManager::claimTrainablePlan ( const ir::OperandIndex ind)

Definition at line 128 of file TensorManager.cc.

129{
130 auto tensor = _tensors->getTrainableTensor(index);
131 assert(tensor && !tensor->is_dynamic());
132
133 auto size = alignedSize(tensor->total_size(), _align);
134 _trainable_mgr->claimPlan(index, size);
135}

References _align, and size.

◆ releaseBackPropPlan()

void onert::backend::train::TensorManager::releaseBackPropPlan ( const ir::OperandIndex ind)

Definition at line 153 of file TensorManager.cc.

154{
155 assert(_tensors->getBackPropTensor(index) && !_tensors->getBackPropTensor(index)->is_dynamic());
156
157 _back_prop_mgr->releasePlan(index);
158}

◆ releaseDisposableBackPropPlan()

void onert::backend::train::TensorManager::releaseDisposableBackPropPlan ( const DisposableTensorIndex ind)

Definition at line 185 of file TensorManager.cc.

186{
187 assert(_tensors->getDisposableBackPropTensor(index) &&
188 !_tensors->getDisposableBackPropTensor(index)->is_dynamic());
189
190 _disposable_back_prop_mgr->releasePlan(index);
191}

◆ releaseGradientPlan()

void onert::backend::train::TensorManager::releaseGradientPlan ( const ir::OperandIndex ind)

Definition at line 169 of file TensorManager.cc.

170{
171 assert(_tensors->getGradientTensor(index) && !_tensors->getGradientTensor(index)->is_dynamic());
172
173 _gradient_mgr->releasePlan(index);
174}

◆ releaseLayerScopePlan()

void onert::backend::train::TensorManager::releaseLayerScopePlan ( const LayerScopeTensorIndex ind)

Definition at line 201 of file TensorManager.cc.

202{
203 assert(_tensors->getLayerScopeTensor(index));
204 _layer_scope_mgr->releasePlan(index);
205}

◆ releaseNonConstPlan()

void onert::backend::train::TensorManager::releaseNonConstPlan ( const ir::OperandIndex ind)

Definition at line 121 of file TensorManager.cc.

122{
123 assert(_tensors->getNonConstTensor(index) && !_tensors->getNonConstTensor(index)->is_dynamic());
124
125 _nonconst_mgr->releasePlan(index);
126}

◆ releaseTrainablePlan()

void onert::backend::train::TensorManager::releaseTrainablePlan ( const ir::OperandIndex ind)

Definition at line 137 of file TensorManager.cc.

138{
139 assert(_tensors->getTrainableTensor(index) && !_tensors->getTrainableTensor(index)->is_dynamic());
140
141 _trainable_mgr->releasePlan(index);
142}

Field Documentation

◆ _align

constexpr uint64_t onert::backend::train::TensorManager::_align = 16
staticconstexpr

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