Skip to main content

Module sysmem

Module sysmem 

Source
Expand description

Best-effort host physical-memory queries for proactive load pre-flight.

cera’s weight and KV-cache allocations are infallible (Vec::with_capacity / owned-buffer reads), so loading a model larger than available RAM aborts the process rather than returning an error. A benchmark harness that runs many models on constrained devices (e.g. Pipette on Android) uses these helpers to estimate the fit and skip an over-large model before loading, instead of crashing.

Best-effort by design: available_memory_bytes returns None on platforms where it can’t query (currently everything except Linux/Android), and the caller decides whether to proceed. Converting the abort itself into a recoverable Err at the allocation site is deliberately out of scope — that needs fallible allocation (try_reserve) threaded through the load path.

Functions§

available_memory_bytes
Currently-available physical memory in bytes, or None when it can’t be determined on this platform.
fits_in_available_memory
Whether required_bytes fits in currently-available physical memory leaving at least headroom_bytes free. None when available memory can’t be queried (see available_memory_bytes) — the caller then decides whether to proceed.