host

package
v2.0.0-beta.19 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 23 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 host reads the facts a snapshot depends on from the machine: the GPUs (NVML), their topology, the driver and kernel, and holds an exclusive lease on the GPUs a run uses.

Index

Constants

View Source
const (
	BackendAuto  = "auto"
	BackendCRIU  = "criu"
	BackendDMTCP = "dmtcp"
)

Process snapshot backends, as agent.BackendCRIU and agent.BackendDMTCP.

View Source
const (
	VendorNVIDIA = "nvidia"
	VendorAMD    = "amd"
)

GPU vendors, as GPU.Vendor names them; NVIDIA's GPUs leave it empty.

View Source
const PeerProbeCommand = "peer-probe"

PeerProbeCommand is the warmctl subcommand that runs the probe in a child process, so that a copy which never finishes cannot hang warmctl itself.

View Source
const TestKFDRootEnv = "WARMCTL_TEST_KFD_ROOT"

TestKFDRootEnv points the KFD paths at a fixture laid out as testdata/kfd-mi350x-pod (dev/kfd, sys/topology, sys/amdgpu): the CPU end-to-end test of the AMD path (tests/integration/amd) runs warmctl in a container that has no AMD GPU. Never set in production.

View Source
const Timeout = 30 * time.Second

Timeout bounds one query: a GPU that fell off the bus can block NVML for minutes, and the caller should hear about it.

Variables

View Source
var (
	KFDDevice    = "/dev/kfd"
	KFDTopology  = "/sys/class/kfd/kfd/topology"
	AMDGPUModule = "/sys/module/amdgpu"
	DRIDir       = "/dev/dri"
)

KFD is where an AMD host's kernel driver describes its GPUs, and the device a ROCm process opens. Tests point them at a fixture.

View Source
var NVIDIADevice = "/dev/nvidiactl"

NVIDIADevice is the control node every NVIDIA driver creates.

View Source
var Open = openSession

Open starts a session on this host's GPUs; tests replace it with a fake.

View Source
var PeerTimeout = 10 * time.Second

PeerTimeout bounds a probe: CUDA's start on every GPU, then 64 MiB per direction, which a working peer path moves in milliseconds. On a broken one, where the PCIe fabric between the GPUs (ACS, an IOMMU) does not carry what the driver reports, the copy never finishes.

Functions

func Busy

func Busy(ctx context.Context, gpus []GPU) (int, error)

Busy counts compute processes on the GPUs.

func CPUFlags

func CPUFlags() []string

CPUFlags are the first CPU's feature flags, sorted: a restored process may use any instruction the donor's CPU had.

func Describe

func Describe(gpus []GPU) string

Describe summarizes GPUs by model: "8× NVIDIA H100 80GB HBM3".

func DevicePath

func DevicePath(busID string) (string, error)

DevicePath is the GPU's device node, /dev/nvidiaN. N is the minor number the driver gives it in /proc/driver/nvidia/gpus/<bus>/information, in the host's order: the same GPU model is /dev/nvidia3 in one pod and /dev/nvidia0 in the next.

func GFX

func GFX(version uint64) string

GFX is the node's ISA name: gfx_target_version 90500 is gfx950.

func IOUringDisabled

func IOUringDisabled() (int, error)

IOUringDisabled is kernel.io_uring_disabled; CRIU cannot dump io_uring, so a snapshot needs 2.

func KFDPresent

func KFDPresent() bool

KFDPresent reports whether this is an AMD compute host warmctl can read: /dev/kfd exists and the topology lists at least one GPU it may read.

func Kernel

func Kernel() string

Kernel is uname -r.

func Leased

func Leased(dir string, g GPU) bool

Leased reports whether a warmctl run holds the GPU's lease in dir.

func MissingFlags

func MissingFlags(donor, here []string) []string

MissingFlags are the donor's CPU flags this host lacks.

func NVIDIADevicePresent

func NVIDIADevicePresent() bool

NVIDIADevicePresent reports an NVIDIA driver's device node.

func ParseIndices

func ParseIndices(spec string) ([]int, error)

ParseIndices reads "0-3,6".

func Processes

func Processes(ctx context.Context) (map[string]int, error)

Processes counts the compute processes on each GPU, by UUID.

func RunPeerProbe

func RunPeerProbe(uuids []string, w io.Writer) error

RunPeerProbe is the child side of ProbePeers: uuids are the GPUs' UUIDs in rank order, as NVML reports them. It writes a line "copy I J" before each copy and a PeerResult as JSON at the end to w.

func Topology

func Topology(ctx context.Context, gpus []GPU) (string, string, error)

Topology is the class of the links between the GPUs (nvlink, pcie or single) and, for the record, a digest of the host's link matrix.

func TopologyClass

func TopologyClass(m LinkMatrix, gpus []GPU) string

TopologyClass is nvlink when every pair of the selected GPUs is joined by NVLink, pcie otherwise; a single GPU is "single".

func VendorOf

func VendorOf(gpus []GPU) string

VendorOf is the vendor of gpus: AMD when they came from the KFD topology, NVIDIA otherwise.

Types

type BackendProbe

type BackendProbe struct {
	// CapEff is the effective capability set of this process.
	CapEff uint64
	// LastPIDWritable: /proc/sys/kernel/ns_last_pid can be written, so the
	// agent can move the PID allocator and CRIU can restore PIDs.
	LastPIDWritable bool
	// Seccomp is the seccomp mode: 0 none, 2 a filter (Docker's default
	// refuses unshare and clone3, which CRIU's restore needs).
	Seccomp int
}

BackendProbe is what decides whether this container may run CRIU.

func ParseStatus

func ParseStatus(status string) BackendProbe

ParseStatus takes CapEff and Seccomp from /proc/self/status.

func ProbeBackend

func ProbeBackend() (BackendProbe, error)

ProbeBackend reads this process's capabilities and seccomp mode and tries ns_last_pid for writing.

func (BackendProbe) CRIUReason

func (p BackendProbe) CRIUReason() string

CRIUReason is why CRIU cannot run here, or "" when it can.

type GPU

type GPU struct {
	Index     int    `json:"index"`
	UUID      string `json:"uuid"`
	Name      string `json:"name"`
	PCIBusID  string `json:"pci_bus_id"`
	MemoryMiB int64  `json:"memory_mib"`
	Driver    string `json:"driver"`
	// Vendor is VendorAMD for a GPU of the KFD topology, empty for NVIDIA's.
	// Arch (gfx950), KFDGPUID (the kernel's gpu_id) and RenderNode
	// (/dev/dri/renderD128) are an AMD GPU's.
	Vendor     string `json:"vendor,omitempty"`
	Arch       string `json:"arch,omitempty"`
	KFDGPUID   uint64 `json:"kfd_gpu_id,omitempty"`
	RenderNode string `json:"render_node,omitempty"`
}

GPU is one device as NVML, or on an AMD host the KFD topology, reports it.

func Inventory

func Inventory(ctx context.Context) ([]GPU, error)

Inventory lists every GPU of the host.

func Pick

func Pick(all []GPU, n int, name string, procs map[string]int, locks string) ([]GPU, error)

Pick chooses n GPUs named name, in PCI order, that run no compute process (procs, from Processes) and that no warmctl run leases in locks.

func Select

func Select(all []GPU, spec string) ([]GPU, error)

Select picks GPUs by index list ("0-3,6") or all when spec is empty, in PCI bus order: the order CUDA gives ranks with CUDA_DEVICE_ORDER=PCI_BUS_ID.

type Lease

type Lease struct {
	// contains filtered or unexported fields
}

Lease holds an exclusive flock per GPU for the life of a run.

func Acquire

func Acquire(dir string, gpus []GPU) (*Lease, error)

Acquire locks <dir>/gpu-<uuid>.lock for every GPU without waiting.

func (*Lease) Release

func (l *Lease) Release()

Release drops the locks.

type LinkMatrix

type LinkMatrix [][]string

LinkMatrix is how every pair of the host's GPUs is linked: X on the diagonal, NV for NVLink, else the PCIe path.

func (LinkMatrix) String

func (m LinkMatrix) String() string

String renders the matrix as nvidia-smi topo -m lays it out.

type PeerCopy

type PeerCopy struct {
	From int     `json:"from"`
	To   int     `json:"to"`
	GBps float64 `json:"gbps"`
}

PeerCopy is one direction of the probe.

type PeerReport

type PeerReport struct {
	PeerResult
	// Broken is set when the driver claims peer access and a copy did not
	// finish within PeerTimeout; Why says which GPUs.
	Broken bool
	Why    string
}

PeerReport says whether the GPUs' peer path works.

func ProbePeers

func ProbePeers(ctx context.Context, self string, gpus []GPU) (PeerReport, error)

ProbePeers copies 64 MiB between every ordered pair of gpus, peer to peer, in a child process (self PeerProbeCommand). Engines trust the driver's report of peer access: vLLM's custom all-reduce and NCCL's P2P transport map each other's memory and spin on it, so a path that does not carry the bytes hangs the engine or faults the GPUs. A child that runs past PeerTimeout is killed; the path is broken if it was inside a copy.

func (PeerReport) String

func (r PeerReport) String() string

String is the report as a log line.

type PeerResult

type PeerResult struct {
	// Claimed is whether the driver reports peer access for every pair.
	Claimed bool       `json:"claimed"`
	Copies  []PeerCopy `json:"copies"`
}

PeerResult is what the probe's child reports.

type Session

type Session interface {
	Driver() (string, error)
	Count() (int, error)
	// GPU is device i's UUID, name, PCI bus ID as NVML prints it and total
	// memory; Index and Driver are left to the caller.
	GPU(i int) (GPU, error)
	// Processes counts the compute processes on device i.
	Processes(i int) (int, error)
	// NVLink reports whether devices i and j reach each other over NVLink.
	NVLink(i, j int) (bool, error)
	// Path is the closest PCIe ancestor of devices i and j in nvidia-smi
	// topo -m's terms: PIX, PXB, PHB, NODE or SYS.
	Path(i, j int) (string, error)
	Close() error
}

Session is an open NVML session. Devices are numbered in NVML's order, which is nvidia-smi's index.

Jump to

Keyboard shortcuts

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