@@ -255,6 +255,29 @@ def _nvidia_cudart_include_dir() -> str:
255255 return str (include_dir ) if include_dir .exists () else ""
256256
257257
258+ @functools .lru_cache (maxsize = None )
259+ def _is_cusolvermp_installed_in_system () -> bool :
260+ """Check if cuSolverMp is registered in the system library cache."""
261+
262+ if platform .system () != "Linux" :
263+ return False
264+
265+ try :
266+ result = subprocess .run (
267+ ["ldconfig" , "-p" ],
268+ capture_output = True ,
269+ text = True ,
270+ check = False ,
271+ )
272+ except (OSError , subprocess .SubprocessError ):
273+ return False
274+
275+ if result .returncode != 0 :
276+ return False
277+
278+ return any ("cusolvermp" in line .lower () for line in result .stdout .splitlines ())
279+
280+
258281@functools .lru_cache (maxsize = None )
259282def _load_cuda_library_from_python (lib_name : str , strict : bool = False ):
260283 """
@@ -369,6 +392,11 @@ def _load_core_library():
369392 _ , _CUDNN_LIB_CTYPES = _load_cuda_library ("cudnn" )
370393 system_nvrtc , _NVRTC_LIB_CTYPES = _load_cuda_library ("nvrtc" )
371394 system_curand , _CURAND_LIB_CTYPES = _load_cuda_library ("curand" )
395+ _CUSOLVERMP_LIB_CTYPES = None
396+ if not _is_cusolvermp_installed_in_system () and any (
397+ _is_package_installed (p ) for p in ("nvidia-cusolvermp-cu12" , "nvidia-cusolvermp-cu13" )
398+ ):
399+ _ , _CUSOLVERMP_LIB_CTYPES = _load_cuda_library_from_python ("cusolverMp" , strict = False )
372400
373401 # This additional step is necessary to be able to install TE wheels
374402 # and import TE (without any guards) in an environment where the cuda
0 commit comments