pub struct MemoryPressureMonitor { /* private fields */ }Expand description
Monitors device memory pressure and drives reactive trim / eviction.
Construct with new supplying the warning and critical used
fractions. Optionally attach an eviction hook with
on_eviction and a transition callback with
on_transition. Feed samples via
observe (synthetic) or poll (live GPU).
Implementations§
Source§impl MemoryPressureMonitor
impl MemoryPressureMonitor
Sourcepub fn new(warning_fraction: f64, critical_fraction: f64) -> CudaResult<Self>
pub fn new(warning_fraction: f64, critical_fraction: f64) -> CudaResult<Self>
Creates a monitor with the given warning and critical used-fraction thresholds.
Both fractions must lie in (0.0, 1.0] and warning_fraction must be
strictly less than critical_fraction.
§Errors
CudaError::InvalidValueif either threshold is non-finite, outside(0.0, 1.0], or ifwarning_fraction >= critical_fraction.
Sourcepub fn on_eviction<F>(self, hook: F) -> Self
pub fn on_eviction<F>(self, hook: F) -> Self
Attaches an eviction hook fired whenever the monitor enters the
critical level. The hook returns the number of bytes it reclaimed,
which is accumulated into total_evicted.
Builder-style; returns self for chaining.
Sourcepub fn on_transition<F>(self, hook: F) -> Self
pub fn on_transition<F>(self, hook: F) -> Self
Attaches a callback fired on every level transition (escalation or de-escalation).
Builder-style; returns self for chaining.
Sourcepub fn warning_fraction(&self) -> f64
pub fn warning_fraction(&self) -> f64
The warning used-fraction threshold.
Sourcepub fn critical_fraction(&self) -> f64
pub fn critical_fraction(&self) -> f64
The critical used-fraction threshold.
Sourcepub fn level(&self) -> PressureLevel
pub fn level(&self) -> PressureLevel
The current pressure level (state from the most recent sample).
Sourcepub fn total_evicted(&self) -> usize
pub fn total_evicted(&self) -> usize
Total bytes reclaimed by the eviction hook over this monitor’s lifetime.
Sourcepub fn eviction_count(&self) -> u64
pub fn eviction_count(&self) -> u64
Number of times the eviction hook has fired.
Sourcepub fn classify(&self, used_fraction: f64) -> PressureLevel
pub fn classify(&self, used_fraction: f64) -> PressureLevel
Classifies a used_fraction (0.0–1.0) into a PressureLevel using
this monitor’s thresholds.
The comparison is inclusive at the threshold (a fraction exactly equal
to the critical threshold is Critical).
Sourcepub fn observe(&mut self, info: MemoryInfo) -> PressureLevel
pub fn observe(&mut self, info: MemoryInfo) -> PressureLevel
Feeds a synthetic memory sample through the monitor and returns the new level.
On a transition the transition callback (if any) fires. On entering the critical level the eviction hook (if any) fires and its return value is accumulated. Re-observing the same level does not re-fire hooks.
Sourcepub fn poll(&mut self) -> CudaResult<PressureLevel>
pub fn poll(&mut self) -> CudaResult<PressureLevel>
Polls live device memory via crate::memory_info::memory_info and
feeds the sample through observe.
§Errors
Forwards any error from the memory-info query (e.g. no current context).