Skip to content

Commit ee855a6

Browse files
committed
Add Linux support for loading libcupti.so.12 and libcupti.so.13
This commit adds support for finding and loading CUPTI libraries on Linux through cuda.pathfinder. It implements support for all enumerated installation methods: - Site-packages: nvidia/cuda_cupti/lib (CUDA 12) and nvidia/cu13/lib (CUDA 13) - Conda: $CONDA_PREFIX/lib (colocated with other CUDA libraries) - CTK via CUDA_HOME: $CUDA_HOME/extras/CUPTI/lib64 - CTK via canary probe: system CTK root discovery (similar to nvvm) Changes: - Add 'cupti' to supported library names and SONAMEs - Add site-packages paths for CUDA 12 and 13 - Add cupti to CTK root canary discoverable libraries - Update find_nvidia_dynamic_lib to handle extras/CUPTI/lib64 path - Add logic to distinguish CTK (extras/CUPTI/lib64) vs conda (lib) paths - Update _find_so_using_lib_dir to support versioned libraries via glob - Add comprehensive mock tests covering all installation methods Fixes #1572 (Linux support) Made-with: Cursor
1 parent 8d0ccdd commit ee855a6

File tree

3 files changed

+388
-4
lines changed

3 files changed

+388
-4
lines changed

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/find_nvidia_dynamic_lib.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _find_dll_using_nvidia_bin_dirs(
8080

8181
def _find_lib_dir_using_anchor_point(libname: str, anchor_point: str, linux_lib_dir: str) -> str | None:
8282
# Resolve paths for the four cases:
83-
# Windows/Linux x nvvm yes/no
83+
# Windows/Linux x nvvm/cupti yes/no
8484
if IS_WINDOWS:
8585
if libname == "nvvm": # noqa: SIM108
8686
rel_paths = [
@@ -93,8 +93,15 @@ def _find_lib_dir_using_anchor_point(libname: str, anchor_point: str, linux_lib_
9393
"bin", # CTK 12
9494
]
9595
else:
96-
if libname == "nvvm": # noqa: SIM108
96+
if libname == "nvvm":
9797
rel_paths = ["nvvm/lib64"]
98+
elif libname == "cupti":
99+
# cupti is in extras/CUPTI/lib64 for CTK, but in lib for conda
100+
# Check if this looks like a CTK root (has extras/CUPTI) or conda (uses linux_lib_dir)
101+
if os.path.isdir(os.path.join(anchor_point, "extras", "CUPTI")):
102+
rel_paths = ["extras/CUPTI/lib64"]
103+
else:
104+
rel_paths = [linux_lib_dir]
98105
else:
99106
rel_paths = [linux_lib_dir]
100107

@@ -128,7 +135,12 @@ def _find_so_using_lib_dir(
128135
so_name = os.path.join(lib_dir, so_basename)
129136
if os.path.isfile(so_name):
130137
return so_name
131-
error_messages.append(f"No such file: {so_name}")
138+
# Look for a versioned library using glob (e.g., libcupti.so.12, libcupti.so.13)
139+
file_wild = so_basename + "*"
140+
for so_name in sorted(glob.glob(os.path.join(lib_dir, file_wild))):
141+
if os.path.isfile(so_name):
142+
return so_name
143+
error_messages.append(f"No such file: {file_wild}")
132144
attachments.append(f' listdir("{lib_dir}"):')
133145
if not os.path.isdir(lib_dir):
134146
attachments.append(" DIRECTORY DOES NOT EXIST")

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/supported_nvidia_libs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
SUPPORTED_LIBNAMES_LINUX_ONLY = (
5252
"cufile",
5353
# "cufile_rdma", # Requires libmlx5.so
54+
"cupti",
5455
)
5556
SUPPORTED_LIBNAMES_LINUX = SUPPORTED_LIBNAMES_COMMON + SUPPORTED_LIBNAMES_LINUX_ONLY
5657

@@ -201,6 +202,10 @@
201202
"libnvrtc.so.13",
202203
),
203204
"nvvm": ("libnvvm.so.4",),
205+
"cupti": (
206+
"libcupti.so.12",
207+
"libcupti.so.13",
208+
),
204209
}
205210
SUPPORTED_LINUX_SONAMES_OTHER = {
206211
"cublasmp": ("libcublasmp.so.0",),
@@ -363,7 +368,7 @@
363368
# CTK root in an isolated child process.
364369
# - discoverable libs: libs that are allowed to use the CTK-root canary fallback.
365370
_CTK_ROOT_CANARY_ANCHOR_LIBNAMES = ("cudart",)
366-
_CTK_ROOT_CANARY_DISCOVERABLE_LIBNAMES = ("nvvm",)
371+
_CTK_ROOT_CANARY_DISCOVERABLE_LIBNAMES = ("nvvm", "cupti")
367372

368373
# Based on output of toolshed/make_site_packages_libdirs_linux.py
369374
SITE_PACKAGES_LIBDIRS_LINUX_CTK = {
@@ -395,6 +400,7 @@
395400
"nvjpeg": ("nvidia/cu13/lib", "nvidia/nvjpeg/lib"),
396401
"nvrtc": ("nvidia/cu13/lib", "nvidia/cuda_nvrtc/lib"),
397402
"nvvm": ("nvidia/cu13/lib", "nvidia/cuda_nvcc/nvvm/lib64"),
403+
"cupti": ("nvidia/cu13/lib", "nvidia/cuda_cupti/lib"),
398404
}
399405
SITE_PACKAGES_LIBDIRS_LINUX_OTHER = {
400406
"cublasmp": ("nvidia/cublasmp/cu13/lib", "nvidia/cublasmp/cu12/lib"),

0 commit comments

Comments
 (0)