Skip to main content

Module memory_planner

Module memory_planner 

Source
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

  1. Liveness Analysis: Track first/last appearance of each buffer in schedule
  2. Event Timeline: Create sorted alloc/free events (frees before allocs at same step)
  3. Pool-Based Allocation: Reuse buffers by (device, dtype, size) key
  4. Apply Replacements: Map logical buffers to physical buffers

Structs§

BufferKey
Key to identify a buffer within a schedule.
BufferLiveness
Liveness information for a buffer.
BufferPoolKey
Key for buffer pooling - groups buffers that can be reused interchangeably.
MemoryPlannerResult
Result of memory planning.
ReuseDependency
Schedule-order dependency introduced by a physical buffer reuse.

Enums§

PlannerMode
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_PLANNER from the environment and resolve to a PlannerMode.
parse_mode
Pure parser for the SVOD_MEMORY_PLANNER env var, exposed for testing.