Expand description
Memory planner for buffer reuse optimization.
This module implements liveness-based memory planning following Tinygrad’s approach. The memory planner analyzes buffer lifetimes across the schedule and reuses buffers with non-overlapping lifetimes, reducing memory consumption.
§Algorithm
- Liveness Analysis: Track first/last appearance of each buffer in schedule
- Event Timeline: Create sorted alloc/free events (frees before allocs at same step)
- Pool-Based Allocation: Reuse buffers by (device, dtype, size) key
- Apply Replacements: Map logical buffers to physical buffers
Structs§
- Buffer
Key - Key to identify a buffer within a schedule.
- Buffer
Liveness - Liveness information for a buffer.
- Buffer
Pool Key - Key for buffer pooling - groups buffers that can be reused interchangeably.
- Memory
Planner Result - Result of memory planning.
- Reuse
Dependency - Schedule-order dependency introduced by a physical buffer reuse.
Enums§
- Planner
Mode - Selects the buffer-allocation strategy used by the planner entrypoint.
Functions§
- apply_
buffer_ replacements - Apply buffer replacements to the schedule.
- apply_
reuse_ dependencies - Add execution-order edges required by physical buffer reuse.
- memory_
planner - Run memory planner on a schedule.
- mode_
from_ env - Read
SVOD_MEMORY_PLANNERfrom the environment and resolve to aPlannerMode. - parse_
mode - Pure parser for the
SVOD_MEMORY_PLANNERenv var, exposed for testing.