pdmlabs.energy.rapl_backend#

Raw Intel RAPL + NVML energy backend โ€“ highest fidelity, Linux + Intel only.

This is the backend the E-LQO paperโ€™s methodology corresponds to: direct hardware counters, no power model anywhere. It exists for two reasons โ€“ as the cross-check that validates the CodeCarbon backend, and for runs where the sampling-thread overhead of CodeCarbon is unwanted.

How it differs from CodeCarbon, and why that is sometimes better#

  • Counters, not samples. RAPL energy_uj and NVMLโ€™s nvmlDeviceGetTotalEnergyConsumption are monotonically accumulating registers. Reading them at the two ends of an interval yields the exact energy over that interval, with no sampling thread and no interpolation. A trial shorter than a sampling period is therefore measured exactly rather than approximated โ€“ the failure mode that forces CodeCarbonโ€™s quality="low" flag simply does not arise.

  • No CO2 conversion of its own. Carbon intensity is supplied by the caller (carbon_intensity_g_per_kwh) rather than looked up, so the number is explicit and auditable instead of depending on a bundled tableโ€™s vintage.

Domain arithmetic โ€“ the trap#

package-N already includes its core and uncore children. Summing package + core + uncore double-counts almost everything. CPU energy is therefore the sum over package domains only (plural: a dual-socket node has intel-rapl:0 and intel-rapl:1), and dram, where present, is a sibling rail added separately.

Counter wraparound#

energy_uj wraps at max_energy_range_uj (262 kJ on an i9-12900K: one wrap per ~18 min at its 241 W PL2; ~65 kJ on some parts). Two reads can undo at most one wrap, and a SEARCH phase routinely spans many, so a background sampler reads every domain at least 4x per worst-case wrap period (poll_s, default 10 s, capped at range / 1000 W / 4) and folds wrap-corrected deltas into monotonic totals; phase and task energies are differences of those totals. A read gap longer than one worst-case wrap period stamps the reading low.

Functions

discover_rapl()

Map the readable RAPL topology.

Classes

RaplBackend([gpu_ids,ย ...])

class pdmlabs.energy.rapl_backend.RaplBackend(gpu_ids=None, carbon_intensity_g_per_kwh=None, poll_s=10.0, power_ceiling_w=None, **_extra)#

Bases: BaseEnergyBackend

POWER_CEILING_W = 1000.0#

Power no single RAPL domain can exceed; far above real parts (the i9-12900Kโ€™s PL2 is 241 W) so the derived poll period stays safe.

name: str = 'rapl'#
probe()#

Report what this backend can actually measure, without measuring.

Returns a dict with at least power_source_cpu, power_source_gpu, ram_source and available (bool). Called by the preflight gate.

shutdown()#

Release any long-lived resource. Idempotent.

start_phase(label)#
start_task(label)#
stop_phase()#
stop_task(token=None)#
pdmlabs.energy.rapl_backend.discover_rapl()#

Map the readable RAPL topology.

Returns {"packages": [...], "dram": [...], "readable": bool} where each entry is {"path", "name", "max"}.