#[non_exhaustive]pub struct MemoryStats {
pub active: usize,
pub peak: usize,
pub active_with_mapped: usize,
pub peak_with_mapped: usize,
pub cache: usize,
pub memory_limit: usize,
pub cache_limit: usize,
pub system_allocations: u64,
pub wired_limit: usize,
pub wired: usize,
pub mapped: usize,
pub wired_mapped: usize,
}Expand description
Memory use and limits of a device’s allocator, in bytes.
peak_with_mapped is nuvec’s one peak-memory metric: compare it with MLX’s
get_peak_memory() (which counts MLX’s copied weights), each reset after loading, in a
fresh process per phase, cross-checked by the operating system’s peak resident size.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.active: usizeBytes in live allocator buffers (rounded allocation sizes), weights copied from
checkpoints included; mapped files not included. MLX: get_active_memory.
peak: usizeThe highest active since creation or the last Device::reset_peak; mapped files
not included.
active_with_mapped: usizeactive + mapped: everything the allocator holds for live arrays, mapped
checkpoints included. MLX: get_active_memory (MLX copies every weight, so its
active memory includes them).
peak_with_mapped: usizeThe highest active + mapped since creation or the last Device::reset_peak,
updated on every change of either: the one peak metric (see above). MLX:
get_peak_memory.
cache: usizeBytes held in the cache for reuse (not in active). MLX: get_cache_memory.
memory_limit: usizeAllocations and mappings that would push active + mapped past this fail with
OutOfMemory (a hard refusal; MLX’s set_memory_limit is a guideline).
cache_limit: usizeThe cache is trimmed to at most this many bytes. MLX: set_cache_limit.
system_allocations: u64Buffers obtained from Metal (cache misses) so far.
wired_limit: usizeBuffers and mapped files are kept resident up to this many bytes (see
Device::set_wired_limit; MLX: set_wired_limit).
wired: usizeBytes currently wired, mapped files included (wired ≤ wired_limit).
mapped: usizeBytes of live memory-mapped files (checkpoints loaded without a copy): each file’s
whole length, header included, rounded up to pages. Not in active or peak. MLX
does not map files.
wired_mapped: usizeThe part of wired that belongs to memory-mapped files.