Skip to content

vllm.utils.vmm_driver

ctypes bindings for the CUDA (cuMem*) and HIP (hipMem*) virtual memory management APIs, used by vllm.utils.extensible_tensor.ExtensibleTensor.

Classes:

  • CudaVmmDriver –
  • HipVmmDriver –

    HIP mirrors the CUDA VMM API with identical signatures, structs and constants.

  • VmmDriver –

    Uniform interface over a GPU driver's VMM API.

Functions:

CudaVmmDriver

Bases: VmmDriver

Methods:

ensure_context(device_index)

Make the primary context of device_index current, as torch does for the device it runs on; usable before torch has touched the device.

supports_gpudirect_rdma_with_vmm(device_index)

Return whether the device supports GPUDirect RDMA on VMM allocations.

HipVmmDriver

Bases: VmmDriver

HIP mirrors the CUDA VMM API with identical signatures, structs and constants.

Methods:

runtime_version()

(major, minor) of the loaded HIP runtime.

VmmDriver

Uniform interface over a GPU driver's VMM API.

Subclasses supply library names and symbols; signatures and structs are shared between CUDA and HIP.

Methods:

  • create –

    Create a physical memory handle of size bytes.

  • ensure_context –

    Make sure a driver context for device_index is current.

  • export_fd –

    Export an allocation as an owned, non-inheritable POSIX descriptor.

  • import_fd –

    Import a POSIX descriptor; the caller still owns and must close it.

  • reserve –

    Reserve a virtual address range and return its base pointer.

  • unusable_runtime_reason –

    Why this driver's runtime cannot back a growable allocation, if so.

create(size, device_index, export_handle_types=0)

Create a physical memory handle of size bytes.

Parameters:

  • size

    (int) –

    Bytes to allocate.

  • device_index

    (int) –

    Device to allocate on.

  • export_handle_types

    (int, default: 0 ) –

    Handle types other processes import the memory through: POSIX file descriptors and/or FABRIC. Both together get a FABRIC handle only, where FABRIC is available.

ensure_context(device_index)

Make sure a driver context for device_index is current.

export_fd(handle)

Export an allocation as an owned, non-inheritable POSIX descriptor.

import_fd(fd)

Import a POSIX descriptor; the caller still owns and must close it.

reserve(size)

Reserve a virtual address range and return its base pointer.

unusable_runtime_reason(device_index)

Why this driver's runtime cannot back a growable allocation, if so.

_find_loaded_library(lib_name, maps_lines=None)

Path of the mapped shared object named lib_name (e.g. libcuda), matched on the file name so that libcudart does not stand in for it.

_set_access_fails_within_reservation(driver, device_index)

Whether set-access rejects one of two allocations mapped side by side in a reservation, as HIP runtimes before ROCm/rocm-systems#2451 do.

Those check the requested size against the reservation's allocations counted from the first in their list rather than from the target. With sizes of one and two granules, one of the two calls fails whichever comes first in that list, so the check does not depend on allocation order.

imex_channel_available()

Whether this process can open an IMEX channel, which FABRIC handles take. The file alone does not tell: a container's device cgroup can still deny it.

vmm_unavailable_reason(export_handle_types=0) cached

Why VMM cannot be used on the current device, or None if it can.

Checks library load, entry points, known runtime defects (by probing), and one reserve/create/map/set-access/unmap/release round trip of a single granule, created with export_handle_types (see VmmDriver.create). Covers WSL2 and non-CUDA/ROCm builds.