A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 10, 15:15 UTC
refactor: find_loaded_library (#31866)
Signed-off-by: tjp_zju <tanjianpingzju1990@gmail.com> Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
tjp_zju committed
Jan 7, 2026 at 14:42 UTC
55caa6051d675148aba009c85618c6d3adf85091
3 files changed
+29
-54
vllm/device_allocator/cumem.py
+1
-27
@@ -19,37 +19,11 @@ import torch
19
20
from vllm.logger import init_logger
21
from vllm.utils.platform_utils import is_pin_memory_available
22
+from vllm.utils.system_utils import find_loaded_library
23
24
logger = init_logger(__name__)
25
26
26
-def find_loaded_library(lib_name) -> str | None:
27
- """
28
- According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
29
- the file `/proc/self/maps` contains the memory maps of the process, which includes the
30
- shared libraries loaded by the process. We can use this file to find the path of the
31
- a loaded library.
32
- """ # noqa
33
- found_line = None
34
- with open("/proc/self/maps") as f:
35
- for line in f:
36
- if lib_name in line:
37
- found_line = line
38
- break
39
- if found_line is None:
40
- # the library is not loaded in the current process
41
- return None
42
- # if lib_name is libcudart, we need to match a line with:
43
- # address /path/to/libcudart-hash.so.11.0
44
- start = found_line.index("/")
45
- path = found_line[start:].strip()
46
- filename = path.split("/")[-1]
47
- assert filename.rpartition(".so")[0].startswith(lib_name), (
48
- f"Unexpected filename: {filename} for library {lib_name}"
49
- )
50
- return path
51
-
52
-
27
cumem_available = False
28
try:
29
from vllm.cumem_allocator import (
vllm/distributed/device_communicators/cuda_wrapper.py
+1
-27
@@ -15,6 +15,7 @@ import torch # noqa
15
import vllm.envs as envs
16
from vllm.logger import init_logger
17
from vllm.platforms import current_platform
18
+from vllm.utils.system_utils import find_loaded_library
19
20
logger = init_logger(__name__)
21
@@ -37,33 +38,6 @@ class Function:
38
argtypes: list[Any]
39
40
40
-def find_loaded_library(lib_name) -> str | None:
41
- """
42
- According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
43
- the file `/proc/self/maps` contains the memory maps of the process, which includes the
44
- shared libraries loaded by the process. We can use this file to find the path of the
45
- a loaded library.
46
- """ # noqa
47
- found = False
48
- with open("/proc/self/maps") as f:
49
- for line in f:
50
- if lib_name in line:
51
- found = True
52
- break
53
- if not found:
54
- # the library is not loaded in the current process
55
- return None
56
- # if lib_name is libcudart, we need to match a line with:
57
- # address /path/to/libcudart-hash.so.11.0
58
- start = line.index("/")
59
- path = line[start:].strip()
60
- filename = path.split("/")[-1]
61
- assert filename.rpartition(".so")[0].startswith(lib_name), (
62
- f"Unexpected filename: {filename} for library {lib_name}"
63
- )
64
- return path
65
-
66
-
41
class CudaRTLibrary:
42
exported_functions = [
43
# cudaError_t cudaSetDevice ( int device )
vllm/utils/system_utils.py
+27
@@ -267,3 +267,30 @@ def set_ulimit(target_soft_limit: int = 65535):
267
current_soft,
268
e,
269
)
270
+
271
+
272
+def find_loaded_library(lib_name: str) -> str | None:
273
+ """
274
+ According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
275
+ the file `/proc/self/maps` contains the memory maps of the process, which includes the
276
+ shared libraries loaded by the process. We can use this file to find the path of the
277
+ a loaded library.
278
+ """ # noqa
279
+ found_line = None
280
+ with open("/proc/self/maps") as f:
281
+ for line in f:
282
+ if lib_name in line:
283
+ found_line = line
284
+ break
285
+ if found_line is None:
286
+ # the library is not loaded in the current process
287
+ return None
288
+ # if lib_name is libcudart, we need to match a line with:
289
+ # address /path/to/libcudart-hash.so.11.0
290
+ start = found_line.index("/")
291
+ path = found_line[start:].strip()
292
+ filename = path.split("/")[-1]
293
+ assert filename.rpartition(".so")[0].startswith(lib_name), (
294
+ f"Unexpected filename: {filename} for library {lib_name}"
295
+ )
296
+ return path