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 MicroMemoryPlannerInterface 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.=
tensorflow/lite/micro/memory_planner/micro_memory_planner.h:47
tflite::MicroMemoryPlanner::MicroMemoryPlanner()tensorflow/lite/micro/memory_planner/micro_memory_planner.h:48
virtual tflite::MicroMemoryPlanner::~MicroMemoryPlanner()AddBuffer
C++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) = 0Pass 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
| Name | Type | Default | Description |
|---|---|---|---|
size | int | Required | |
first_time_used | int | Required | |
last_time_used | int | Required |
AddBuffer
C++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
| Name | Type | Default | Description |
|---|---|---|---|
size | int | Required | |
first_time_used | int | Required | |
last_time_used | int | Required | |
offline_offset | int | Required |
The largest contiguous block of memory that's needed to hold the layout.
tensorflow/lite/micro/memory_planner/micro_memory_planner.h:68
virtual size_t tflite::MicroMemoryPlanner::GetMaximumMemorySize() = 0The largest contiguous block of memory that’s needed to hold the layout.
How many buffers have been added to the planner.
tensorflow/lite/micro/memory_planner/micro_memory_planner.h:70
virtual int tflite::MicroMemoryPlanner::GetBufferCount() = 0How many buffers have been added to the planner.
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) = 0Calculated layout offset for the N-th buffer added to the planner.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
buffer_index | int | Required | |
offset | int * | Required |
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
| Name | Type | Default | Description |
|---|---|---|---|
scratch_buffer | unsigned char * | Required | |
scratch_buffer_size | int | Required |
Method will return True if the MicroMemoryPlanner preserves all tensors after invocation, and False if it doesn't.
tensorflow/lite/micro/memory_planner/micro_memory_planner.h:86
virtual bool tflite::MicroMemoryPlanner::preserves_all_tensors() const = 0Method will return True if the MicroMemoryPlanner preserves all tensors after invocation, and False if it doesn’t.
tensorflow/lite/micro/memory_planner/micro_memory_planner.h:88
virtual void tflite::MicroMemoryPlanner::PrintMemoryPlan()