cuda

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package cuda provides CUDA checkpoint and restore operations.

Index

Constants

View Source
const (

	// HelperBinaryName is the cuda-checkpoint-helper executable name.
	HelperBinaryName = "cuda-checkpoint-helper"
	// DefaultHelperBinaryPath is the agent-side cuda-checkpoint-helper absolute path.
	// In the placeholder namespace pass filepath.Join(bundleDir, HelperBinaryName) instead.
	DefaultHelperBinaryPath = "/usr/local/bin/" + HelperBinaryName
)
View Source
const JobFileEnv = "CUDA_CHECKPOINT_JOB_FILE"

JobFileEnv is the CUDA launch-job environment variable consumed by the driver.

Variables

This section is empty.

Functions

func BuildDeviceMap

func BuildDeviceMap(sourceUUIDs, targetUUIDs []string, log logr.Logger) (string, error)

BuildDeviceMap creates a cuda-checkpoint-helper --device-map value from source and target GPU UUID lists. When a source UUID exists in the target set, it maps to itself (identity mapping) to avoid unnecessary cross-GPU restore on same-node restores where kubelet returns GPUs in different order. Remaining unmatched source UUIDs are paired with remaining unmatched target UUIDs positionally. If all mappings are identity mappings, it returns an empty string so same-GPU restores use the default CUDA restore path instead of forcing the GPU migration path.

func DiscoverGPUUUIDs

func DiscoverGPUUUIDs(ctx context.Context, clientset kubernetes.Interface, podName, podNamespace, containerName, hostProcPath string, pid int, log logr.Logger) ([]string, error)

DiscoverGPUUUIDs resolves GPU UUIDs in the container's runtime ordinal order.

func FilterProcesses

func FilterProcesses(ctx context.Context, allPIDs []int, log logr.Logger) []int

FilterProcesses returns the subset of candidate PIDs that hold actual CUDA contexts. Uses --get-restore-tid (the same technique as the CRIU CUDA plugin) instead of --get-state, because --get-state incorrectly matches coordinator processes like cuda-checkpoint --launch-job that share a /proc namespace with CUDA processes but don't hold CUDA contexts themselves.

func GetGPUUUIDsViaDRAAPI

func GetGPUUUIDsViaDRAAPI(ctx context.Context, clientset kubernetes.Interface, podName, podNamespace, containerName string, log logr.Logger) ([]string, bool, error)

GetGPUUUIDsViaDRAAPI resolves GPU UUIDs for a pod by querying the Kubernetes API: Pod (resource claim refs) -> ResourceClaim (allocation results) -> ResourceSlice (device attributes). A non-empty containerName restricts resolution to the claims (and claim requests) that container references via resources.claims. On success, the returned bool reports whether NVIDIA DRA GPU allocations were found for that container. With a non-nil error, it reports whether the container was established to reference resource claims, in which case the caller must fail instead of falling back to other discovery paths.

func GetGPUUUIDsViaNvidiaSmi

func GetGPUUUIDsViaNvidiaSmi(ctx context.Context, hostProcPath string, pid int) ([]string, error)

GetGPUUUIDsViaNvidiaSmi discovers GPU UUIDs by running nvidia-smi inside the container's mount and PID namespaces. This is the fallback path when the kubelet PodResources API does not report GPU devices (e.g. when GPUs are allocated via DRA instead of the NVIDIA device plugin).

func GetPodGPUUUIDs

func GetPodGPUUUIDs(ctx context.Context, podName, podNamespace, containerName string) ([]string, error)

GetPodGPUUUIDs resolves GPU UUIDs for a pod/container from kubelet PodResources (nvidia.com/gpu entries in GetDevices()).

func JobFileFromCheckpoint

func JobFileFromCheckpoint(checkpointDir string) (string, error)

JobFileFromCheckpoint returns the staged job file when an artifact contains one.

func PrepareLiveJobFile

func PrepareLiveJobFile(stagedJobFile string) (string, error)

PrepareLiveJobFile materializes the immutable capture-time launch-job state at the fixed launch-job path. It runs inside the restore container's namespaces before CRIU recreates processes. The returned path is the per-restore working copy that CUDA helpers must use; the staged artifact remains immutable so it can seed later restores.

func SetLiveJobFileOwner

func SetLiveJobFileOwner(jobFile string, uid, gid int) error

SetLiveJobFileOwner makes the restore-time working copy accessible to the restored workload without following a replacement symlink.

func StageJobFile

func StageJobFile(sourceRootPath, checkpointDir string, sourceGPUCount int) (string, error)

StageJobFile copies a launch-job file into the checkpoint artifact and returns the host-visible path to the source pod's live job file. Capture helpers must use that live file so they join the same CUDA job as the target processes; the artifact copy is only a seed for later restore pods. The launch wrapper persists the driver-created file at a fixed path before starting the workload.

Types

type CheckpointPhaseTimings

type CheckpointPhaseTimings struct {
	TotalDuration time.Duration
}

func CheckpointProcessTree

func CheckpointProcessTree(ctx context.Context, cudaPIDs []int, jobFile, checkpointDir string, log logr.Logger) (CheckpointPhaseTimings, error)

CheckpointProcessTree locks and checkpoints CUDA state for all given PIDs, then persists the launch-job state needed to restore them. On failure, the caller is expected to fail the operation and terminate the workload.

type RestorePhaseTimings

type RestorePhaseTimings struct {
	TotalDuration time.Duration
}

func RestoreAndUnlockProcessTree

func RestoreAndUnlockProcessTree(ctx context.Context, cudaPIDs []int, deviceMap, helperBinaryPath string, log logr.Logger) (RestorePhaseTimings, error)

RestoreAndUnlockProcessTree restores and unlocks CUDA state for the given PIDs. helperBinaryPath must be the absolute path to cuda-checkpoint-helper: DefaultHelperBinaryPath on the agent, or filepath.Join(bundleDir, HelperBinaryName) inside the placeholder namespace.

Jump to

Keyboard shortcuts

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