Loading...
Searching...
No Matches
energy_meter.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2026 Artificial Intelligence Techniques, S.L. and Roberto López González
3
4#pragma once
5
7{
8
9// Board power over a window, read through NVML, for the autotuners that
10// choose between kernels of comparable speed by what they cost to run.
11//
12// NVML is loaded at run time (libnvidia-ml.so.1 ships with the driver, not
13// the toolkit), so the library links nothing extra and a machine without a
14// working NVML simply reports the meter unavailable, which the callers treat
15// as "choose by time alone". The device is matched to the current CUDA
16// device by PCI bus id, not by index: NVML and CUDA enumerate GPUs in
17// different orders.
18//
19// The reading is the driver's own power sample ring (nvmlDeviceGetSamples,
20// one sample per ~20 ms), averaged over the samples that fall inside the
21// window, rather than the cumulative energy counter, which this GeForce
22// reports as zero, or nvmlDeviceGetPowerUsage, which is a one-second
23// average and cannot tell two kernels apart. A window needs to hold several
24// samples to mean anything; energy_meter_window_watts() reports how many it
25// held so the caller can refuse a reading that is too thin.
26bool energy_meter_available() noexcept;
27
28// A timestamp marking the start of a window, in NVML's clock (microseconds).
29unsigned long long energy_meter_begin() noexcept;
30
31// Mean board power in watts over the samples taken since `begin`, and the
32// number of samples that mean rests on. Returns 0 W with 0 samples when the
33// meter is unavailable or the ring held nothing newer than `begin`.
34double energy_meter_window_watts(unsigned long long begin, int& samples) noexcept;
35
36}
Definition energy_meter.h:7
bool energy_meter_available() noexcept
unsigned long long energy_meter_begin() noexcept
double energy_meter_window_watts(unsigned long long begin, int &samples) noexcept