ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::basic::DynamicMemoryManager Class Reference

#include <MemoryManager.h>

Public Member Functions

 DynamicMemoryManager ()=default
 
virtual ~DynamicMemoryManager ()=default
 
std::shared_ptr< Allocatorallocate (const ITensor *tensor, uint32_t capacity)
 
void deallocate (const ITensor *tensor)
 
void deallocate (void)
 

Detailed Description

Definition at line 58 of file MemoryManager.h.

Constructor & Destructor Documentation

◆ DynamicMemoryManager()

onert::backend::basic::DynamicMemoryManager::DynamicMemoryManager ( )
default

◆ ~DynamicMemoryManager()

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

Member Function Documentation

◆ allocate()

std::shared_ptr< basic::Allocator > onert::backend::basic::DynamicMemoryManager::allocate ( const ITensor tensor,
uint32_t  capacity 
)

Definition at line 75 of file MemoryManager.cc.

77{
78 auto find = _mem_alloc_map.find(tensor);
79 if (find != _mem_alloc_map.end())
80 throw std::runtime_error("Cannot allocate memory for a tensor. It was already allocated.");
81
82 _mem_alloc_map[tensor] = std::make_shared<basic::Allocator>(capacity);
83 return _mem_alloc_map[tensor];
84}
Section find(const Sections &sections, const std::string &name)
Find a section with name, empty section if not found.

Referenced by onert::backend::basic::Tensor::applyShape(), and onert::backend::builtin::kernel::WhileLayer::run().

◆ deallocate() [1/2]

void onert::backend::basic::DynamicMemoryManager::deallocate ( const ITensor tensor)

Definition at line 86 of file MemoryManager.cc.

87{
88 auto find = _mem_alloc_map.find(tensor);
89 if (find == _mem_alloc_map.end())
90 throw std::runtime_error("Cannot find Allocator for the requested index");
91
92 find->second->release(); // explicitly erase memory
93 _mem_alloc_map.erase(find); // remove tensor and alloc
94}

Referenced by onert::backend::basic::Tensor::applyShape(), onert::backend::basic::Tensor::deallocBuffer(), and onert::backend::builtin::kernel::WhileLayer::run().

◆ deallocate() [2/2]

void onert::backend::basic::DynamicMemoryManager::deallocate ( void  )

Definition at line 96 of file MemoryManager.cc.

97{
98 for (auto &&mem_alloc : _mem_alloc_map)
99 {
100 // Release memory buffer of mem_alloc
101 mem_alloc.second->release();
102 }
103
104 _mem_alloc_map.clear();
105}

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