GpuMonitor class
#include <gtopt/gpu_monitor.hpp>
NVML-backed GPU monitor. Loads libnvidia-ml.so.1 lazily; if absent it degrades to a no-GPU monitor (never throws, never a build dep).
Base classes
- class GpuMonitorBase
Public types
- struct Nvml
- dlopen'd NVML function table + cached per-device handles (pimpl).
Public static functions
- static auto probe_device_count() -> int noexcept
Constructors, destructors, conversion operators
- GpuMonitor() defaulted
- GpuMonitor(const GpuMonitor&) deleted
- GpuMonitor(GpuMonitor&&) deleted
- ~GpuMonitor() override
Public functions
- auto device(int index) const -> std::optional<GpuDeviceState> override noexcept
- Live state of device
index, or nullopt if out of range / no NVML. - auto device_count() const -> int override noexcept
- Number of visible CUDA devices (0 when !has_gpu()).
- auto get_interval() const -> auto noexcept
- auto has_gpu() const -> bool override noexcept
- True only when a GPU backend is usable: NVML loaded AND >=1 device.
- auto least_loaded_device() const -> std::optional<int> override noexcept
- void notify_stop() noexcept
- auto operator=(const GpuMonitor&) -> GpuMonitor& deleted
- auto operator=(GpuMonitor&&) -> GpuMonitor& deleted
- void request_stop() noexcept
- void set_interval(std::chrono::milliseconds interval) noexcept
- void start()
- void stop() noexcept
Function documentation
static int gtopt:: GpuMonitor:: probe_device_count() noexcept
One-shot device-count probe WITHOUT starting a monitor thread: dlopen NVML, count devices, shut NVML down again. 0 when NVML/GPU is absent. Used by ResourceGovernor's lazy auto-configuration to size the GPU token buckets exactly once per process.
std::optional<int> gtopt:: GpuMonitor:: least_loaded_device() const override noexcept
Ordinal of the device with the most free VRAM (multi-GPU assignment), or nullopt when no device is visible.
void gtopt:: GpuMonitor:: request_stop() noexcept
Signal the sampling thread to wind down without joining (Phase-1 helper used by the pool's shutdown, mirroring CPUMonitor::request_stop).
void gtopt:: GpuMonitor:: start()
Initialise NVML (once) and start the background sampling thread. Safe to call when NVML is unavailable — leaves the monitor in the no-GPU state. Idempotent.