gpuprobe

package
v0.206.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gpuprobe is the LEAF that owns the machine's live GPU and host-RAM readers: the nvidia-smi per-device query (its command line, its PATH fallback, its CSV parser) and the free-host-RAM reader. It imports nothing from the rest of the harness so that BOTH the fleet node's health sampler (internal/fleetnode) and the composite tier's placement guards (internal/placement) read the same numbers through the same parser — one parser, one set of pins, no second "nvidia-smi reader" that could disagree with the first about what a card's free memory is. ADR 0052 / plan Task 4.

Index

Constants

View Source
const DefaultHostRAMHeadroomGiB = 8.0

DefaultHostRAMHeadroomGiB is the host RAM the admission rule keeps uncommitted beyond what a lease declares (config gpu_host_ram_headroom_gib, 0 = this). It is the room the desktop, the agents and the kernel's own growth need while a lease loads. The incident box's non-media baseline was 56 GiB of desktop apps, agent CLIs, browsers, WSL and kernel pools, and that baseline moves by several GiB inside a minute, so 8 is the floor, not a measurement of any one job.

CHOSEN 2026-10-09 by the harness session, NOT MEASURED, and not a number the operator typed. What it stands in for is each node's interactive working-set swing, which has not been measured yet: the measurement procedure, the data points so far and the table that takes `measured <date> <node> n=<k>` rows are in docs/systems/gpu-lease.md ("How the numbers get measured"). The config key is the override and the thing to change when a node's own measurement says so.

View Source
const HostMemorySupported = hostRAMSupported

HostMemorySupported says whether this platform has a reader at all (Windows and Linux do). On a platform without one the admission rule cannot judge and admits, rather than refusing every lease for a number nobody can take; on a platform with one, an unreadable reading refuses.

Variables

This section is empty.

Functions

func DisplayCardUUIDs

func DisplayCardUUIDs(devices []Device) map[string]bool

DisplayCardUUIDs returns, by UUID, the cards driving a display IN USE (display_active Enabled: a game or a lit screen has initialised one) — the ones the 3-card law forbids seats from using, so utilization on them is never the harness's own work. It answers "whose load is this": the node's work_util_pct, the lease verdict, the foreign-load guard and the delegator's free-card count read it. It deliberately does NOT read display_attached, which is true for the whole life of the box and would hide the node's own work on that card.

The guard matters as much as the rule: a box whose ONLY card is its display card runs its seats there by necessity (a single-GPU desktop, an iGPU node). Excluding it would leave that box with no card left to score, so a display card is only ever excluded when at least one non-display card exists.

A nil result means "exclude nothing" — which is also what a driver that does not report display_active yields, because absent evidence is never a yes.

func FreeGiB

func FreeGiB(devs []Device, key string) (float64, bool)

func HostFreeRAMGiB

func HostFreeRAMGiB() (float64, bool)

HostFreeRAMGiB reports the host's free (available-to-allocate) physical RAM in GiB. The composite tier's `host_ram` guard needs it because the triple layer's MoE seats hold tens of GB of experts in system RAM (--n-cpu-moe): VRAM headroom alone says nothing about whether such a seat can load, and a load that pushes the host into swap stalls every other seat on the box. Windows reads kernel32.GlobalMemoryStatusEx (AvailPhys), Linux /proc/meminfo MemAvailable; any other platform — or a failed read — returns ok=false so the guard fails CLOSED rather than admitting on a number it never had.

It is the available-RAM half of ReadHostMemory (hostmemory.go), which also carries the commit charge the lease admission rule reads (HostRAMAdmits): the same reading, so a seat's guard and a lease's gate cannot be looking at two different host states.

func IndexOf

func IndexOf(devs []Device, key string) (string, bool)

FreeGiB finds one device by the key a config pins it with and returns its free memory. key is either a bare nvidia-smi index ("1") or a UUID prefix ("GPU-8888bbbb" or the full UUID), compared case-insensitively — <node-b>'s live config pins the display card by UUID because the board reorders indices on power loss, while a plain box pins by index, and one lookup must serve both. The bool is the ONLY honest answer for "not found": a guard that read an absent card as 0 GiB would refuse every load, one that read it as unbounded would admit onto a card it cannot see, so the caller must treat !ok as "refuse" (the guards fail closed). An empty key, an index no device carries, or a UUID prefix that matches MORE than one card (ambiguous — "GPU-" matches every card) is !ok. IndexOf resolves a device key — a CUDA index or a GPU-UUID prefix — to the CUDA index nvidia-smi reports for it. Ambiguous (a prefix matching two cards) or absent = !ok, so a caller refuses rather than guessing which card an operator's UUID meant. It exists because a display card is pinned by UUID on a board that reorders indices on power loss, while a seat is pinned by index: the two must be compared in one space.

func MergeThermal

func MergeThermal(devs []Device, rows []Thermal)

MergeThermal copies each row's values onto the device with the same UUID. It matches by UUID, never by index: an index is only stable until the board reorders, and a thermal figure on the wrong card is worse than none. A device no row names is left as it is, and so is a row no device names. The values are copied, so a device edited later cannot reach the rows a caller keeps.

func NvidiaSmiRunner

func NvidiaSmiRunner() func() (string, error)

NvidiaSmiRunner returns the function that shells the per-device query — the exact command fleet-serve's health sampler has always run — resolving nvidia-smi from PATH first and, on Windows, falling back to C:\Windows\System32\nvidia-smi.exe: a service/task principal (the fleet node runs as a scheduled task) can carry a PATH without the driver's directory even though the binary is installed, and "nvidia-smi not found" on a box with three NVIDIA cards would fail every display-card guard closed forever. The lookup happens per call, not at construction, so a driver install after the harness started is picked up.

func ResetDisplayAwareState

func ResetDisplayAwareState()

ResetDisplayAwareState forgets that a driver refused display_attached, so the next query tries the full one again. A test seam for packages whose tests stub nvidia-smi; production never calls it.

func ResetThermalState

func ResetThermalState()

ResetThermalState forgets which variant of the thermal query worked. A test seam; production never calls it.

func RunDisplayAware

func RunDisplayAware(run func(withAttached bool) (string, error)) (string, error)

RunDisplayAware runs the per-device query with display_attached and, when the driver refuses it, the same query without. See RunDisplayAwareReport; this is the form for a caller that does not need to know which of the two it got.

func ScreenCardIndexes

func ScreenCardIndexes(devs []Device) []string

ScreenCardIndexes lists, as nvidia-smi indices in the order the probe lists them, the cards the driver says drive a monitor: display_active Enabled OR display_attached Yes (Device.DrivesDisplay, the placement rule). It is how the display_floor guard learns that the card a config NAMES is not the card the screen is on (the board reorders on a power loss, a cable moves): the guard contradicts a declaration on this evidence, never assumes one from it.

So it answers only when the reading can: nil when no card drives a display (headless, or the screen is on an iGPU), and nil when any device of the reading is AttachedUnknown (the query that carries display_attached failed once, so the reading cannot tell the monitor's card from the others, and a display_active that happens to read Enabled is not evidence either). Several cards are named when several drive a display; a declared card among them is not contradicted.

func ScreenCardUUIDs

func ScreenCardUUIDs(devices []Device) map[string]bool

ScreenCardUUIDs returns, by UUID, the cards the operator's screen is on or can be on: display_active Enabled OR display_attached Yes (Device.DrivesDisplay). It answers "may a render be PLACED on this card": the card table (BuildCards) and so the allocator read it, and the monitor's card is never auto-picked, with the screen asleep as with it lit. The same single-card guard applies as in DisplayCardUUIDs.

func ThrottleReasonNames

func ThrottleReasonNames(mask uint64) []string

ThrottleReasonNames names the bits set in an NVML clock event reasons mask, lowest bit first. Idle is not listed; a bit this table does not know comes out as unknown:0x<bit>. A mask with nothing to say is nil.

func UseHostMemoryReader

func UseHostMemoryReader(fn func() (HostMemory, bool)) (restore func())

UseHostMemoryReader makes ReadHostMemory call fn until restore is called. It exists for tests of the packages that take a lease (a stand-in host with a known commit charge, so a test result does not depend on what the machine running it is doing); production code never calls it.

Types

type AttachedState

type AttachedState int

AttachedState says what one reading knows about display_attached.

const (
	// AttachedRead: the full query ran, and the output carries display_attached.
	AttachedRead AttachedState = iota
	// AttachedUnsupported: the driver does not give the field (it refused it, or has failed
	// the full query so often that it is treated as refusing). The display rule rests on
	// display_active alone, as it did before the field was read.
	AttachedUnsupported
	// AttachedUnknown: the full query failed once for a reason that does not name the field.
	// This reading carries no display_attached, and it is NOT because the driver lacks it, so
	// the card the monitor is plugged into cannot be told from the others by it.
	AttachedUnknown
)

func RunDisplayAwareReport

func RunDisplayAwareReport(run func(withAttached bool) (string, error)) (string, AttachedState, error)

RunDisplayAwareReport is RunDisplayAware that also says what the reading knows about display_attached. run(true) must run the full query and run(false) the fallback; both readers of the card table (this package's Read and the lease verdict's sampler in gpuactivity) go through here so they degrade the same way.

WHAT ARMS THE DEGRADE. Only a failure of the full query that names the field (the driver refusing it), or attachedRefusalLimit unexplained failures in a row, makes the full query be skipped for attachedRetryEvery, and the downgrade is logged once when it is armed. Any other failure answers THIS call from the fallback and is remembered by nobody: display_attached is the only signal that marks the monitor's card while the screen sleeps, so one transient nvidia-smi error must not cost ten minutes of it. That one reading says so (AttachedUnknown). When both queries fail nvidia-smi itself is the problem: the full query's error is returned and nothing is remembered.

type Card

type Card struct {
	// UUID is the card's nvidia-smi UUID as reported ("GPU-..."). LeaseID is the form a
	// lease records.
	UUID         string  `json:"uuid"`
	NvidiaIndex  int     `json:"index"`
	Name         string  `json:"name"`
	Display      bool    `json:"display"`
	VRAMTotalGiB float64 `json:"vram_total_gb"`
	VRAMFreeGiB  float64 `json:"vram_free_gb"`
	UtilPct      int     `json:"util_pct"`
	UtilKnown    bool    `json:"util_known"`
	// ComfyOrder is the card's position in CUDA's FASTEST_FIRST order (what ComfyUI's
	// --cuda-device counts), or -1 when it is not known. See the file comment.
	ComfyOrder int `json:"comfy_order"`
	// DisplayUnknown marks a card of a reading that could not say which card the monitor is
	// on (Device.AttachedUnknown). The allocator does not auto-assign such a card: "unknown" is
	// never "not the operator's screen".
	DisplayUnknown bool `json:"display_unknown,omitempty"`
}

Card is one GPU as the card table sees it.

func BuildCards

func BuildCards(devs []Device, comfyOrder string) (cards []Card, warn string)

BuildCards turns parsed nvidia-smi devices into the card table. Display is the placement rule, ScreenCardUUIDs (a box whose only card is its display card excludes nothing). comfyOrder is the operator's declaration of ComfyUI's order, a comma list of nvidia indices or UUID prefixes with the fastest card first ("" = not declared). A spec that does not name every card exactly once is rejected as a whole: warn says why and every ComfyOrder stays unknown, because half an order answers no question.

func CardByComfyOrder

func CardByComfyOrder(cards []Card, n int) (Card, bool)

CardByComfyOrder finds the card at a ComfyUI/FASTEST_FIRST position. ok is false when no card carries that position, which includes every card when the order is unknown.

func ReadCards

func ReadCards(ctx context.Context, comfyOrder string) ([]Card, string, error)

ReadCards runs the nvidia-smi per-device query and builds the card table.

func ResolveCards

func ResolveCards(cards []Card, keys []string) ([]Card, error)

ResolveCards maps keys to cards, in key order. A key is a nvidia-smi index (all digits) or a UUID prefix (at least four characters after an optional "GPU-"), compared case-insensitively. A key that matches no card, matches several, or names a card a second time is an error: a lease that silently landed on the wrong card is the defect this table exists to prevent.

func (Card) LeaseID

func (c Card) LeaseID() string

LeaseID is the form a lease records for this card: the UUID lower-cased (a claim is one file per card, and the file system may be case-insensitive).

type Device

type Device struct {
	Index    int     `json:"index"`
	UUID     string  `json:"uuid"`
	Name     string  `json:"name"`
	TotalGiB float64 `json:"vram_total_gb"`
	FreeGiB  float64 `json:"vram_free_gb"`
	// UtilPct is nvidia-smi utilization.gpu (0-100) when the query carried it.
	// UtilKnown distinguishes "0 %" from "not queried" (a 5-field line from an
	// older launcher); consumers must never treat an unknown as idle.
	UtilPct   int  `json:"util_pct"`
	UtilKnown bool `json:"util_known"`
	// DisplayActive is nvidia-smi's display_active for this card: whether a
	// display is attached and being driven by it. It is the DIRECT answer to
	// "is this the operator's screen" — the property itself, not an inference
	// from which processes happen to be visible — and it costs no extra
	// nvidia-smi call because it rides the one per-device query every reader
	// already runs. False for a driver that does not report it and for a line
	// from an older launcher that lacks the column: absent is never "yes".
	DisplayActive bool `json:"display_active,omitempty"`
	// DisplayAttached is nvidia-smi's display_attached: a physical monitor is
	// connected to one of this card's connectors. It is the signal that holds at the
	// desk, because display_active reads Disabled on every card of the 3-card box
	// unless a display is initialised (a game, a lit screen) while display_attached
	// stays Yes on the card that drives the monitor (measured 2026-10-03). Absent is
	// never "yes": a driver without the field, and a line from the older query,
	// leave it false. Read it through DrivesDisplay (the placement rule), never on its own.
	DisplayAttached bool `json:"display_attached,omitempty"`
	// AttachedUnknown is set on every device of a reading that carries no display_attached
	// because the full query FAILED for a reason that does not name the field (a transient):
	// the reading cannot say which card the monitor is on. A driver that refuses the field has
	// no such mark (the rule rests on display_active alone, as it always did).
	AttachedUnknown bool `json:"attached_unknown,omitempty"`
	// TemperatureC is nvidia-smi temperature.gpu in degrees C and ThrottleReasons the clock event reasons
	// active when it was read (the NVML bits, named: ThrottleReasonNames). Neither rides the per-device query
	// above: ReadThermal asks for them in a second, optional query, so an old driver that refuses a thermal
	// column can never take the memory reading down with it. Absent is never "cool" and never "not throttled":
	// the query failed, was not due, or the driver answered [N/A] or [Not Supported] for the card (or has no
	// throttle field at all). A card read with nothing limiting its clocks (no reason beyond idle) publishes an
	// EMPTY array, so "read, none active" is told from "not read": ThrottleReasons is nil for the second and a
	// non-nil empty slice for the first, which is why the tag is omitzero (omitempty would drop both). A pointer
	// for the temperature, so a reading is told from none.
	TemperatureC    *int     `json:"temperature_c,omitempty"`
	ThrottleReasons []string `json:"throttle_reasons,omitzero"`
}

Device is one parsed nvidia-smi device line: the index/uuid/name nvidia-smi itself reports plus its GiB memory figures. JSON tags match the gpu_devices[] shape documented in docs/FLEET-NODE.md (fleetnode.GPUDevice is an alias of this type, so the health payload's wire shape is unchanged by the move). UUID is what primary_gpu_uuid — and the composite tier's display-card pin — match against: an index is only stable until the board reorders on a power loss, the UUID is burned into the card.

func HeadlineDevice

func HeadlineDevice(devices []Device) Device

HeadlineDevice picks which parsed device a single vram_total_gb/vram_free_gb pair describes. A single render job binds to exactly ONE CUDA device — so the admission-relevant number is the biggest device a job could actually land on, never an arbitrary enumeration index. That distinction is the whole bug this fixes: nvidia-smi enumerates in PCI bus order, which has no relationship to which device a CUDA app actually computes on (CUDA_DEVICE_ORDER=FASTEST_FIRST can bind cuda:0 to nvidia-smi index 1) — "index 0 wins" was an artifact of enumeration order dressed up as a measurement, and it silently mis-sizes admission whenever the compute card isn't index 0.

Rule: the device with the LARGEST TotalGiB wins. An exact tie in total is broken by whichever has more FreeGiB right now (more headroom to admit a job against). This is deliberately NOT a sum across devices — summing free VRAM would let the dispatcher admit a job that no single card can actually hold, since a render binds to one device, not the fleet of them combined.

Documented limitation: on a box with two near-identical-capacity cards (16311 MiB vs 16303 MiB total, an 8 MiB gap from per-SKU driver/firmware reserve, not a real capacity difference), this rule has no way to know which index a CUDA app's device-order policy will actually pick — nvidia-smi carries no such signal. It picks the device with more raw capacity, which is a defensible, deterministic, non-arbitrary choice, but is NOT guaranteed to be "the compute card" on near-twin hardware. The full per-device list exists precisely so a caller that needs to reason about this edge case (the placement guards, a smarter dispatcher) has the real numbers for every card, not just the headline guess. This is the FALLBACK rule — fleetnode.SelectHeadlineDevice applies it only when no primary_gpu_uuid is pinned (or the pinned UUID isn't present).

devices must be non-empty — callers only reach this after a successful parse, which never returns an empty slice.

func ParseSmiMemoryDevices

func ParseSmiMemoryDevices(out string) ([]Device, error)

ParseSmiMemoryDevices parses `nvidia-smi --query-gpu=index,uuid,name, memory.total,memory.used[,utilization.gpu] --format=csv,noheader,nounits` output — one line per GPU, e.g. "0, GPU-1111aaaa-2222-3333-4444-555566667777, NVIDIA GeForce RTX 5060 Ti, 16311, 867" (5 fields) or with utilization: "0, GPU-1111aaaa-2222-3333-4444-555566667777, NVIDIA GeForce RTX 5060 Ti, 16311, 867, 37" (6 fields) — into an ordered []Device (nvidia-smi's own enumeration order, i.e. PCI bus order; NOT necessarily CUDA device order — see HeadlineDevice's doc comment for why that distinction is the whole bug this parser exists to fix, and fleetnode.SelectHeadlineDevice / primary_gpu_uuid for the deterministic override).

CRLF and surrounding whitespace are tolerated (nvidia-smi emits \r\n on Windows). Blank lines and lines that don't parse as "index, uuid, name, total, used[, utilization]" are SKIPPED rather than failing the whole probe — a single garbled/partial row (a transient nvidia-smi hiccup) must not take down every other card's reading. A line whose total is <= 0, whose used is negative, or whose used EXCEEDS its total is likewise skipped (not a working GPU line — see the used>total check below for why this is a skip, not a clamp).

The optional 6th field (utilization.gpu) is parsed when present. If the 6th field is malformed, out of range (not 0-100), or missing (5-field line), the device is STILL returned with UtilKnown=false and UtilPct=0 — the memory data is too valuable to lose over a transient utilization query failure or an older query format. Only the first five fields are mandatory for a valid device; the 6th is never required.

If NO line parses into a valid device (memory fields), that IS an error: the fleet contract treats vram_total_gb <= 0 as a failed probe, so a would-be zero-device snapshot must never reach the caller as success — and a placement guard that received an empty list as success could admit onto a card it cannot see.

func Read

func Read(ctx context.Context) ([]Device, error)

Read runs the live nvidia-smi query and parses it — the one call a placement Snapshot or a health tick makes to learn every card's free memory. ctx bounds the exec so a wedged driver (nvidia-smi can hang for tens of seconds during a device reset) cannot stall an admission decision past the caller's deadline; a hang, a missing binary, or a parse of zero valid devices all return an error, never an empty success.

func ReadWith

func ReadWith(run func() (string, error)) ([]Device, error)

ReadWith is Read over an injected runner (a recorded nvidia-smi output in tests, a remote/cached reader in a sampler) so every consumer of the parse exercises the SAME error path: a failed runner is an error, never an empty device list that a guard could mistake for "no card is busy".

func (Device) DrivesDisplay

func (d Device) DrivesDisplay() bool

DrivesDisplay is the placement answer to "is this the operator's screen": display_active Enabled OR display_attached Yes. The card table asks it (ScreenCardUUIDs, so the allocator never auto-picks the monitor's card). It is NOT the load-attribution rule: that reads display_active alone (DisplayCardUUIDs), see display.go for why the two differ.

type HostLoad

type HostLoad struct {
	// TouchGiB is the working set the job will touch: the physical RAM it occupies.
	TouchGiB float64
	// CommitGiB is the commit it will be charged: memory the OS promises it, touched or not.
	CommitGiB float64
	// CommitStated says CommitGiB is a figure the caller stated or measured (gpu reserve --ram-commit): it is judged against the
	// OS commit limit. Not set, CommitGiB is the touched figure standing in for a commit nobody stated, and it is judged against
	// physical RAM less the headroom, the line a caller that declares one figure has always been held to (or against an enforced
	// commit limit less the headroom when that sits below physical RAM: the nearer line). It is read on a need;
	// on a pending or held figure it means nothing.
	CommitStated bool
}

HostLoad is what a job takes of the host's memory, in the two quantities the admission rule keeps apart.

func (HostLoad) Declares

func (l HostLoad) Declares() bool

Declares says the job declares any host memory at all: the one test every "does this lease ask the host for something" decision goes through, so a job that declares only a commit is not mistaken for one that declares nothing. A figure that is not a number (NaN) declares something: "nothing" is the answer that skips the rule, and the rule is where such a figure is refused.

type HostMemory

type HostMemory struct {
	// PhysicalGiB is the installed RAM the OS can use.
	PhysicalGiB float64
	// AvailableGiB is what can be handed out without paging (standby and cache that can be dropped
	// count): the figure the old free-RAM guards read.
	AvailableGiB float64
	// CommitUsedGiB is memory the OS has committed: promised to processes, resident or not. Windows
	// total minus available page file (GlobalMemoryStatusEx); Linux Committed_AS (a limit only in strict mode).
	CommitUsedGiB float64
	// CommitLimitGiB is what the OS will commit before refusing: physical plus page file on Windows,
	// CommitLimit on Linux.
	CommitLimitGiB float64
	// CommitLimitSoft says CommitLimitGiB is not a limit this OS enforces (Linux with vm.overcommit_memory 0 or 1,
	// or a sandbox that hides the accounting). The zero value is a hard limit: Windows always, Linux in strict mode.
	CommitLimitSoft bool
}

HostMemory is one reading of the host's memory, in GiB. A reading whose commit limit is enforced (CommitLimitSoft false: Windows always, Linux in strict mode) must carry that limit: one that leaves CommitLimitGiB at 0 is not a reading, the rule waits on it as unreadable and its verdict is unknown, because a counter that came back zero must not turn the commit brake off. A SOFT reading carries a limit nobody enforces, and may leave it 0.

func ReadHostMemory

func ReadHostMemory() (HostMemory, bool)

ReadHostMemory takes one reading. ok=false means this platform has no reader or the read failed: see HostMemorySupported for which of the two.

func (HostMemory) Verdict

func (m HostMemory) Verdict(headroomGiB float64) HostVerdict

Verdict judges a reading against the configured headroom, by the lines HostRAMAdmitsLoad applies: the available physical memory, the commit charge against physical RAM (the line a commit nobody stated is held to, on every reading), and the commit limit where the OS enforces one. OVER is the commit charge above physical RAM, or nothing available, or the limit reached; NEAR is within the headroom of any of them. They are the guard's own conservative lines for the house rule (RAM is overflow only and never makes the box unstable), chosen 2026-10-09 and not measured: a definition of "too little room", not a reading of paging. A reading from a platform whose limit is enforced but carries none is unknown (fail closed), and so is one with a figure that is not a finite number (nothing compares against NaN).

type HostRAMCheck

type HostRAMCheck struct {
	// OK: the lease may be granted as far as host RAM goes.
	OK bool
	// Impossible: no state of this box admits the declaration (a touched set above physical RAM less the headroom, or a commit
	// above the commit limit less the headroom), so waiting cannot help; the caller refuses instead of queueing.
	Impossible bool
	// Unreadable: the reading could not be taken on a platform that has a reader.
	Unreadable bool
	// The numbers the touched-set condition rested on, all GiB. NeedGiB is the working set the job declared and PendingGiB the
	// part still to be touched of leases already granted; AvailableGiB is what could be handed out without paging when the
	// decision was taken and AvailableAfterGiB what would be left of it (admitted iff at least HeadroomGiB); LimitGiB is
	// physical RAM less the headroom, the most a touched set can ever be admitted at.
	NeedGiB, PendingGiB, PhysicalGiB, HeadroomGiB, LimitGiB, AvailableGiB, AvailableAfterGiB float64
	// The numbers the commit condition rested on, all GiB. CommittedGiB is the commit charge now, CommitNeedGiB the commit the
	// job declared and CommitPendingGiB the part still to be charged of leases already granted (for a stated commit their
	// declared commit less what their processes are charged; for an unstated one their declared working set less what their
	// processes occupy, the figure the physical line has always counted); CommitLimitGiB is the OS commit limit, CommitBoundGiB
	// the line the commit is judged against less the headroom (the commit limit for a stated commit; physical RAM for an
	// unstated one, or the commit limit where an enforced one sits below it), and CommitProjectedGiB the charge the grant would reach (admitted iff at most the bound). The last two are
	// set when the commit condition applies.
	CommittedGiB, CommitNeedGiB, CommitPendingGiB, CommitLimitGiB, CommitBoundGiB, CommitProjectedGiB float64
	// CommitApplies says the commit condition was put to this reading: the job declared a commit and either did not state it (the
	// physical line, on every reading) or stated it and the OS enforces a commit limit. CommitStated says the job stated it.
	// TouchShort and CommitShort say which condition refused; both can.
	CommitApplies, CommitStated, TouchShort, CommitShort bool
	// Why is the sentence a refusal carries ("" when OK).
	Why string
}

HostRAMCheck is the answer of the admission rule.

func HostRAMAdmits

func HostRAMAdmits(mem HostMemory, readable bool, needGiB, pendingGiB, headroomGiB float64) HostRAMCheck

HostRAMAdmits is HostRAMAdmitsLoad for a caller that declares ONE figure: it is taken for both quantities and states no commit, so such a caller is judged on its commit against physical RAM less the headroom, as it was before the two conditions existed. The pending figure is likewise taken for both.

func HostRAMAdmitsLoad

func HostRAMAdmitsLoad(mem HostMemory, readable bool, need, pending HostLoad, headroomGiB float64) HostRAMCheck

HostRAMAdmitsLoad is THE rule, read by the lease grant (authoritative, inside the grant's critical section) and by the card allocator (advisory, before it picks cards), so the two cannot disagree. An admission needs BOTH conditions:

touched:  available now - need.TouchGiB - pending.TouchGiB             >= headroom
commit:   commit charge now + need.CommitGiB + pending.CommitGiB       <= commit limit - headroom      (a STATED commit)
          commit charge now + need.CommitGiB + pending.TouchGiB        <= min(physical RAM, enforced commit limit) - headroom
                                                                                                       (a commit nobody stated)

the stated form only where the OS enforces a commit limit (HostMemory.CommitLimitSoft is false), the unstated form on every reading, and either only when the job declared a commit. need is what the lease declares it will load; pending is the part of the leases ALREADY GRANTED that has not loaded yet (declared less what their processes hold), which neither counter yet includes: for the touched condition and the unstated commit line the working set their processes occupy is subtracted, for the stated commit line the private bytes they are charged. A quantity a job declares as 0 is not judged: it adds nothing to that counter, so refusing it would idle a card without making the memory any safer; a job that declares neither is admitted whatever the box looks like. A touched set above physical RAM less the headroom, or a commit above the line it is judged against less the headroom, is Impossible: it cannot be admitted however long it waits.

WHY THE LINES ARE THESE (see the file header). A STATED commit is compared to the commit limit, not to physical RAM: committed memory is not memory in use, and the limit is the line the OS enforces (it refuses allocations there once the page file has reached its maximum; see THE LIMIT MOVES in the file header). A commit nobody stated is the touched figure standing in for one, and keeps the line it always had, physical RAM, unless an enforced commit limit sits nearer (strict-mode Linux: about half the RAM plus the swap), in which case it is held to that limit like any commit on that host: its stand-in can understate a job that commits more than it touches. What a job TOUCHES is compared to the memory that is available, because that is what pages when it runs out. A declaration is an estimate (the model files' size, or the largest working set a render's tree reached): this rule is a brake on DECLARED loads, not a bound on what the box commits, and neither term sees a process that holds no lease.

type HostVerdict

type HostVerdict string

HostVerdict is the one word for how the host's memory stands against the two lines the admission rule keeps.

const (
	// HostOK: the available memory, the room under physical RAM for the commit charge and (where the OS enforces one) the room
	// under the commit limit all exceed the headroom, so a lease that declares host RAM can be admitted if it is small enough.
	HostOK HostVerdict = "OK"
	// HostNear: one of them is inside the headroom, so a lease judged on that line waits: one that touches host RAM when the
	// available memory is, one that states no commit when the room under physical RAM (or under an enforced commit limit that
	// sits below it) is, one that states its commit when the room under the commit limit is. A lease that states its commit is not held to the physical-RAM line, so it can be admitted
	// while the host reads NEAR on that line alone.
	HostNear HostVerdict = "NEAR"
	// HostOver: one of them is gone: no memory is available, or the commit charge is above physical RAM (the line a commit nobody
	// stated is held to), or it has reached a commit limit the OS enforces (allocations by other processes can fail once the page
	// file has reached its maximum; before that Windows grows a system-managed file). Whether the
	// box is paging NOW is not something this reading can say (that takes page-file growth or the pages-out rate), so nothing
	// built on the verdict claims it.
	HostOver HostVerdict = "OVER"
	// HostUnknown: the reading could not be taken.
	HostUnknown HostVerdict = "unknown"
)

type Thermal

type Thermal struct {
	Index           int
	UUID            string
	TemperatureC    *int
	ThrottleReasons []string
}

Thermal is one card's row of the thermal query, keyed by the card's UUID. A nil TemperatureC is "not read", never a value. ThrottleReasons has three states: nil is "not read" (the driver answered N/A or [Not Supported], or the query had no throttle column), a non-nil empty slice is "read, and nothing is limiting the clocks" (a mask of 0, or the idle bit alone), and a slice with names is the reasons active.

func ParseThermal

func ParseThermal(out string) ([]Thermal, error)

ParseThermal parses `nvidia-smi --query-gpu=index,uuid,temperature.gpu[,<throttle field>] --format=csv,noheader,nounits`: one line per card, e.g. "0, GPU-1111aaaa-..., 83, 0x0000000000000060". A line that is not that shape is skipped, like ParseSmiMemoryDevices; a column the driver cannot give ("N/A", "[Not Supported]") leaves that value out of the row and keeps the other. No line parsing at all is an error: an empty success must never read as a cool node.

func ReadThermal

func ReadThermal(ctx context.Context) ([]Thermal, error)

ReadThermal runs the thermal query and parses it. ctx bounds the exec, like Read. The driver's own naming decides the query (see thermalVariants); the one that worked is tried first on the next read. A failure that is not the driver refusing a field (a missing binary, a wedged driver) is returned at once and walks nothing, so a broken nvidia-smi is not spawned three times per attempt.

Directories

Path Synopsis
Package smitest is test support for code that reads the card table through nvidia-smi: a stand-in nvidia-smi that is the test binary itself, put first on PATH, answering as slowly as a loaded box does.
Package smitest is test support for code that reads the card table through nvidia-smi: a stand-in nvidia-smi that is the test binary itself, put first on PATH, answering as slowly as a loaded box does.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL