vllm.utils.extensible_tensor
¶
Growable device byte buffers backed by GPU virtual memory management.
Classes:
-
ExtensibleTensor–A device byte buffer that grows without moving its base pointer.
Functions:
-
granule_size–Commit granule for device_index: driver granularity, floored at 2 MiB.
-
uint8_tensor_from_ptr–Wrap device memory at
ptras a uint8 tensor; the caller keeps it mapped.
ExtensibleTensor
¶
A device byte buffer that grows without moving its base pointer.
The reservation is divided into contiguous segments whose committed bytes
form a prefix of each; num_segments equal segments by default, or the
explicit segment_capacities (in bytes, summing to max_num_bytes).
Other processes can import the memory through export_handle_types (see
VmmDriver.create).
Methods:
-
full_view–Uint8 view spanning the whole reservation.
-
release_physical–Drop all physical pages but keep the reservation and its views.
-
resize_per_segment_–Grow every segment's committed prefix to the same size.
-
resize_segments_–Grow each segment's committed prefix; optionally zero the new bytes.
-
segment_view–Uint8 tensor over one segment's committed prefix, sized exactly to it.
-
segments_backed_by_one_chunk–Whether each segment's first
sizes[i]bytes lie within a single
Attributes:
-
bytes_per_segment(int) –Current committed prefix size of each segment in bytes (equal segments).
-
num_bytes(int) –Current committed size in bytes, summed over all segments.
-
num_physical_chunks(int) –Number of driver allocations currently mapped into the reservation.
-
physical_bytes(int) –Physically mapped bytes, including granule rounding.
-
segment_capacity_bytes(int) –Maximum size of each segment (equal segments).
-
segment_offsets(list[int]) –Byte offset of each segment within the reservation.
bytes_per_segment
property
¶
Current committed prefix size of each segment in bytes (equal segments).
num_bytes
property
¶
Current committed size in bytes, summed over all segments.
num_physical_chunks
property
¶
Number of driver allocations currently mapped into the reservation.
physical_bytes
property
¶
Physically mapped bytes, including granule rounding.
segment_capacity_bytes
property
¶
Maximum size of each segment (equal segments).
segment_offsets
property
¶
Byte offset of each segment within the reservation.
full_view()
¶
Uint8 view spanning the whole reservation.
release_physical()
¶
Drop all physical pages but keep the reservation and its views.
resize_per_segment_(bytes_per_segment, zero_new=False)
¶
Grow every segment's committed prefix to the same size.
resize_segments_(sizes, zero_new=False)
¶
Grow each segment's committed prefix; optionally zero the new bytes.
segment_view(index)
¶
Uint8 tensor over one segment's committed prefix, sized exactly to it.
segments_backed_by_one_chunk(sizes)
¶
Whether each segment's first sizes[i] bytes lie within a single
driver allocation, as RDMA registration of the segment requires.
_VirtualBuffer
¶
One device VA reservation and the physical chunks mapped into it.
Memory is committed in granules via ensure_committed_range; already-mapped
granules are skipped, so ranges may abut or overlap.
Methods:
-
ensure_committed_range–Map physical pages so that the byte range
[start, end)is backed. -
release_physical–Unmap and release all physical memory, keeping the VA reservation.
Attributes:
-
committed_bytes(int) –Total physically mapped bytes (a multiple of the granularity).
committed_bytes
property
¶
Total physically mapped bytes (a multiple of the granularity).
_grant_access(first, last)
¶
Grant device access over the granule run [first, last).
Per run rather than per chunk: ROCm rejects a set-access range that starts inside an already-mapped region. Re-granting is a cheap no-op.
_map_chunk_at(offset, size)
¶
Create one physical chunk of size bytes and map it at offset.
_run_bounds(first, last)
¶
Bounds of the maximal contiguous mapped run covering [first, last).
ensure_committed_range(start, end)
¶
Map physical pages so that the byte range [start, end) is backed.
release_physical()
¶
Unmap and release all physical memory, keeping the VA reservation.
granule_size(device_index)
¶
Commit granule for device_index: driver granularity, floored at 2 MiB.
uint8_tensor_from_ptr(ptr, num_bytes, device_index)
¶
Wrap device memory at ptr as a uint8 tensor; the caller keeps it mapped.
The DLManagedTensor is malloc'd and never freed: torch reads it when the view is destroyed, which can be after this module's globals are cleared at interpreter exit. Its deleter is NULL, so nothing calls back into Python.