cuda

package
v2.0.0-beta.17 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 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 cuda finds the processes of a tree that hold CUDA state and moves that state with NVIDIA's cuda-checkpoint: lock, checkpoint to host memory before the CRIU dump; restore onto the receiver's GPUs and unlock after.

Index

Constants

View Source
const (
	BackendAuto   = "auto"
	BackendDriver = "driver"
	BackendCLI    = "cli"
)

Backend names: Select takes them, and auto picks the driver when it can.

View Source
const (
	CallTimeout   = 90 * time.Second
	LockTimeoutMS = 60000
)

CallTimeout bounds one checkpoint call; LockTimeoutMS is how long a lock may wait for in-flight CUDA work.

Variables

This section is empty.

Functions

func DeviceMap

func DeviceMap(pairs []Pair) (string, error)

DeviceMap is cuda-checkpoint's --device-map: every GPU the processes saw, donor UUID to receiver UUID, in rank order.

func Owners

func Owners(pids []int) ([]int, error)

Owners are the processes among pids that hold CUDA state: they map libcuda and keep a /dev/nvidia* descriptor open. A vLLM engine at TP8 has ten: eight workers, the engine core and the API server.

Types

type Backend

type Backend interface {
	Name() string
	State(ctx context.Context, pid int) (string, error)
	Lock(ctx context.Context, pid, timeoutMS int) error
	Checkpoint(ctx context.Context, pid int) error
	Restore(ctx context.Context, pid int, pairs []Pair) error
	Unlock(ctx context.Context, pid int) error
}

Backend moves the CUDA state of one process. Session keeps the order of the processes, the barriers between phases and the state checks.

func Select

func Select(mode, helper string) (b Backend, why string, err error)

Select returns the backend a session should use. auto takes the driver API when this host's libcuda has it with a struct layout known here, else the cuda-checkpoint binary at helper; driver fails instead of falling back. why says what auto saw.

type CLI

type CLI struct {
	Helper string
	// contains filtered or unexported fields
}

CLI runs NVIDIA's cuda-checkpoint once per process and call.

func NewCLI

func NewCLI(helper string) *CLI

NewCLI uses the helper binary at path.

func (*CLI) Checkpoint

func (c *CLI) Checkpoint(ctx context.Context, pid int) error

Checkpoint moves the locked process's device memory to host memory.

func (*CLI) Lock

func (c *CLI) Lock(ctx context.Context, pid, timeoutMS int) error

Lock blocks the process's CUDA calls, waiting up to timeoutMS for work in flight.

func (*CLI) Name

func (c *CLI) Name() string

Name is the backend as the logs show it.

func (*CLI) Restore

func (c *CLI) Restore(ctx context.Context, pid int, pairs []Pair) error

Restore puts the checkpointed process's memory back, on the pairs' target GPUs.

func (*CLI) State

func (c *CLI) State(ctx context.Context, pid int) (string, error)

State is the process's CUDA state: running, locked, checkpointed or failed.

func (*CLI) Unlock

func (c *CLI) Unlock(ctx context.Context, pid int) error

Unlock lets the restored process's CUDA calls run again.

type Driver

type Driver struct{}

Driver calls the CUDA checkpoint API of libcuda in this process.

func NewDriver

func NewDriver() (*Driver, error)

NewDriver loads libcuda and checks that its restore arguments have a layout known here.

func (*Driver) Checkpoint

func (*Driver) Checkpoint(ctx context.Context, pid int) error

Checkpoint moves the locked process's device memory to host memory.

func (*Driver) Lock

func (*Driver) Lock(ctx context.Context, pid, timeoutMS int) error

Lock blocks the process's CUDA calls, waiting up to timeoutMS for work in flight.

func (*Driver) Name

func (*Driver) Name() string

Name is the backend as the logs show it.

func (*Driver) Restore

func (*Driver) Restore(ctx context.Context, pid int, pairs []Pair) error

Restore puts the checkpointed process's memory back, on the pairs' target GPUs.

func (*Driver) State

func (*Driver) State(ctx context.Context, pid int) (string, error)

State is the process's CUDA state: running, locked, checkpointed or failed.

func (*Driver) Unlock

func (*Driver) Unlock(ctx context.Context, pid int) error

Unlock lets the restored process's CUDA calls run again.

type Pair

type Pair struct {
	Source string `json:"source"`
	Target string `json:"target"`
}

Pair maps a donor GPU to a receiver GPU.

func ParseDeviceMap

func ParseDeviceMap(m string) ([]Pair, error)

ParseDeviceMap is DeviceMap's inverse.

type Session

type Session struct {
	Backend Backend
	Owners  []int
	// Parallel owners are restored concurrently, after the others: the
	// workers, when no collective keeps peer memory mapped between them.
	Parallel []int
	// Concurrent also restores the other owners concurrently, as their own
	// barrier before the parallel ones, and unlocks every owner at once.
	Concurrent bool
	// Phases holds the seconds each phase of the last Restore took.
	Phases map[string]float64
}

Session moves the CUDA state of a set of processes through a Backend. Each phase is a barrier: every owner finishes it before any starts the next. A failure is final; the caller removes the container.

func NewSession

func NewSession(b Backend, owners []int) *Session

NewSession moves the owners' state through b.

func (*Session) Checkpoint

func (s *Session) Checkpoint(ctx context.Context) error

Checkpoint locks every owner and moves its device memory to the host.

func (*Session) Restore

func (s *Session) Restore(ctx context.Context, deviceMap string) error

Restore puts every owner's device memory back on the mapped GPUs (a DeviceMap) and unlocks it.

Jump to

Keyboard shortcuts

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