|
5 | 5 | """
|
6 | 6 |
|
7 | 7 | import ctypes
|
| 8 | +import glob |
8 | 9 | from dataclasses import dataclass
|
9 | 10 | from typing import Any, Dict, List, Optional
|
10 | 11 |
|
11 | 12 | # this line makes it possible to directly load `libcudart.so` using `ctypes`
|
12 | 13 | import torch # noqa
|
13 | 14 |
|
| 15 | +import vllm.envs as envs |
14 | 16 | from vllm.logger import init_logger
|
15 | 17 |
|
16 | 18 | logger = init_logger(__name__)
|
@@ -60,6 +62,29 @@ def find_loaded_library(lib_name) -> Optional[str]:
|
60 | 62 | return path
|
61 | 63 |
|
62 | 64 |
|
| 65 | +def get_cudart_lib_path_from_env() -> Optional[str]: |
| 66 | + """ |
| 67 | + In some system, find_loaded_library() may not work. So we allow users to |
| 68 | + specify the path through environment variable VLLM_CUDART_SO_PATH. |
| 69 | + """ |
| 70 | + cudart_so_env = envs.VLLM_CUDART_SO_PATH |
| 71 | + if cudart_so_env is not None: |
| 72 | + cudart_paths = [ |
| 73 | + cudart_so_env, |
| 74 | + ] |
| 75 | + for path in cudart_paths: |
| 76 | + file_paths = glob.glob(path) |
| 77 | + if len(file_paths) > 0: |
| 78 | + logger.info( |
| 79 | + "Found cudart library at %s through env var" |
| 80 | + "VLLM_CUDART_SO_PATH=%s", |
| 81 | + file_paths[0], |
| 82 | + cudart_so_env, |
| 83 | + ) |
| 84 | + return file_paths[0] |
| 85 | + return None |
| 86 | + |
| 87 | + |
63 | 88 | class CudaRTLibrary:
|
64 | 89 | exported_functions = [
|
65 | 90 | # cudaError_t cudaSetDevice ( int device )
|
@@ -105,8 +130,13 @@ class CudaRTLibrary:
|
105 | 130 | def __init__(self, so_file: Optional[str] = None):
|
106 | 131 | if so_file is None:
|
107 | 132 | so_file = find_loaded_library("libcudart")
|
| 133 | + if so_file is None: |
| 134 | + so_file = get_cudart_lib_path_from_env() |
108 | 135 | assert so_file is not None, \
|
109 |
| - "libcudart is not loaded in the current process" |
| 136 | + ( |
| 137 | + "libcudart is not loaded in the current process, " |
| 138 | + "try setting VLLM_CUDART_SO_PATH" |
| 139 | + ) |
110 | 140 | if so_file not in CudaRTLibrary.path_to_library_cache:
|
111 | 141 | lib = ctypes.CDLL(so_file)
|
112 | 142 | CudaRTLibrary.path_to_library_cache[so_file] = lib
|
|
0 commit comments