ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci_interpreter::SimpleMemoryManager Class Reference

#include <SimpleMemoryManager.h>

Collaboration diagram for luci_interpreter::SimpleMemoryManager:

Public Member Functions

void allocate_memory (luci_interpreter::Tensor &tensor) final
 
void release_memory (luci_interpreter::Tensor &tensor) final
 
uint8_t * allocate_memory (const circle::Tensor *tensor)
 
void release_memory (uint8_t *data)
 
- Public Member Functions inherited from luci_interpreter::IMemoryManager
virtual ~IMemoryManager ()=default
 

Detailed Description

Definition at line 25 of file SimpleMemoryManager.h.

Member Function Documentation

◆ allocate_memory() [1/2]

uint8_t * luci_interpreter::SimpleMemoryManager::allocate_memory ( const circle::Tensor *  tensor)

Definition at line 24 of file SimpleMemoryManager.cpp.

25{
26 const auto element_size = getDataTypeSize(Tensor::element_type(tensor));
27 const auto num_elements = Tensor::num_elements(tensor);
28
29 assert(element_size * num_elements > 0);
30
31 return new uint8_t[num_elements * element_size];
32}
size_t getDataTypeSize(DataType data_type)
Definition DataType.h:33
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59

References luci_interpreter::getDataTypeSize().

◆ allocate_memory() [2/2]

void luci_interpreter::SimpleMemoryManager::allocate_memory ( luci_interpreter::Tensor tensor)
finalvirtual

Implements luci_interpreter::IMemoryManager.

Definition at line 22 of file SimpleMemoryManager.cpp.

23{
24 if (!tensor.is_allocatable())
25 {
26 return;
27 }
28 if (tensor.is_data_allocated())
29 {
30 release_memory(tensor);
31 }
32 const auto element_size = getDataTypeSize(tensor.element_type());
33
34 // Use large_num_elements to avoid overflow
35 const auto num_elements = tensor.shape().large_num_elements();
36
37 auto *data = new uint8_t[num_elements * element_size];
38 tensor.set_data_buffer(data);
39}
void release_memory(luci_interpreter::Tensor &tensor) final
const T * data(const std::vector< T, Alloc > &v)

References flatbuffers::data(), luci_interpreter::getDataTypeSize(), and release_memory().

◆ release_memory() [1/2]

void luci_interpreter::SimpleMemoryManager::release_memory ( luci_interpreter::Tensor tensor)
finalvirtual

Implements luci_interpreter::IMemoryManager.

Definition at line 41 of file SimpleMemoryManager.cpp.

42{
43 if (!tensor.is_data_allocated())
44 {
45 tensor.set_data_buffer(nullptr);
46 return;
47 }
48 auto data = tensor.data<uint8_t>();
49 delete[] data;
50 tensor.set_data_buffer(nullptr);
51}

References flatbuffers::data().

Referenced by allocate_memory().

◆ release_memory() [2/2]

void luci_interpreter::SimpleMemoryManager::release_memory ( uint8_t *  data)

Definition at line 34 of file SimpleMemoryManager.cpp.

35{
36 if (data == nullptr)
37 return;
38
39 delete[] data;
40}

References flatbuffers::data().


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