Skip to content
heliaRT
API reference
HELIA HUB

MicroMemoryPlanner

Interface for planning reusable buffers.

Machine-readable model

class

Interface class for planning the layout of memory buffers during the execution of a graph.

tensorflow/lite/micro/memory_planner/micro_memory_planner.h:45

class MicroMemoryPlanner

Interface class for planning the layout of memory buffers during the execution of a graph. It’s designed to be used by a client that iterates in any order through the buffers it wants to lay out, and then calls the getter functions for information about the calculated layout. For example:

SomeMemoryPlanner planner; planner.AddBuffer(100, 0, 1); // Buffer 0 planner.AddBuffer(50, 2, 3); // Buffer 1 planner.AddBuffer(50, 2, 3); // Buffer 2

int offset0; TF_EXPECT_OK(planner.GetOffsetForBuffer(0, &offset0)); int offset1; TF_EXPECT_OK(planner.GetOffsetForBuffer(1, &offset1)); int offset2; TF_EXPECT_OK(planner.GetOffsetForBuffer(2, &offset2)); const int arena_size_needed = planner.GetMaximumMemorySize();

The goal is for applications to be able to experiment with different layout strategies without changing their client code, by swapping out classes that implement this interface.=

method

Pass information about a buffer's size and lifetime to the layout algorithm.

tensorflow/lite/micro/memory_planner/micro_memory_planner.h:55

virtual TfLiteStatus tflite::MicroMemoryPlanner::AddBuffer(int size, int first_time_used, int last_time_used) = 0

Pass information about a buffer’s size and lifetime to the layout algorithm. The order this is called implicitly assigns an index to the result, so the buffer information that’s passed into the N-th call of this method will be used as the buffer_index argument to GetOffsetForBuffer().

Parameters of AddBuffer
NameTypeDefaultDescription
sizeintRequired
first_time_usedintRequired
last_time_usedintRequired
method

Record details of an offline planned buffer offset we want to place.

tensorflow/lite/micro/memory_planner/micro_memory_planner.h:62

virtual TfLiteStatus tflite::MicroMemoryPlanner::AddBuffer(
int size,
int first_time_used,
int last_time_used,
int offline_offset
)

Record details of an offline planned buffer offset we want to place. offline_offset is the buffer offset from the start of the arena. This is to support offline memory planning from the flatbuffer metadata. By default, it returns an error.

Parameters of AddBuffer
NameTypeDefaultDescription
sizeintRequired
first_time_usedintRequired
last_time_usedintRequired
offline_offsetintRequired
method

Calculated layout offset for the N-th buffer added to the planner.

tensorflow/lite/micro/memory_planner/micro_memory_planner.h:72

virtual TfLiteStatus tflite::MicroMemoryPlanner::GetOffsetForBuffer(int buffer_index, int *offset) = 0

Calculated layout offset for the N-th buffer added to the planner.

Parameters of GetOffsetForBuffer
NameTypeDefaultDescription
buffer_indexintRequired
offsetint *Required
method

Init

C++

Provides the scratch buffer in case that the memory planner needs it.

tensorflow/lite/micro/memory_planner/micro_memory_planner.h:79

virtual TfLiteStatus tflite::MicroMemoryPlanner::Init(unsigned char *scratch_buffer, int scratch_buffer_size)

Provides the scratch buffer in case that the memory planner needs it. The lifetime of scratch buffers lifetime lasts until the static memory plan is committed. The default implementation is for the memory planner that does not need scratch buffer and simply returns ok.

Parameters of Init
NameTypeDefaultDescription
scratch_bufferunsigned char *Required
scratch_buffer_sizeintRequired