refactor: find_loaded_library (#31866)
Signed-off-by: tjp_zju <tanjianpingzju1990@gmail.com> Co-authored-by: Cyrus Leung <cyrus.tl.leung@gmail.com>
This commit is contained in:
@@ -19,37 +19,11 @@ import torch
|
|||||||
|
|
||||||
from vllm.logger import init_logger
|
from vllm.logger import init_logger
|
||||||
from vllm.utils.platform_utils import is_pin_memory_available
|
from vllm.utils.platform_utils import is_pin_memory_available
|
||||||
|
from vllm.utils.system_utils import find_loaded_library
|
||||||
|
|
||||||
logger = init_logger(__name__)
|
logger = init_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def find_loaded_library(lib_name) -> str | None:
|
|
||||||
"""
|
|
||||||
According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
|
|
||||||
the file `/proc/self/maps` contains the memory maps of the process, which includes the
|
|
||||||
shared libraries loaded by the process. We can use this file to find the path of the
|
|
||||||
a loaded library.
|
|
||||||
""" # noqa
|
|
||||||
found_line = None
|
|
||||||
with open("/proc/self/maps") as f:
|
|
||||||
for line in f:
|
|
||||||
if lib_name in line:
|
|
||||||
found_line = line
|
|
||||||
break
|
|
||||||
if found_line is None:
|
|
||||||
# the library is not loaded in the current process
|
|
||||||
return None
|
|
||||||
# if lib_name is libcudart, we need to match a line with:
|
|
||||||
# address /path/to/libcudart-hash.so.11.0
|
|
||||||
start = found_line.index("/")
|
|
||||||
path = found_line[start:].strip()
|
|
||||||
filename = path.split("/")[-1]
|
|
||||||
assert filename.rpartition(".so")[0].startswith(lib_name), (
|
|
||||||
f"Unexpected filename: {filename} for library {lib_name}"
|
|
||||||
)
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
cumem_available = False
|
cumem_available = False
|
||||||
try:
|
try:
|
||||||
from vllm.cumem_allocator import (
|
from vllm.cumem_allocator import (
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import torch # noqa
|
|||||||
import vllm.envs as envs
|
import vllm.envs as envs
|
||||||
from vllm.logger import init_logger
|
from vllm.logger import init_logger
|
||||||
from vllm.platforms import current_platform
|
from vllm.platforms import current_platform
|
||||||
|
from vllm.utils.system_utils import find_loaded_library
|
||||||
|
|
||||||
logger = init_logger(__name__)
|
logger = init_logger(__name__)
|
||||||
|
|
||||||
@@ -37,33 +38,6 @@ class Function:
|
|||||||
argtypes: list[Any]
|
argtypes: list[Any]
|
||||||
|
|
||||||
|
|
||||||
def find_loaded_library(lib_name) -> str | None:
|
|
||||||
"""
|
|
||||||
According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
|
|
||||||
the file `/proc/self/maps` contains the memory maps of the process, which includes the
|
|
||||||
shared libraries loaded by the process. We can use this file to find the path of the
|
|
||||||
a loaded library.
|
|
||||||
""" # noqa
|
|
||||||
found = False
|
|
||||||
with open("/proc/self/maps") as f:
|
|
||||||
for line in f:
|
|
||||||
if lib_name in line:
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if not found:
|
|
||||||
# the library is not loaded in the current process
|
|
||||||
return None
|
|
||||||
# if lib_name is libcudart, we need to match a line with:
|
|
||||||
# address /path/to/libcudart-hash.so.11.0
|
|
||||||
start = line.index("/")
|
|
||||||
path = line[start:].strip()
|
|
||||||
filename = path.split("/")[-1]
|
|
||||||
assert filename.rpartition(".so")[0].startswith(lib_name), (
|
|
||||||
f"Unexpected filename: {filename} for library {lib_name}"
|
|
||||||
)
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
class CudaRTLibrary:
|
class CudaRTLibrary:
|
||||||
exported_functions = [
|
exported_functions = [
|
||||||
# cudaError_t cudaSetDevice ( int device )
|
# cudaError_t cudaSetDevice ( int device )
|
||||||
|
|||||||
@@ -267,3 +267,30 @@ def set_ulimit(target_soft_limit: int = 65535):
|
|||||||
current_soft,
|
current_soft,
|
||||||
e,
|
e,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def find_loaded_library(lib_name: str) -> str | None:
|
||||||
|
"""
|
||||||
|
According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
|
||||||
|
the file `/proc/self/maps` contains the memory maps of the process, which includes the
|
||||||
|
shared libraries loaded by the process. We can use this file to find the path of the
|
||||||
|
a loaded library.
|
||||||
|
""" # noqa
|
||||||
|
found_line = None
|
||||||
|
with open("/proc/self/maps") as f:
|
||||||
|
for line in f:
|
||||||
|
if lib_name in line:
|
||||||
|
found_line = line
|
||||||
|
break
|
||||||
|
if found_line is None:
|
||||||
|
# the library is not loaded in the current process
|
||||||
|
return None
|
||||||
|
# if lib_name is libcudart, we need to match a line with:
|
||||||
|
# address /path/to/libcudart-hash.so.11.0
|
||||||
|
start = found_line.index("/")
|
||||||
|
path = found_line[start:].strip()
|
||||||
|
filename = path.split("/")[-1]
|
||||||
|
assert filename.rpartition(".so")[0].startswith(lib_name), (
|
||||||
|
f"Unexpected filename: {filename} for library {lib_name}"
|
||||||
|
)
|
||||||
|
return path
|
||||||
|
|||||||
Reference in New Issue
Block a user