greedy_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
Greedy memory planner for AOT models.
Functions
plan
plan(model: AirModel, memory_constraints: list[MemoryConstraint] | None = None, tensor_constraints: list[AttributeRuleset] | None = None) -> MemoryPlan
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.
Parameters:
-
model
AirModel
) –The target model.
-
memory_constraints
list[MemoryConstraint] | None
, default:None
) –Memory constraints
-
tensor_constraints
list[AttributeRuleset] | None
, default:None
) –Tensor constraints
Returns:
-
MemoryPlan
(MemoryPlan
) –The memory plan containing tensor allocations and arena usages.