ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor > Class Template Reference

#include <AclTensorManager.h>

Public Types

using T_AclMemoryManager = AclMemoryManager< T_ITensor, T_Tensor, T_SubTensor >
 

Public Member Functions

 AclTensorManager (T_AclMemoryManager *const_mgr, T_AclMemoryManager *nonconst_mgr, IInternalBufferManager *inter_mgr)
 
virtual ~AclTensorManager ()=default
 
void allocateConsts (void)
 
void allocateNonconsts (void)
 
void deallocateConsts (void)
 
void deallocateNonconsts (void)
 
void allocateInternalBufferManager (void)
 
void deallocateInternalBufferManager (void)
 
void buildTensor (const ir::OperandIndex &ind, const ::arm_compute::TensorInfo &info, size_t rank, bool as_const, size_t num_uses)
 
void buildSubtensor (const ir::OperandIndex &parent, const ir::OperandIndex &child, const ::arm_compute::TensorShape &shape, const ::arm_compute::Coordinates &coordinates, size_t rank, bool extent_parent)
 
std::shared_ptr< T_ITensor > findTensorAsParent (const ir::OperandIndex &ind)
 
void startLifetime (const ir::OperandIndex &ind)
 
void finishLifetime (const ir::OperandIndex &ind)
 
std::shared_ptr< T_ITensor > at (const ir::OperandIndex &ind)
 
ir::OperandIndexMap< std::shared_ptr< T_Tensor > > & constTensors (void)
 
ir::OperandIndexMap< std::shared_ptr< T_Tensor > > & nonconstTensors (void)
 
ir::OperandIndexMap< std::shared_ptr< T_SubTensor > > & nonconstSubtensors (void)
 
std::shared_ptr<::arm_compute::IMemoryManager > internal_buffer_manager (void)
 
void iterate (const std::function< void(const ir::OperandIndex &)> &fn)
 
void tryDeallocConstants (void)
 

Detailed Description

template<typename T_ITensor, typename T_Tensor, typename T_SubTensor>
class onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >

Definition at line 29 of file AclTensorManager.h.

Member Typedef Documentation

◆ T_AclMemoryManager

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
using onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::T_AclMemoryManager = AclMemoryManager<T_ITensor, T_Tensor, T_SubTensor>

Definition at line 32 of file AclTensorManager.h.

Constructor & Destructor Documentation

◆ AclTensorManager()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::AclTensorManager ( T_AclMemoryManager const_mgr,
T_AclMemoryManager nonconst_mgr,
IInternalBufferManager inter_mgr 
)

Definition at line 87 of file AclTensorManager.h.

90 : _const_mgr{const_mgr}, _nonconst_mgr{nonconst_mgr}, _inter_mgr{inter_mgr}
91{
92 // DO NOTHING
93}

◆ ~AclTensorManager()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
virtual onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::~AclTensorManager ( )
virtualdefault

Member Function Documentation

◆ allocateConsts()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::allocateConsts ( void  )

Definition at line 96 of file AclTensorManager.h.

97{
98 _const_mgr->allocate();
99}

References onert::backend::acl_common::IInternalBufferManager::allocate().

◆ allocateInternalBufferManager()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::allocateInternalBufferManager ( void  )

Definition at line 120 of file AclTensorManager.h.

121{
122 _inter_mgr->allocate();
123}

◆ allocateNonconsts()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::allocateNonconsts ( void  )

Definition at line 102 of file AclTensorManager.h.

103{
104 _nonconst_mgr->allocate();
105}

◆ at()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
std::shared_ptr< T_ITensor > onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::at ( const ir::OperandIndex ind)

Definition at line 201 of file AclTensorManager.h.

202{
203 if (_ind_to_mgr.find(ind) == _ind_to_mgr.end())
204 return nullptr;
205
206 auto &tensors = _ind_to_mgr.at(ind).tensors();
207 if (tensors.find(ind) != tensors.end())
208 {
209 return tensors.at(ind);
210 }
211 else
212 {
213 auto subtensors = _ind_to_mgr.at(ind).subtensors();
214 auto itr = subtensors.find(ind);
215 if (itr == subtensors.end())
216 return nullptr;
217 else
218 return itr->second;
219 }
220}

◆ buildSubtensor()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::buildSubtensor ( const ir::OperandIndex parent,
const ir::OperandIndex child,
const ::arm_compute::TensorShape &  shape,
const ::arm_compute::Coordinates &  coordinates,
size_t  rank,
bool  extent_parent 
)

Definition at line 150 of file AclTensorManager.h.

154{
155 assert(_ind_to_mgr.find(child) == _ind_to_mgr.end());
156 std::shared_ptr<T_ITensor> parent_tensor = findTensorAsParent(parent);
157 assert(parent_tensor);
158 _nonconst_mgr->buildSubtensor(parent_tensor, child, shape, coordinates, rank, extent_parent);
159 _ind_to_mgr.insert({child, *_nonconst_mgr});
160}
std::shared_ptr< T_ITensor > findTensorAsParent(const ir::OperandIndex &ind)

◆ buildTensor()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::buildTensor ( const ir::OperandIndex ind,
const ::arm_compute::TensorInfo &  info,
size_t  rank,
bool  as_const,
size_t  num_uses 
)

Definition at line 132 of file AclTensorManager.h.

135{
136 assert(_ind_to_mgr.find(ind) == _ind_to_mgr.end());
137 if (as_const)
138 {
139 _const_mgr->buildTensor(ind, info, rank, num_uses);
140 _ind_to_mgr.insert({ind, *_const_mgr});
141 }
142 else
143 {
144 _nonconst_mgr->buildTensor(ind, info, rank, num_uses);
145 _ind_to_mgr.insert({ind, *_nonconst_mgr});
146 }
147}
volatile const char info[]

References info.

◆ constTensors()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
ir::OperandIndexMap< std::shared_ptr< T_Tensor > > & onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::constTensors ( void  )

Definition at line 224 of file AclTensorManager.h.

225{
226 return _const_mgr->tensors();
227}

◆ deallocateConsts()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::deallocateConsts ( void  )

Definition at line 108 of file AclTensorManager.h.

109{
110 _const_mgr->deallocate();
111}

◆ deallocateInternalBufferManager()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::deallocateInternalBufferManager ( void  )

Definition at line 126 of file AclTensorManager.h.

127{
128 _inter_mgr->deallocate();
129}

◆ deallocateNonconsts()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::deallocateNonconsts ( void  )

Definition at line 114 of file AclTensorManager.h.

115{
116 _nonconst_mgr->deallocate();
117}

◆ findTensorAsParent()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
std::shared_ptr< T_ITensor > onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::findTensorAsParent ( const ir::OperandIndex ind)

Definition at line 164 of file AclTensorManager.h.

165{
166
167 auto &tensors = _nonconst_mgr->tensors();
168 auto &subtensors = _nonconst_mgr->subtensors();
169 if (tensors.find(ind) != tensors.end())
170 {
171 // Parent is allocated as tensor
172 return tensors[ind];
173 }
174 else if (subtensors.find(ind) != subtensors.end())
175 {
176 // Parent is allocated as subtensor
177 return subtensors[ind];
178 }
179 else
180 {
181 return nullptr;
182 }
183}

◆ finishLifetime()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::finishLifetime ( const ir::OperandIndex ind)

Definition at line 193 of file AclTensorManager.h.

194{
195 assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end());
196 _ind_to_mgr.at(ind).finishLifetime(ind);
197}

◆ internal_buffer_manager()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
std::shared_ptr<::arm_compute::IMemoryManager > onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::internal_buffer_manager ( void  )

Definition at line 245 of file AclTensorManager.h.

246{
247 return _inter_mgr->internal_buffer_manager();
248}

◆ iterate()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::iterate ( const std::function< void(const ir::OperandIndex &)> &  fn)

Definition at line 251 of file AclTensorManager.h.

253{
254 for (auto &&it : _nonconst_mgr->tensors())
255 fn(it.first);
256
257 for (auto &&it : _nonconst_mgr->subtensors())
258 fn(it.first);
259
260 for (auto &&it : _const_mgr->tensors())
261 fn(it.first);
262}

◆ nonconstSubtensors()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
ir::OperandIndexMap< std::shared_ptr< T_SubTensor > > & onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::nonconstSubtensors ( void  )

Definition at line 238 of file AclTensorManager.h.

239{
240 return _nonconst_mgr->subtensors();
241}

◆ nonconstTensors()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
ir::OperandIndexMap< std::shared_ptr< T_Tensor > > & onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::nonconstTensors ( void  )

Definition at line 231 of file AclTensorManager.h.

232{
233 return _nonconst_mgr->tensors();
234}

◆ startLifetime()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::startLifetime ( const ir::OperandIndex ind)

Definition at line 186 of file AclTensorManager.h.

187{
188 assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end());
189 _ind_to_mgr.at(ind).startLifetime(ind);
190}

◆ tryDeallocConstants()

template<typename T_ITensor , typename T_Tensor , typename T_SubTensor >
void onert::backend::acl_common::AclTensorManager< T_ITensor, T_Tensor, T_SubTensor >::tryDeallocConstants ( void  )

Definition at line 265 of file AclTensorManager.h.

266{
267 auto &tensors = _const_mgr->tensors();
268
269 for (auto it = tensors.begin(); it != tensors.end();)
270 {
271 const auto &ind = it->first;
272 auto tensor = it->second;
273 // NOTE The condition "tensor->num_uses() < 2" is used to prevent deallocating a constant tensor
274 // used in several nodes.
275 if (tensor->handle() && !tensor->handle()->is_used() && tensor->num_uses() < 2)
276 {
277 VERBOSE(AclTensorManager) << "Tensor " << ind
278 << " will be deallocated as an unused constant tensor" << std::endl;
279 tensor->allocator()->free();
280 tensor.reset();
281 it = tensors.erase(it);
282 }
283 else
284 {
285 ++it;
286 }
287 }
288}
#define VERBOSE(name, lv)
Definition Log.h:71

References VERBOSE.


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