ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 33 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 36 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 97 of file AclTensorManager.h.

100 : _const_mgr{const_mgr}, _nonconst_mgr{nonconst_mgr}, _inter_mgr{inter_mgr}
101{
102 // DO NOTHING
103}

◆ ~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 106 of file AclTensorManager.h.

107{
108 _const_mgr->allocate();
109}

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 130 of file AclTensorManager.h.

131{
132 _inter_mgr->allocate();
133}

◆ 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 112 of file AclTensorManager.h.

113{
114 _nonconst_mgr->allocate();
115}

◆ 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 211 of file AclTensorManager.h.

212{
213 if (_ind_to_mgr.find(ind) == _ind_to_mgr.end())
214 return nullptr;
215
216 auto &tensors = _ind_to_mgr.at(ind).tensors();
217 if (tensors.find(ind) != tensors.end())
218 {
219 return tensors.at(ind);
220 }
221 else
222 {
223 auto subtensors = _ind_to_mgr.at(ind).subtensors();
224 auto itr = subtensors.find(ind);
225 if (itr == subtensors.end())
226 return nullptr;
227 else
228 return itr->second;
229 }
230}

◆ 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 160 of file AclTensorManager.h.

164{
165 assert(_ind_to_mgr.find(child) == _ind_to_mgr.end());
166 std::shared_ptr<T_ITensor> parent_tensor = findTensorAsParent(parent);
167 assert(parent_tensor);
168 _nonconst_mgr->buildSubtensor(parent_tensor, child, shape, coordinates, rank, extent_parent);
169 _ind_to_mgr.insert({child, *_nonconst_mgr});
170}
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 142 of file AclTensorManager.h.

145{
146 assert(_ind_to_mgr.find(ind) == _ind_to_mgr.end());
147 if (as_const)
148 {
149 _const_mgr->buildTensor(ind, info, rank, num_uses);
150 _ind_to_mgr.insert({ind, *_const_mgr});
151 }
152 else
153 {
154 _nonconst_mgr->buildTensor(ind, info, rank, num_uses);
155 _ind_to_mgr.insert({ind, *_nonconst_mgr});
156 }
157}
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 234 of file AclTensorManager.h.

235{
236 return _const_mgr->tensors();
237}

◆ 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 118 of file AclTensorManager.h.

119{
120 _const_mgr->deallocate();
121}

◆ 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 136 of file AclTensorManager.h.

137{
138 _inter_mgr->deallocate();
139}

◆ 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 124 of file AclTensorManager.h.

125{
126 _nonconst_mgr->deallocate();
127}

◆ 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 174 of file AclTensorManager.h.

175{
176
177 auto &tensors = _nonconst_mgr->tensors();
178 auto &subtensors = _nonconst_mgr->subtensors();
179 if (tensors.find(ind) != tensors.end())
180 {
181 // Parent is allocated as tensor
182 return tensors[ind];
183 }
184 else if (subtensors.find(ind) != subtensors.end())
185 {
186 // Parent is allocated as subtensor
187 return subtensors[ind];
188 }
189 else
190 {
191 return nullptr;
192 }
193}

◆ 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 203 of file AclTensorManager.h.

204{
205 assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end());
206 _ind_to_mgr.at(ind).finishLifetime(ind);
207}

◆ 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 255 of file AclTensorManager.h.

256{
257 return _inter_mgr->internal_buffer_manager();
258}

◆ 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 261 of file AclTensorManager.h.

263{
264 for (auto &&it : _nonconst_mgr->tensors())
265 fn(it.first);
266
267 for (auto &&it : _nonconst_mgr->subtensors())
268 fn(it.first);
269
270 for (auto &&it : _const_mgr->tensors())
271 fn(it.first);
272}

◆ 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 248 of file AclTensorManager.h.

249{
250 return _nonconst_mgr->subtensors();
251}

◆ 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 241 of file AclTensorManager.h.

242{
243 return _nonconst_mgr->tensors();
244}

◆ 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 196 of file AclTensorManager.h.

197{
198 assert(_ind_to_mgr.find(ind) != _ind_to_mgr.end());
199 _ind_to_mgr.at(ind).startLifetime(ind);
200}

◆ 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 275 of file AclTensorManager.h.

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

References VERBOSE.


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