﻿# Preserve the driver epoch when differencing NVML energy counters

Subtract NVML energy readings only across a verified device and driver epoch, retaining query status, time boundaries and useful-work counts.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-perf-nvml-energy-counter-epoch/
Language: en

An energy report becomes negative after a maintenance window. The workload did not generate electricity: the measurement subtracted values from different counter lifetimes. NVML exposes a cumulative device energy reading whose origin is the last driver reload. A meaningful interval needs successful readings for the same device within an established driver epoch.

## Keep identity with the reading

Store the GPU UUID with each sample rather than relying on enumeration position. NVIDIA documents that enumeration order can change across boots. A collector restarted on a different device index can otherwise subtract unrelated counters without producing an obvious type error. Preserve driver information and the collection context alongside the numerical value so maintenance events can be investigated later.

## Preserve the counter epoch

The total-energy query reports millijoules accumulated since driver reload. A reload therefore breaks an interval spanning that boundary. Reject a decreasing delta instead of presenting negative energy or blindly treating it as a counter wrap. An increasing value alone does not prove epoch continuity: evidence of maintenance or collector gaps can still make the endpoints incomparable.

## Retain query outcomes

The API can report unsupported readings or an inaccessible device. Store status separately from the output value and require successful endpoints before subtraction. Filling an unsupported value with zero fabricates energy behavior and can create a large false increase on recovery. Support is a documented device capability, not something established by finding the function in a loaded library.

## Align time and work

Use a suitable monotonic clock to record observation intervals, with wall time retained for maintenance correlation. Record the completed useful work in the same interval, including the chosen treatment of failures. The energy counter describes the GPU device population, including concurrent work. It does not isolate the inference process or include the entire host merely because the requests ran on that host.

## Report invalid intervals honestly

Keep the raw endpoints, units, statuses and reason an interval was excluded. Start a fresh interval after reestablishing identity and epoch continuity. This prevents silently joining readings across a driver event. The resulting device-energy-per-work estimate still needs an explicit workload boundary; it is not automatically marginal request energy or a comparison of whole-system electrical efficiency.

## Primary references

[NVML Device Energy Counter and Identity Queries](https://docs.nvidia.com/deploy/nvml-api/latest/api/group__nvmlDeviceQueries.html).

[NVIDIA System Management Interface Device Identification](https://docs.nvidia.com/deploy/nvidia-smi/index.html).

[Linux clock_gettime Clock Semantics](https://man7.org/linux/man-pages/man2/clock_gettime.2.html).

Related reading: [Energy per LLM request: measuring without false precision](/journal/measuring-energy-per-inference/); [GPU power caps: an energy and latency experiment](/journal/gpu-power-cap-latency-frontier/).
