vllm.platforms.cuda
¶
Code inside this file can safely assume cuda platform, e.g. importing pynvml. However, it should not initialize cuda context.
Classes:
CudaPlatformBase
¶
Bases: Platform
Methods:
-
get_cuda_runtime_major–Major
torch.version.cudaversion, or0if undetermined. -
import_kernels–Import CUDA kernel extensions (_C_stable_libtorch).
-
insert_blocks_to_device–Copy blocks from src_cache to dst_cache on GPU.
-
set_device–Set the device for the current platform.
-
support_deep_gemm–Currently, only Hopper and Blackwell GPUs are supported.
-
swap_out_blocks_to_host–Copy blocks from GPU to host (CPU).
get_cuda_runtime_major()
classmethod
¶
Major torch.version.cuda version, or 0 if undetermined.
import_kernels()
classmethod
¶
Import CUDA kernel extensions (_C_stable_libtorch).
insert_blocks_to_device(src_cache, dst_cache, src_block_indices, dst_block_indices)
classmethod
¶
Copy blocks from src_cache to dst_cache on GPU.
set_device(device)
classmethod
¶
Set the device for the current platform.
support_deep_gemm()
classmethod
¶
Currently, only Hopper and Blackwell GPUs are supported.
swap_out_blocks_to_host(src_cache, dst_cache, src_block_indices, dst_block_indices)
classmethod
¶
Copy blocks from GPU to host (CPU).
NvmlCudaPlatform
¶
Bases: CudaPlatformBase
Methods:
-
get_all_device_numa_nodes–Get NUMA nodes for all visible GPU devices.
-
get_all_gpu_pci_bus_ids–Query NVML for GPU index -> PCI bus ID mapping.
-
get_device_numa_node–Get the NUMA node ID for a GPU device.
-
is_fully_connected–Query if the set of gpus are fully connected by nvlink (1 hop).
_cpu_in_cpulist(cpu_id, cpulist)
classmethod
¶
Check if a CPU ID is in a cpulist string such as '0-3,8-11'.
_get_device_cpu_affinity(handle)
classmethod
¶
Get the list of CPU IDs associated with a GPU via NVML.
_get_numa_node_for_cpu(cpu_id)
classmethod
¶
Determine which NUMA node a CPU belongs to.
_numa_node_has_cpus(node_id)
classmethod
¶
Check whether a NUMA node has any CPUs assigned to it.
get_all_device_numa_nodes()
classmethod
¶
Get NUMA nodes for all visible GPU devices.
get_all_gpu_pci_bus_ids()
classmethod
¶
Query NVML for GPU index -> PCI bus ID mapping.
get_device_numa_node(device_id=0)
classmethod
¶
Get the NUMA node ID for a GPU device.
is_fully_connected(physical_device_ids)
classmethod
¶
Query if the set of gpus are fully connected by nvlink (1 hop).
_cuda_device_count_stateless(cuda_visible_devices=None)
cached
¶
Get number of CUDA devices, caching based on the value of CUDA_VISIBLE_DEVICES at the time of call.
This should be used instead of torch.accelerator.device_count() unless CUDA_VISIBLE_DEVICES has already been set to the desired value.
This can be removed and simply replaced with torch.cuda.get_device_count¶
after https://github.com/pytorch/pytorch/pull/122815 is released.¶
_detect_confidential_compute()
cached
¶
Whether the GPU runs in NVIDIA Confidential Computing mode.
Overridable via VLLM_CONFIDENTIAL_COMPUTE=1/0; detected once via NVML
and cached. Returns False if CUDA is unavailable or NVML fails.
_get_backend_priorities(use_mla, device_capability, num_heads=None, kv_cache_dtype=None, use_non_causal=False, head_size=None, use_mm_prefix=False)
cached
¶
Get backend priorities with lazy import to avoid circular dependency.
_get_wsl_kernel_version()
cached
¶
Return the WSL2 kernel version as a tuple, or None on parse failure.
platform.uname().release on WSL2 looks like "5.15.167.4-microsoft-standard-WSL2"; we take the numeric prefix.