Python rrun API Reference#
Resource binding utilities from the rrun launcher.
- class rapidsmpf.rrun.BindingValidation( )#
Results of validating actual vs. expected resource bindings.
- Parameters:
- cpu_ok
CPU affinity check passed.
- numa_ok
NUMA binding check passed.
- ucx_ok
UCX network devices check passed.
- expected_ucx_devices
Expected UCX devices as a comma-separated string.
Methods
all_passed(self)Return
Trueif all validation checks passed.See also
validate_bindingProduce a validation result.
- class rapidsmpf.rrun.ExpectedBinding(
- cpu_affinity: str = '',
- memory_binding: list[int] = <factory>,
- network_devices: list[str] = <factory>,
Expected resource binding derived from topology information.
Represents the binding configuration that should be in effect for a given GPU according to the system topology.
- Parameters:
- cpu_affinity
Expected CPU affinity list.
- memory_binding
Expected NUMA node IDs.
- network_devices
Expected network devices.
See also
validate_bindingCompare actual vs. expected bindings.
- class rapidsmpf.rrun.ResourceBinding(
- rank: int | None,
- gpu_id: int | None,
- gpu_pci_bus_id: str,
- cpu_affinity: str,
- numa_nodes: list[int],
- ucx_net_devices: str,
Live resource binding configuration collected from the running process.
Holds the CPU affinity, NUMA memory binding, and network device configuration that are currently in effect.
- Parameters:
- rank
Process rank, or
Noneif not available.- gpu_id
GPU device ID, or
Noneif not available.- gpu_pci_bus_id
GPU PCI bus ID (empty if unavailable).
- cpu_affinity
CPU affinity string (e.g.,
"0-19,40-59").- numa_nodes
NUMA node IDs bound to this process.
- ucx_net_devices
Value of the
UCX_NET_DEVICESenvironment variable.
See also
check_bindingCollect the live binding of the calling process.
- rapidsmpf.rrun.bind(gpu_id=None, *, cpu=True, memory=True, network=True, verify=True)#
Bind the calling process to resources topologically close to a GPU.
Discovers the system topology, then applies CPU affinity, NUMA memory binding, and/or network device configuration as requested.
Warning
This function is not thread-safe. It temporarily modifies the
CUDA_VISIBLE_DEVICESenvironment variable during topology discovery and mutates process-wide state (CPU affinity, NUMA memory policy, and theUCX_NET_DEVICESenvironment variable). It should be called exactly once per process, ideally early in initialization and before other threads are spawned.GPU resolution order:
Use
gpu_idif provided.Otherwise, parse the first entry of the
CUDA_VISIBLE_DEVICESenvironment variable.If neither is available, raise
RuntimeError.
- Parameters:
- gpu_id
Physical GPU device index (as reported by
nvidia-smi). WhenNone, the first GPU inCUDA_VISIBLE_DEVICESis used.- cpu
Set CPU affinity to cores near the GPU (default
True).- memory
Set NUMA memory policy to nodes near the GPU (default
True).- network
Set
UCX_NET_DEVICESto NICs near the GPU (defaultTrue).- verify
Read back and verify that bindings match the requested configuration after applying them (default
True).
- Raises:
- RuntimeError
If no GPU ID can be determined, topology discovery fails, the resolved GPU is not found in the discovered topology, an enabled CPU or network binding could not be applied, a NUMA memory policy operation fails unexpectedly, or post-bind verification detects a mismatch between the requested and actual state. NUMA memory binding is skipped when the current OS/container does not allow memory-policy syscalls or the requested node is outside the task’s allowed memory nodes.
- ValueError
If
gpu_idis not a non-negative integer.
- rapidsmpf.rrun.check_binding(gpu_id_hint=None)#
Collect the live resource binding of the calling process.
Queries the current CPU affinity, NUMA memory nodes, UCX network device configuration, process rank, and GPU information. Fields that cannot be determined (e.g. rank when no launcher environment is set, or GPU ID when
CUDA_VISIBLE_DEVICESis absent and no hint is given) are returned asNone.- Parameters:
- gpu_id_hint
GPU device index hint. When a non-negative integer the value is stored directly; when
Nonethe GPU ID is read fromCUDA_VISIBLE_DEVICES. When a valid GPU ID is available the PCI bus ID is also queried.
- Returns:
- ResourceBinding
The collected resource binding.
- rapidsmpf.rrun.validate_binding(actual, expected)#
Validate an actual resource binding against an expected one.
Compares the live actual binding with expected and reports per-resource pass/fail status.
- Parameters:
- actualResourceBinding
Live resource binding (from
check_binding()).- expectedExpectedBinding
Expected binding (from topology or another source).
- Returns:
- BindingValidation
Per-resource validation results.