public class NLinuxGpuProbe extends Object
NGpuDevice instances carrying the
capabilities declared by NGpuDevice.
Detection is layered by cost. The kernel exposes vendor, pci identity, bound
module, device count, model name and uuid as plain files, and those readings
are identical on every distribution because they are kernel interfaces rather
than a userspace layout. Only compute capability and NVIDIA memory amounts
require running nvidia-smi.
The identity of a device cannot change while the machine is up, so it is probed once and cached. Memory amounts can and do change constantly, so they are re-read on every call and never cached : a caller asking how much video memory is free must not be handed a figure from process startup.
The filesystem root and the command runner are injectable, so that the whole reading can be exercised against fixture directories rather than against the machine the tests happen to run on.
Every probe is fail-safe, an unreadable or missing source degrades the
corresponding property to unknown and never propagates an error : a machine
with no GPU, a container without device passthrough and a card left to
nouveau are all normal outcomes rather than failures.
| Modifier and Type | Method and Description |
|---|---|
List<NGpuDevice> |
detect()
Reads the devices under this probe's root.
|
static List<NGpuDevice> |
gpus()
Probes the machine.
|
static NLinuxGpuProbe |
of(Path root,
Function<String[],String> commandRunner)
Builds a probe reading an arbitrary root through an arbitrary command
runner, which is what makes the reading testable : a fixture directory
standing in for
/sys and /proc, and a stub standing in for
the vendor tool. |
public static NLinuxGpuProbe of(Path root, Function<String[],String> commandRunner)
/sys and /proc, and a stub standing in for
the vendor tool.
The runner is handed the command and its arguments and returns the
standard output, or null when the tool is missing, fails or times out,
which is the contract exec(String...) honours.
root - directory standing in for the filesystem rootcommandRunner - runner invoking a command, null result meaning no answerpublic static List<NGpuDevice> gpus()
Device identity is cached, memory amounts are read afresh on every call,
so that the returned NRam describes the machine now rather than at
first probe.
public List<NGpuDevice> detect()
gpus() it does
not require the host to be linux, the root being whatever it was built
with.Copyright © 2026 vpc open source initiative. All rights reserved.