From 5fc328465ac7be8ef953fd3200951b56c92f0b4e Mon Sep 17 00:00:00 2001 From: blake-snc Date: Sun, 15 Feb 2026 08:43:04 -0800 Subject: [PATCH] fix(sgl-kernel): support CUDA 13 runtime preloading for DGX Spark (#18747) Co-authored-by: Claude Opus 4.6 --- sgl-kernel/python/sgl_kernel/load_utils.py | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/sgl-kernel/python/sgl_kernel/load_utils.py b/sgl-kernel/python/sgl_kernel/load_utils.py index d0b18d3fc..5c37402b3 100644 --- a/sgl-kernel/python/sgl_kernel/load_utils.py +++ b/sgl-kernel/python/sgl_kernel/load_utils.py @@ -166,6 +166,14 @@ def _load_architecture_specific_ops(): ) # All attempts failed + cuda_version = torch.version.cuda + if cuda_version and cuda_version.startswith("13"): + install_hint = ( + "pip install sgl-kernel --index-url https://docs.sglang.ai/whl/cu130/" + ) + else: + install_hint = "pip install --upgrade sgl_kernel" + error_msg = f""" [sgl_kernel] CRITICAL: Could not load any common_ops library! @@ -177,9 +185,10 @@ Attempted locations: GPU Info: - Compute capability: {compute_capability} - Expected variant: {variant_name} +- CUDA version: {cuda_version} Please ensure sgl_kernel is properly installed with: -pip install --upgrade sgl_kernel +{install_hint} Error details from previous import attempts: {attempt_error_msg} @@ -205,7 +214,7 @@ def _find_cuda_home(): def _preload_cuda_library(): - """Preload the CUDA runtime library to help avoid 'libcudart.so.12 not found' issues.""" + """Preload the CUDA runtime library to help avoid 'libcudart.so not found' issues.""" cuda_home = Path(_find_cuda_home()) candidate_dirs = [ @@ -217,16 +226,22 @@ def _preload_cuda_library(): Path("/usr/lib"), ] + # Determine CUDA major version to try the matching library first. + # On CUDA 13 systems (e.g., DGX Spark), only libcudart.so.13 exists. + cuda_major = torch.version.cuda.split(".")[0] if torch.version.cuda else "12" + lib_versions = list(dict.fromkeys([cuda_major, "13", "12"])) + 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 {candidate}: {e}") - continue + for lib_version in lib_versions: + candidate = base / f"libcudart.so.{lib_version}" + 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 {candidate}: {e}") + continue logger.debug("[sgl_kernel] Could not preload CUDA runtime library")