ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 56 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 71 of file MemoryManager.cc.

73{
74 auto find = _mem_alloc_map.find(tensor);
75 if (find != _mem_alloc_map.end())
76 throw std::runtime_error("Cannot allocate memory for a tensor. It was already allocated.");
77
78 _mem_alloc_map[tensor] = std::make_shared<basic::Allocator>(capacity);
79 return _mem_alloc_map[tensor];
80}
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 82 of file MemoryManager.cc.

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

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 92 of file MemoryManager.cc.

93{
94 for (auto &&mem_alloc : _mem_alloc_map)
95 {
96 // Release memory buffer of mem_alloc
97 mem_alloc.second->release();
98 }
99
100 _mem_alloc_map.clear();
101}

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