-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[sgl-kernel] fix runtime error while preloading CUDA runtime #13089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -205,20 +205,28 @@ def _find_cuda_home(): | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def _preload_cuda_library(): | ||||||||||||||||||||||||||||||||||
| """Preload the CUDA runtime library to help avoid 'libcudart.so.12 not found' issues.""" | ||||||||||||||||||||||||||||||||||
| cuda_home = Path(_find_cuda_home()) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (cuda_home / "lib").is_dir(): | ||||||||||||||||||||||||||||||||||
| cuda_path = cuda_home / "lib" | ||||||||||||||||||||||||||||||||||
| elif (cuda_home / "lib64").is_dir(): | ||||||||||||||||||||||||||||||||||
| cuda_path = cuda_home / "lib64" | ||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||
| # Search for 'libcudart.so.12' in subdirectories | ||||||||||||||||||||||||||||||||||
| for path in cuda_home.rglob("libcudart.so.12"): | ||||||||||||||||||||||||||||||||||
| cuda_path = path.parent | ||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||
| raise RuntimeError("Could not find CUDA lib directory.") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| cuda_include = (cuda_path / "libcudart.so.12").resolve() | ||||||||||||||||||||||||||||||||||
| if cuda_include.exists(): | ||||||||||||||||||||||||||||||||||
| ctypes.CDLL(str(cuda_include), mode=ctypes.RTLD_GLOBAL) | ||||||||||||||||||||||||||||||||||
| candidate_dirs = [ | ||||||||||||||||||||||||||||||||||
| cuda_home / "lib", | ||||||||||||||||||||||||||||||||||
| cuda_home / "lib64", | ||||||||||||||||||||||||||||||||||
| Path("/usr/lib/x86_64-linux-gnu"), | ||||||||||||||||||||||||||||||||||
| Path("/usr/lib/aarch64-linux-gnu"), | ||||||||||||||||||||||||||||||||||
| Path("/usr/lib64"), | ||||||||||||||||||||||||||||||||||
| Path("/usr/lib"), | ||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| for base in candidate_dirs: | ||||||||||||||||||||||||||||||||||
| candidate = base / "libcudart.so.12" | ||||||||||||||||||||||||||||||||||
| if candidate.exists(): | ||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||
| cuda_runtime_lib = candidate.resolve() | ||||||||||||||||||||||||||||||||||
| ctypes.CDLL(str(cuda_runtime_lib), mode=ctypes.RTLD_GLOBAL) | ||||||||||||||||||||||||||||||||||
| logger.debug(f"Preloaded CUDA runtime under {cuda_runtime_lib}") | ||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||
| logger.debug(f"Failed to load {cuda_runtime_lib}: {e}") | ||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||
anvdn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| logger.debug("[sgl_kernel] Could not preload CUDA runtime library") | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous implementation used
Suggested change
|
||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one promising way, to detect the lib in the env, would be detecting whether there are
nvidia-cuda-runtime-like packages (such packages can be found on pytorch pypi, and NVIDIA's nvidia-cuda-runtime-cu11, nvidia-cuda-runtime-cu12, nvidia-cuda-runtime) installed in the current env.If so, its paths could be also candidate dirs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on that. However, given we currently have no reason to believe we need to keep this pre-loading logic, maybe that's not worth the extra complexity right now? In particular, I don't see any such logic in vLLM repo. Wdyt?