ResourceGovernor class
#include <gtopt/resource_governor.hpp>
Public types
- class Ticket
Public static functions
- static auto instance() -> ResourceGovernor& noexcept
- Process-global instance shared across every work pool.
Constructors, destructors, conversion operators
- ResourceGovernor(const ResourceGovernor&) deleted
- ResourceGovernor(ResourceGovernor&&) deleted
- ~ResourceGovernor() defaulted
Public functions
- void configure(int device_count, int gpu_concurrency_per_device = 1) noexcept
- auto device_count() const -> int noexcept
- Number of configured GPU devices.
- auto gpu_available() -> bool noexcept
- auto gpu_capacity() const -> int noexcept
- Total GPU tokens across all devices (0 when GPU gating is disabled).
- auto gpu_in_use() const -> int noexcept
- Currently-held GPU tokens (for tests / diagnostics).
- auto operator=(const ResourceGovernor&) -> ResourceGovernor& deleted
- auto operator=(ResourceGovernor&&) -> ResourceGovernor& deleted
- auto try_admit(ResourceClass cls) -> Ticket noexcept
Function documentation
void gtopt:: ResourceGovernor:: configure(int device_count,
int gpu_concurrency_per_device = 1) noexcept
(Re)size the GPU token buckets: device_count devices, each with gpu_concurrency_per_device tokens (clamped to >= 0 / >= 1). device_count == 0 disables GPU gating (all tasks admit). Safe to call once at startup; any in-flight tickets keep their prior device index valid (release is index-checked).
bool gtopt:: ResourceGovernor:: gpu_available() noexcept
Non-consuming dispatch-gate check: true when a GPU token is free OR GPU gating is disabled (no devices / never configured). The pool's can_dispatch_task uses this to throttle GPU-class tasks; the real acquisition happens post-pop via try_admit (race-tolerant: an empty ticket there means "execute anyway" — the backend's own serialization mutex still carries correctness).
Ticket gtopt:: ResourceGovernor:: try_admit(ResourceClass cls) noexcept
Try to admit one task of class cls. CPU tasks always admit (no token). GPU tasks admit iff some device has a free token (P1 will also project VRAM); the returned ticket carries the least-loaded such device.
Lazily auto-configures on the first GPU query: probes the NVML device count once (GpuMonitor::probe_device_count) and mints GTOPT_GPU_CONCURRENCY tokens per device (env, default 1 — Default compute mode time-slices contexts, so >1 buys nothing without MPS).