Skip to content

greedy_memory_planner

GreedyMemoryPlanner API

The GreedyMemoryPlanner class implements a greedy algorithm for memory allocation in the context of AOT (Ahead-Of-Time) compilation for machine learning models. It is designed to optimize memory usage by reusing gaps from tensors whose lifetimes have ended.

Classes:

  • GreedyMemoryPlanner

    Implements a greedy memory allocation strategy for tensors in a shared buffer.

Copyright 2025 Ambiq. All Rights Reserved.

Classes

GreedyMemoryPlanner

GreedyMemoryPlanner(operators: list[AotOperator], model: ModelT, subgraph: SubGraphT)

Functions

plan_memory
plan_memory() -> tuple[dict[int, int], int]

Allocate offsets for each tensor in a shared buffer using a first-fit algorithm that reuses gaps from tensors whose lifetimes have ended. This version also merges contiguous free blocks, and if the last free block aligns with the current offset, that block will be used for allocation.

Returns:

  • allocation ( dict ) –

    Mapping from tensor index -> offset (in bytes).

  • total_size ( int ) –

    Total buffer size required.

Functions