Module energy

Module energy 

Source
Expand description

2026-09-26: Energy attribution: the NVML counter’s deltas, paired with the tokens produced over the same interval.

Two cumulative totals are kept, GPU-rail millijoules and tokens, and sampled together into EnergyRing. Every ratio is formed from differences of those totals: J/token over the last crate::hub::LIVE_WINDOW samples, J/token since the first sample, and a request’s energy (its token share of its lifetime window). No ratio is accumulated.

The sampler thread reads the counter at the device cadence, not per scheduler step, so a window’s ΔE/Δtokens is exact up to one sample period at each edge. A backwards step is a wrap or a reset; CounterTracker::advance tells them apart.

Owner: telemetry. Invariants: none beyond the types.

Structs§

CounterTracker
2026-09-26: Turns raw counter readings into non-negative deltas.
EnergyPoint
2026-09-26: One ring point: cumulative energy and tokens at one sample instant.
EnergyRing
2026-09-26: The sampled (time, energy, tokens) series. push assumes one writer (the sampler thread); any number of readers read without a lock.

Enums§

Advance
2026-09-26: What one counter reading did to the running total.

Constants§

RING_SLOTS
2026-09-26: Ring capacity: 8192 samples, ~13.6 minutes at the 10 Hz serving cadence. A request older than the ring is attributed from the oldest point it still holds.

Functions§

joules_per_token
2026-09-26: GPU-rail joules per token for a (ΔmJ, Δtokens) pair. None when either is 0, so the result is never 0 or ∞.
request_millijoules
2026-09-26: Millijoules attributed to a request that emitted tokens over [start_ns, end_ns]: its share, by tokens, of the energy counted over that window. None when the ring is empty or the window saw no tokens.