Utility subclass of MicroAllocator that records all allocations inside the arena.
class RecordingMicroAllocator : public tflite::MicroAllocatorUtility subclass of MicroAllocator that records all allocations inside the arena. A summary of allocations can be logged through the ErrorReporter by invoking LogAllocations(). This special allocator requires an instance of RecordingSingleArenaBufferAllocator to capture allocations in the head and tail. Arena allocation recording can be retrieved by type through the GetRecordedAllocation() function. This class should only be used for auditing memory usage or integration testing.
Create
C++static RecordingMicroAllocator * tflite::RecordingMicroAllocator::Create(uint8_t *tensor_arena, size_t arena_size)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
tensor_arena | uint8_t * | Required | |
arena_size | size_t | Required |
Returns the fixed amount of memory overhead of RecordingMicroAllocator.
static size_t tflite::RecordingMicroAllocator::GetDefaultTailUsage()Returns the fixed amount of memory overhead of RecordingMicroAllocator.
Returns the recorded allocations information for a given allocation type.
RecordedAllocation tflite::RecordingMicroAllocator::GetRecordedAllocation(RecordedAllocationType allocation_type) constReturns the recorded allocations information for a given allocation type.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
allocation_type | RecordedAllocationType | Required |
const RecordingSingleArenaBufferAllocator * tflite::RecordingMicroAllocator::GetSimpleMemoryAllocator() constLogs out through the ErrorReporter all allocation recordings by type defined in RecordedAllocationType.
void tflite::RecordingMicroAllocator::PrintAllocations() constLogs out through the ErrorReporter all allocation recordings by type defined in RecordedAllocationType.
Allocates persistent buffer which has the same life time as the allocator.
void * tflite::RecordingMicroAllocator::AllocatePersistentBuffer(size_t bytes)Allocates persistent buffer which has the same life time as the allocator. The memory is immediately available and is allocated from the tail of the arena.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
bytes | size_t | Required |
Allocates an array in the arena to hold pointers to the node and registration pointers required to represent the inference graph of the model.
TfLiteStatus tflite::RecordingMicroAllocator::AllocateNodeAndRegistrations( const Model *model, SubgraphAllocations *subgraph_allocations)Allocates an array in the arena to hold pointers to the node and registration pointers required to represent the inference graph of the model.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
model | const Model * | Required | |
subgraph_allocations | SubgraphAllocations * | Required |
Allocates the list of persistent TfLiteEvalTensors that are used for the "eval" phase of model inference.
TfLiteStatus tflite::RecordingMicroAllocator::AllocateTfLiteEvalTensors( const Model *model, SubgraphAllocations *subgraph_allocations)Allocates the list of persistent TfLiteEvalTensors that are used for the “eval” phase of model inference. These structs will be the source of truth for all tensor buffers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
model | const Model * | Required | |
subgraph_allocations | SubgraphAllocations * | Required |
Allocates persistent tensor buffers for variable tensors in the subgraph.
TfLiteStatus tflite::RecordingMicroAllocator::AllocateVariables( const SubGraph *subgraph, TfLiteEvalTensor *eval_tensors, const int32_t *offline_planner_offsets)Allocates persistent tensor buffers for variable tensors in the subgraph. Online and offline variable tensors are handled differently hence the offline_planner_offsets parameter is needed.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
subgraph | const SubGraph * | Required | |
eval_tensors | TfLiteEvalTensor * | Required | |
offline_planner_offsets | const int32_t * | Required |
TODO(b/162311891): Once all kernels have been updated to the new API drop this method.
TfLiteTensor * tflite::RecordingMicroAllocator::AllocatePersistentTfLiteTensorInternal()TODO(b/162311891): Once all kernels have been updated to the new API drop this method. It is only used to record TfLiteTensor persistent allocations.
TODO(b/162311891): Once all kernels have been updated to the new API drop this function since all allocations for quantized data will take place in the temp se…
TfLiteStatus tflite::RecordingMicroAllocator::PopulateTfLiteTensorFromFlatbuffer( const Model *model, TfLiteTensor *tensor, int tensor_index, int subgraph_index, bool allocate_temp)TODO(b/162311891): Once all kernels have been updated to the new API drop this function since all allocations for quantized data will take place in the temp section.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
model | const Model * | Required | |
tensor | TfLiteTensor * | Required | |
tensor_index | int | Required | |
subgraph_index | int | Required | |
allocate_temp | bool | Required |