From 603f5ce0204f854c7d090c302fe2c86c75f23767 Mon Sep 17 00:00:00 2001 From: Liangsheng Yin Date: Sun, 3 Aug 2025 06:23:11 +0800 Subject: [PATCH] [Bug] fix green context's incompatibility with `cuda < 12.4` (#8701) --- sgl-kernel/csrc/spatial/greenctx_stream.cu | 17 +++++++++++++++++ sgl-kernel/python/sgl_kernel/spatial.py | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/sgl-kernel/csrc/spatial/greenctx_stream.cu b/sgl-kernel/csrc/spatial/greenctx_stream.cu index 9d7a44a1a..cf3e7da65 100644 --- a/sgl-kernel/csrc/spatial/greenctx_stream.cu +++ b/sgl-kernel/csrc/spatial/greenctx_stream.cu @@ -7,6 +7,8 @@ #include "cuda_utils.h" #include "greenctx_stream.h" +#if CUDA_VERSION >= 12040 + static std::vector create_greenctx_stream_fallback(CUgreenCtx gctx[2]) { CUstream streamA, streamB; CUcontext ctx; @@ -94,3 +96,18 @@ std::vector create_greenctx_stream_by_value(int64_t smA, int64_t smB, i return vec; } + +#else + +std::vector create_greenctx_stream_by_value(int64_t smA, int64_t smB, int64_t device) { + TORCH_CHECK( + false, + "Green Contexts feature requires CUDA Toolkit 12.4 or newer. Current CUDA version: " + + std::to_string(CUDA_VERSION)); + + // This is a stub function that should never be reached + // Return empty vector to satisfy return type requirement + return {}; +} + +#endif diff --git a/sgl-kernel/python/sgl_kernel/spatial.py b/sgl-kernel/python/sgl_kernel/spatial.py index 8fe2a3dd7..25490d253 100644 --- a/sgl-kernel/python/sgl_kernel/spatial.py +++ b/sgl-kernel/python/sgl_kernel/spatial.py @@ -14,6 +14,11 @@ def create_greenctx_stream_by_value( Returns: tuple[ExternalStream, ExternalStream]: The two streams. """ + if torch.version.cuda < "12.4": + raise RuntimeError( + "Green Contexts feature requires CUDA Toolkit 12.4 or newer." + ) + if device_id is None: device_id = torch.cuda.current_device()