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

#include <TensorBuilder.h>

Public Member Functions

 TensorBuilder (const std::shared_ptr< TensorRegistry > &tensor_reg, const exec::train::optimizer::Optimizer *optimizer)
 
void registerTensorInfo (const ir::OperandIndex &ind, const ir::OperandInfo &info)
 Register tensor information to allocate on train backend.
 
void registerBackwardTensorInfo (const ir::OperandIndex &ind, const ir::OperandInfo &info)
 Register informations of tensor used only in backward to allocate on train backend.
 
void registerDisposableBackwardTensorInfo (const DisposableTensorIndex &index, const ir::OperandInfo &info)
 
void registerLayerScopeTensor (const LayerScopeTensorIndex &index, std::shared_ptr< LayerScopeTensor > &info)
 
void notifyFirstUse (const ir::OperandIndex &)
 
void notifyLastUse (const ir::OperandIndex &)
 
void notifyBackwardFirstUse (const ir::OperandIndex &)
 
void notifyBackwardLastUse (const ir::OperandIndex &)
 
void notifyDisposableBackPropFirstUse (const DisposableTensorIndex &)
 
void notifyDisposableBackPropLastUse (const DisposableTensorIndex &)
 
void notifyLayerScopeFirstUse (const LayerScopeTensorIndex &)
 
void notifyLayerScopeLastUse (const LayerScopeTensorIndex &)
 
bool isRegistered (const ir::OperandIndex &) const
 
bool isRegisteredBackward (const ir::OperandIndex &) const
 
bool isRegisteredDisposableBackwardTensor (const DisposableTensorIndex &index) const
 
bool isRegisteredLayerScopeTensor (const ir::OperationIndex &) const
 
const util::Set< LayerScopeTensorIndex > & getRegisteredLayerScopeTensorIndices (const ir::OperationIndex &) const
 
LayerScopeTensorLifeTime getLayerScopeTensorLifeTime (const LayerScopeTensorIndex &) const
 
void allocate (void)
 
void allocateBackward (void)
 
void allocateLayerScope (void)
 

Detailed Description

Definition at line 33 of file TensorBuilder.h.

Constructor & Destructor Documentation

◆ TensorBuilder()

onert::backend::train::TensorBuilder::TensorBuilder ( const std::shared_ptr< TensorRegistry > &  tensor_reg,
const exec::train::optimizer::Optimizer optimizer 
)

Definition at line 24 of file TensorBuilder.cc.

26 : _tensor_reg{tensor_reg}, _tensor_mgr{new TensorManager(tensor_reg, optimizer->getVarCount())},
27 _optimizer{optimizer}
28{
29 /* empty */
30}
acl_common::AclTensorManager< operand::ICLTensor, operand::CLTensor, operand::CLSubTensor > TensorManager

Member Function Documentation

◆ allocate()

void onert::backend::train::TensorBuilder::allocate ( void  )

Definition at line 223 of file TensorBuilder.cc.

224{
225 _tensor_mgr->allocateNonConstTensors();
226 _tensor_mgr->allocateTrainableTensors();
227}

◆ allocateBackward()

void onert::backend::train::TensorBuilder::allocateBackward ( void  )

Definition at line 229 of file TensorBuilder.cc.

230{
231 _tensor_mgr->allocateBackPropTensors();
232 _tensor_mgr->allocateGradientTensors();
233 _tensor_mgr->allocateDisposableBackPropTensors();
234}

◆ allocateLayerScope()

void onert::backend::train::TensorBuilder::allocateLayerScope ( void  )

Definition at line 236 of file TensorBuilder.cc.

236{ _tensor_mgr->allocateLayerScopeTensors(); }

◆ getLayerScopeTensorLifeTime()

LayerScopeTensorLifeTime onert::backend::train::TensorBuilder::getLayerScopeTensorLifeTime ( const LayerScopeTensorIndex index) const

Definition at line 216 of file TensorBuilder.cc.

217{
218 const auto &ls_tensors = _tensor_reg->layerscope_tensors();
219 const auto &tensor = ls_tensors.at(index);
220 return tensor->lifetime();
221}

Referenced by onert::backend::train::TensorPlanner::planLayerScopeTensors().

◆ getRegisteredLayerScopeTensorIndices()

const util::Set< LayerScopeTensorIndex > & onert::backend::train::TensorBuilder::getRegisteredLayerScopeTensorIndices ( const ir::OperationIndex index) const

Definition at line 207 of file TensorBuilder.cc.

208{
209 const auto pair = _operation_to_layerscope.find(index);
210 assert(pair != _operation_to_layerscope.end());
211
212 return pair->second;
213}

Referenced by onert::backend::train::TensorPlanner::planLayerScopeTensors().

◆ isRegistered()

bool onert::backend::train::TensorBuilder::isRegistered ( const ir::OperandIndex index) const

Definition at line 185 of file TensorBuilder.cc.

186{
187 return _tensor_info_map.find(index) != _tensor_info_map.end();
188}

Referenced by onert::backend::train::TensorPlanner::planNonConstTensors(), and onert::backend::train::TensorPlanner::planTrainableTensors().

◆ isRegisteredBackward()

bool onert::backend::train::TensorBuilder::isRegisteredBackward ( const ir::OperandIndex index) const

Definition at line 190 of file TensorBuilder.cc.

191{
192 return _backward_tensor_info_map.find(index) != _backward_tensor_info_map.end();
193}

Referenced by onert::backend::train::TensorPlanner::planBackPropTensors(), and onert::backend::train::TensorPlanner::planGradientTensors().

◆ isRegisteredDisposableBackwardTensor()

bool onert::backend::train::TensorBuilder::isRegisteredDisposableBackwardTensor ( const DisposableTensorIndex index) const

Definition at line 195 of file TensorBuilder.cc.

196{
197 return _disposable_backprops.contains(index);
198}

Referenced by onert::backend::train::TensorPlanner::planDisposableBackPropTensors().

◆ isRegisteredLayerScopeTensor()

bool onert::backend::train::TensorBuilder::isRegisteredLayerScopeTensor ( const ir::OperationIndex index) const

Definition at line 200 of file TensorBuilder.cc.

201{
202 const auto pair = _operation_to_layerscope.find(index);
203 return (pair != _operation_to_layerscope.end());
204}

Referenced by onert::backend::train::TensorPlanner::planLayerScopeTensors().

◆ notifyBackwardFirstUse()

void onert::backend::train::TensorBuilder::notifyBackwardFirstUse ( const ir::OperandIndex index)

Definition at line 140 of file TensorBuilder.cc.

141{
142 // TODO Support momory plan
143 if (_as_constants[index])
144 {
145 _tensor_mgr->claimGradientPlan(index);
146 }
147 else
148 {
149 _tensor_mgr->claimBackPropPlan(index);
150 }
151}

Referenced by onert::backend::train::TensorPlanner::planBackPropTensors(), and onert::backend::train::TensorPlanner::planGradientTensors().

◆ notifyBackwardLastUse()

void onert::backend::train::TensorBuilder::notifyBackwardLastUse ( const ir::OperandIndex index)

Definition at line 153 of file TensorBuilder.cc.

154{
155 if (_as_constants[index])
156 {
157 _tensor_mgr->releaseGradientPlan(index);
158 }
159 else
160 {
161 _tensor_mgr->releaseBackPropPlan(index);
162 }
163}

Referenced by onert::backend::train::TensorPlanner::planBackPropTensors(), and onert::backend::train::TensorPlanner::planGradientTensors().

◆ notifyDisposableBackPropFirstUse()

void onert::backend::train::TensorBuilder::notifyDisposableBackPropFirstUse ( const DisposableTensorIndex index)

Definition at line 165 of file TensorBuilder.cc.

166{
167 _tensor_mgr->claimDisposableBackPropPlan(index);
168}

Referenced by onert::backend::train::TensorPlanner::planDisposableBackPropTensors().

◆ notifyDisposableBackPropLastUse()

void onert::backend::train::TensorBuilder::notifyDisposableBackPropLastUse ( const DisposableTensorIndex index)

Definition at line 170 of file TensorBuilder.cc.

171{
172 _tensor_mgr->releaseDisposableBackPropPlan(index);
173}

Referenced by onert::backend::train::TensorPlanner::planDisposableBackPropTensors().

◆ notifyFirstUse()

void onert::backend::train::TensorBuilder::notifyFirstUse ( const ir::OperandIndex index)

Definition at line 115 of file TensorBuilder.cc.

116{
117 // TODO Support momory plan
118 if (_as_constants[index])
119 {
120 _tensor_mgr->claimTrainablePlan(index);
121 }
122 else
123 {
124 _tensor_mgr->claimNonConstPlan(index);
125 }
126}

Referenced by onert::backend::train::TensorPlanner::planNonConstTensors(), and onert::backend::train::TensorPlanner::planTrainableTensors().

◆ notifyLastUse()

void onert::backend::train::TensorBuilder::notifyLastUse ( const ir::OperandIndex index)

Definition at line 128 of file TensorBuilder.cc.

129{
130 if (_as_constants[index])
131 {
132 _tensor_mgr->releaseTrainablePlan(index);
133 }
134 else
135 {
136 _tensor_mgr->releaseNonConstPlan(index);
137 }
138}

Referenced by onert::backend::train::TensorPlanner::planNonConstTensors(), and onert::backend::train::TensorPlanner::planTrainableTensors().

◆ notifyLayerScopeFirstUse()

void onert::backend::train::TensorBuilder::notifyLayerScopeFirstUse ( const LayerScopeTensorIndex index)

Definition at line 175 of file TensorBuilder.cc.

176{
177 _tensor_mgr->claimLayerScopePlan(index);
178}

Referenced by onert::backend::train::TensorPlanner::planLayerScopeTensors().

◆ notifyLayerScopeLastUse()

void onert::backend::train::TensorBuilder::notifyLayerScopeLastUse ( const LayerScopeTensorIndex index)

Definition at line 180 of file TensorBuilder.cc.

181{
182 _tensor_mgr->releaseLayerScopePlan(index);
183}

Referenced by onert::backend::train::TensorPlanner::planLayerScopeTensors().

◆ registerBackwardTensorInfo()

void onert::backend::train::TensorBuilder::registerBackwardTensorInfo ( const ir::OperandIndex ind,
const ir::OperandInfo info 
)

Register informations of tensor used only in backward to allocate on train backend.

Parameters
[in]indOperand index
[in]infoOperand information

Definition at line 53 of file TensorBuilder.cc.

55{
56 _backward_tensor_info_map.emplace(index, info);
57
58 assert(!info.isDynamic());
59
60 // NOTE For now, whether or not to build operands to trainable tensor depends on whether
61 // the corresponding operand is constant.
62 assert(_as_constants[index] == info.isConstant());
63 if (_as_constants[index])
64 {
65 auto tensor = std::make_unique<GradientTensor>(info);
66 _tensor_reg->setGradientTensor(index, std::move(tensor));
67
68 // Initialize tensors for gradient variables
69 for (uint32_t i = 0; i < _optimizer->getVarCount(); ++i)
70 {
71 auto tensor = std::make_unique<Tensor>(info);
72 _tensor_reg->getTrainableTensor(index)->appendOptVar(std::move(tensor));
73 }
74 }
75 else
76 {
77 auto tensor = std::make_unique<BackPropTensor>(info);
78 _tensor_reg->setBackPropTensor(index, std::move(tensor));
79 }
80}
virtual uint32_t getVarCount() const =0
Get the number of optimizer variables s.
volatile const char info[]

References onert::exec::train::optimizer::Optimizer::getVarCount(), and info.

◆ registerDisposableBackwardTensorInfo()

void onert::backend::train::TensorBuilder::registerDisposableBackwardTensorInfo ( const DisposableTensorIndex index,
const ir::OperandInfo info 
)

Definition at line 82 of file TensorBuilder.cc.

84{
85 assert(!info.isDynamic());
86 assert(!_as_constants[index.operand_index()]);
87
88 auto disposable_tensor = std::make_unique<BackPropTensor>(info);
89 _tensor_reg->setDisposableBackPropTensor(index, std::move(disposable_tensor));
90
91 _disposable_backprops.add(index);
92}
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References info.

◆ registerLayerScopeTensor()

void onert::backend::train::TensorBuilder::registerLayerScopeTensor ( const LayerScopeTensorIndex index,
std::shared_ptr< LayerScopeTensor > &  info 
)

Definition at line 94 of file TensorBuilder.cc.

96{
97 const auto op_idx = index.op_index();
98
99 const auto pair = _operation_to_layerscope.find(op_idx);
100 if (pair == _operation_to_layerscope.end())
101 {
102 util::Set<LayerScopeTensorIndex> tensor_indices;
103 tensor_indices.add(index);
104 _operation_to_layerscope[op_idx] = tensor_indices;
105 }
106 else
107 {
108 assert(!pair->second.contains(index));
109 pair->second.add(index);
110 }
111
112 _tensor_reg->setLayerScopeTensor(index, tensor);
113}

References onert::util::Set< Element >::add().

◆ registerTensorInfo()

void onert::backend::train::TensorBuilder::registerTensorInfo ( const ir::OperandIndex ind,
const ir::OperandInfo info 
)

Register tensor information to allocate on train backend.

Parameters
[in]indOperand index
[in]infoOperand information

Definition at line 32 of file TensorBuilder.cc.

33{
34 _tensor_info_map.emplace(index, info);
35 _as_constants[index] = info.isConstant();
36
37 assert(!info.isDynamic());
38
39 // NOTE For now, whether or not to build operands to trainable tensor depends on whether
40 // the corresponding operand is constant.
41 if (_as_constants[index])
42 {
43 auto tensor = std::make_unique<TrainableTensor>(info);
44 _tensor_reg->setTrainableTensor(index, std::move(tensor));
45 }
46 else
47 {
48 auto tensor = std::make_unique<Tensor>(info);
49 _tensor_reg->setNonConstTensor(index, std::move(tensor));
50 }
51}

References info.


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