unilab.training.cuda_mps_cli¶
User-owned CUDA MPS daemon management for the UniLab CLI.
This module owns command-level lifecycle operations for explicitly requested MPS control daemons. It intentionally treats daemon ownership as an external, security-sensitive host service: every stop is gated by a UniLab daemon record containing the recorded process identity, and records are scoped by user and host. It never mutates the calling shell’s CUDA environment.
The topology model distinguishes single-GPU, single-task multi-GPU, and task-per-GPU placements. Only single-GPU execution is currently accepted; the other shapes fail closed rather than silently choosing a future topology.
Functions
|
Check both PID and Linux process start-time to avoid PID reuse. |
|
Return record identity plus PID/start-time liveness evidence. |
|
Discover physical host GPUs through the public |
|
Validate topology and daemon state without creating or changing anything. |
|
Return launcher-facing CUDA environment without mutating this process. |
|
Build read-only host capability and managed-daemon status. |
|
List current-user/current-host daemon records without mutating them. |
|
Run the CUDA MPS management CLI and return a process exit code. |
|
Load and scope-check a UniLab daemon record. |
|
Resolve selector syntax to canonical GPU UUIDs and a topology mode. |
|
Select the sole live user-owned daemon environment for one GPU. |
|
Start an explicitly requested, user-owned daemon and record its identity. |
|
Stop every current-user/current-host daemon recorded by UniLab. |
|
Stop only a daemon whose UniLab record and process identity still match. |
|
Return canonical GPU identities visible under the current host mask. |
Classes
A discovered control pipe and whether a UniLab record owns it. |
|
A UniLab-owned daemon identity; absence means no stop authority. |
|
Canonical GPU identity suitable for persisted topology records. |
|
Read-only host, control-pipe, and managed-daemon status. |
|
A resolved selector before any host service is created. |
Exceptions
A user-actionable, fail-closed CUDA MPS CLI error. |
|
A recorded daemon identity is no longer live; its record was cleaned. |
- exception unilab.training.cuda_mps_cli.CudaMpsError[source]¶
Bases:
RuntimeErrorA user-actionable, fail-closed CUDA MPS CLI error.
- exception unilab.training.cuda_mps_cli.StaleCudaMpsDaemonError[source]¶
Bases:
CudaMpsErrorA recorded daemon identity is no longer live; its record was cleaned.
- class unilab.training.cuda_mps_cli.GpuIdentity[source]¶
Bases:
objectCanonical GPU identity suitable for persisted topology records.
- class unilab.training.cuda_mps_cli.DaemonRecord[source]¶
Bases:
objectA UniLab-owned daemon identity; absence means no stop authority.
- Parameters:
- __init__(name, uid, host, topology_mode, gpu_uuids, pipe_directory, log_directory, pid, process_start_ticks, created_at)¶
- class unilab.training.cuda_mps_cli.ControlPipeStatus[source]¶
Bases:
objectA discovered control pipe and whether a UniLab record owns it.
- class unilab.training.cuda_mps_cli.HostStatus[source]¶
Bases:
objectRead-only host, control-pipe, and managed-daemon status.
- Parameters:
-
gpus:
tuple[GpuIdentity,...]¶
-
control_pipes:
tuple[ControlPipeStatus,...]¶
-
managed_daemons:
tuple[DaemonRecord,...]¶
-
compatible_topology_modes:
tuple[str,...] = ('single_gpu', 'single_task_multi_gpu', 'task_per_gpu')¶
- __init__(platform, nvidia_smi_available, cuda_visible_devices, gpus, control_pipes, managed_daemons, diagnostic=None, compatible_topology_modes=('single_gpu', 'single_task_multi_gpu', 'task_per_gpu'))¶
- class unilab.training.cuda_mps_cli.TopologyPlan[source]¶
Bases:
objectA resolved selector before any host service is created.
- Parameters:
selector (
str)topology_mode (
str)gpus (
tuple[GpuIdentity,...])
-
gpus:
tuple[GpuIdentity,...]¶
- unilab.training.cuda_mps_cli.discover_gpus(run_command=<function run>)[source]¶
Discover physical host GPUs through the public
nvidia-smiCLI.- Parameters:
run_command (
Callable[...,CompletedProcess[str]])- Return type:
- unilab.training.cuda_mps_cli.visible_gpus(cuda_visible_devices=None, run_command=<function run>)[source]¶
Return canonical GPU identities visible under the current host mask.
- Parameters:
- Return type:
- unilab.training.cuda_mps_cli.read_daemon_record(root, name, *, uid=None, host=None)[source]¶
Load and scope-check a UniLab daemon record.
name=Noneselects the sole current-user/current-host live daemon. The common single-GPU workflow therefore needs no daemon label.
- unilab.training.cuda_mps_cli.list_daemon_records(root=None, *, uid=None, host=None)[source]¶
List current-user/current-host daemon records without mutating them.
- unilab.training.cuda_mps_cli.daemon_process_is_live(daemon, *, proc_stat=<function _proc_stat>)[source]¶
Check both PID and Linux process start-time to avoid PID reuse.
- unilab.training.cuda_mps_cli.resolve_topology(selector, *, cuda_visible_devices=None, run_command=<function run>)[source]¶
Resolve selector syntax to canonical GPU UUIDs and a topology mode.
Noneselects the single visible GPU. On a single-GPU host this is the default CLI path: users need no selector, daemon name, or custom paths.- Parameters:
- Return type:
- unilab.training.cuda_mps_cli.daemon_status(daemon, *, proc_stat=<function _proc_stat>)[source]¶
Return record identity plus PID/start-time liveness evidence.
- unilab.training.cuda_mps_cli.host_status(root=None, *, cuda_visible_devices=None, run_command=<function run>, uid=None, host=None)[source]¶
Build read-only host capability and managed-daemon status.
- unilab.training.cuda_mps_cli.start_daemon(selector, *, name=None, pipe_dir=None, log_dir=None, root=None, cuda_visible_devices=None, run_command=<function run>, daemon=True, foreground_runner=None)[source]¶
Start an explicitly requested, user-owned daemon and record its identity.
The caller remains responsible for exporting the resulting environment into a training launcher; this command never changes its parent shell.
- Parameters:
- Return type:
- unilab.training.cuda_mps_cli.environment_for_daemon(daemon)[source]¶
Return launcher-facing CUDA environment without mutating this process.
- Parameters:
daemon (
DaemonRecord)- Return type:
- unilab.training.cuda_mps_cli.select_environment_for_gpu(gpu_uuid, *, root=None, proc_stat=<function _proc_stat>)[source]¶
Select the sole live user-owned daemon environment for one GPU.
This is launcher-facing data only. It does not mutate the current process, start a daemon, stop a daemon, or provide stop authority.
- unilab.training.cuda_mps_cli.stop_daemon(name, *, root=None, run_command=<function run>, proc_stat=<function _proc_stat>)[source]¶
Stop only a daemon whose UniLab record and process identity still match.
- unilab.training.cuda_mps_cli.stop_all_daemons(*, root=None, run_command=<function run>, proc_stat=<function _proc_stat>)[source]¶
Stop every current-user/current-host daemon recorded by UniLab.