| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #include "edge-impulse-sdk/tensorflow/lite/micro/persistent_arena_buffer_allocator.h" |
|
|
| #include "edge-impulse-sdk/tensorflow/lite/micro/memory_helpers.h" |
| #include "edge-impulse-sdk/tensorflow/lite/micro/micro_log.h" |
|
|
| namespace tflite { |
|
|
| PersistentArenaBufferAllocator::PersistentArenaBufferAllocator( |
| uint8_t* buffer, size_t buffer_size) |
| : buffer_head_(buffer), |
| buffer_tail_(buffer + buffer_size), |
| tail_temp_(buffer_tail_) {} |
|
|
| PersistentArenaBufferAllocator::~PersistentArenaBufferAllocator() {} |
|
|
| uint8_t* PersistentArenaBufferAllocator::AllocatePersistentBuffer( |
| size_t size, size_t alignment) { |
| uint8_t* const aligned_result = |
| AlignPointerDown(tail_temp_ - size, alignment); |
| if (aligned_result < buffer_head_) { |
| #ifndef TF_LITE_STRIP_ERROR_STRINGS |
| const size_t missing_memory = buffer_head_ - aligned_result; |
| MicroPrintf( |
| "Failed to allocate tail memory. Requested: %u, " |
| "available %u, missing: %u", |
| size, size - missing_memory, missing_memory); |
| #endif |
| return nullptr; |
| } |
| tail_temp_ = aligned_result; |
| return aligned_result; |
| } |
|
|
| size_t PersistentArenaBufferAllocator::GetPersistentUsedBytes() const { |
| return buffer_tail_ - tail_temp_; |
| } |
|
|
| } |
|
|