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).
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.
Source code in vllm/utils/extensible_tensor.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
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()
¶
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.
Source code in vllm/utils/extensible_tensor.py
segment_view(index)
¶
Uint8 tensor over one segment's committed prefix, sized exactly to it.
Source code in vllm/utils/extensible_tensor.py
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.
Source code in vllm/utils/extensible_tensor.py
_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).
Source code in vllm/utils/extensible_tensor.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
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.
Source code in vllm/utils/extensible_tensor.py
_map_chunk_at(offset, size)
¶
Create one physical chunk of size bytes and map it at offset.
Source code in vllm/utils/extensible_tensor.py
_run_bounds(first, last)
¶
Bounds of the maximal contiguous mapped run covering [first, last).
Source code in vllm/utils/extensible_tensor.py
ensure_committed_range(start, end)
¶
Map physical pages so that the byte range [start, end) is backed.
Source code in vllm/utils/extensible_tensor.py
release_physical()
¶
Unmap and release all physical memory, keeping the VA reservation.
Source code in vllm/utils/extensible_tensor.py
granule_size(device_index)
¶
Commit granule for device_index: driver granularity, floored at 2 MiB.
Source code in vllm/utils/extensible_tensor.py
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.