metrale_gpu_runtime/gpu/baseline.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-25: The free-memory baseline: free device memory after the backend is
4//! built and before weights load. It lives in
5//! `metrale_telemetry::run_metrics::RunMetrics::baseline_free_bytes`, which
6//! `reset_for_new_run` clears when a CUDA backend is built.
7//!
8//! Owner: gpu-runtime.
9//! Invariants: none beyond the types.
10
11use super::*;
12
13/// 2026-09-25: Record the free-memory baseline; the last call wins.
14pub fn set_baseline_free_bytes(bytes: usize) {
15 metrale_telemetry::run_metrics::metrics()
16 .baseline_free_bytes
17 .store(bytes, Ordering::Relaxed);
18}
19
20/// 2026-09-25: The recorded baseline, or `None` while it is unset (stored as 0).
21pub fn baseline_free_bytes() -> Option<usize> {
22 match metrale_telemetry::run_metrics::metrics()
23 .baseline_free_bytes
24 .load(Ordering::Relaxed)
25 {
26 0 => None,
27 v => Some(v),
28 }
29}