Skip to content

Commit 86776ad

Browse files
[bugfix]: gate SM103 VSA build on CUDA 12.9
Keep CUDA 12.8 GB200 builds from receiving the unsupported compute_103a gencode. Export whether the extension actually contains an SM103a image so runtime dispatch falls back safely when a CUDA 12.8 build is moved to B300.
1 parent 7bb76b5 commit 86776ad

4 files changed

Lines changed: 54 additions & 5 deletions

File tree

fastvideo-kernel/CMakeLists.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ if(BUILD_CXX_KERNELS)
397397
# the cmake variable stays empty, so testing that alone silently skips the kernel and
398398
# leaves a build that succeeds with the op missing.
399399
set(ENABLE_VSA_SM100_FAMILY OFF)
400+
set(ENABLE_VSA_SM103A OFF)
400401
set(_VSA_ARCH_LIST "${TORCH_CUDA_ARCH_LIST}")
401402
if(NOT _VSA_ARCH_LIST AND DEFINED ENV{TORCH_CUDA_ARCH_LIST})
402403
set(_VSA_ARCH_LIST "$ENV{TORCH_CUDA_ARCH_LIST}")
@@ -405,12 +406,32 @@ if(BUILD_CXX_KERNELS)
405406
set(ENABLE_VSA_SM100_FAMILY ON)
406407
endif()
407408
if(ENABLE_VSA_SM100_FAMILY)
408-
message(STATUS "fastvideo-kernel: building block_sparse_sm100a (sm_100a/sm_103a, 64- and 128-token blocks)")
409+
set(_VSA_COMPILE_OPTIONS
410+
"-gencode"
411+
"arch=compute_100a,code=sm_100a"
412+
)
413+
set(_VSA_NATIVE_ARCHS "sm_100a")
414+
# CUDA 12.9 introduced the SM103 compiler target. Keep CUDA 12.8
415+
# GB200 builds working instead of passing nvcc an unknown compute_103a.
416+
if(NOT CUDAToolkit_VERSION VERSION_LESS 12.9)
417+
list(APPEND _VSA_COMPILE_OPTIONS
418+
"-gencode"
419+
"arch=compute_103a,code=sm_103a"
420+
)
421+
list(APPEND _VSA_NATIVE_ARCHS "sm_103a")
422+
set(ENABLE_VSA_SM103A ON)
423+
endif()
424+
list(APPEND _VSA_COMPILE_OPTIONS "-DVSA_BHSD=true")
425+
string(JOIN "/" _VSA_NATIVE_ARCHS_DISPLAY ${_VSA_NATIVE_ARCHS})
426+
message(STATUS
427+
"fastvideo-kernel: building block_sparse_sm100a "
428+
"(${_VSA_NATIVE_ARCHS_DISPLAY}, 64- and 128-token blocks)"
429+
)
409430
list(APPEND EXTENSION_SOURCES csrc/attention/block_sparse_sm100a.cu
410431
csrc/attention/block_sparse_blk128_sm100a.cu)
411432
set_source_files_properties(csrc/attention/block_sparse_sm100a.cu
412433
csrc/attention/block_sparse_blk128_sm100a.cu PROPERTIES
413-
COMPILE_OPTIONS "-gencode;arch=compute_100a,code=sm_100a;-gencode;arch=compute_103a,code=sm_103a;-DVSA_BHSD=true")
434+
COMPILE_OPTIONS "${_VSA_COMPILE_OPTIONS}")
414435
endif()
415436

416437
Python_add_library(fastvideo_kernel_ops MODULE USE_SABI ${SKBUILD_SABI_VERSION} WITH_SOABI
@@ -431,6 +452,9 @@ if(BUILD_CXX_KERNELS)
431452
if(ENABLE_VSA_SM100_FAMILY)
432453
list(APPEND COMPILE_DEFS TK_COMPILE_BLOCK_SPARSE_VSA_SM100A)
433454
endif()
455+
if(ENABLE_VSA_SM103A)
456+
list(APPEND COMPILE_DEFS TK_COMPILE_BLOCK_SPARSE_VSA_SM103A)
457+
endif()
434458
if(ENABLE_TK_KERNELS)
435459
list(APPEND COMPILE_DEFS TK_COMPILE_ST_ATTN TK_COMPILE_BLOCK_SPARSE)
436460
endif()

fastvideo-kernel/csrc/common_extension.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
5454
m.def("block_sparse_sm100a_blk128_fwd",
5555
torch::wrap_pybind_function(block_sparse_sm100a_blk128_fwd),
5656
"VSA block-sparse attention forward, 128-token blocks (Blackwell sm100a/sm103a)");
57+
#ifdef TK_COMPILE_BLOCK_SPARSE_VSA_SM103A
58+
m.attr("_has_vsa_sm103a") = true;
59+
#else
60+
m.attr("_has_vsa_sm103a") = false;
61+
#endif
5762
#endif
5863

5964
#ifdef TK_COMPILE_ST_ATTN

fastvideo-kernel/python/fastvideo_kernel/block_sparse_attn_sm100a.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0
22
"""Data-center Blackwell CUDA block-sparse VSA forward.
33
4-
The historical ``sm100a`` module and symbol names are retained for compatibility, but the
5-
extension carries native sm_100a and sm_103a images and supports both device generations.
4+
The historical ``sm100a`` module and symbol names are retained for compatibility. The
5+
extension always carries a native sm_100a image and also carries sm_103a when built with
6+
CUDA 12.9 or newer.
67
78
A third backend behind the same VSA op as the Triton and CuTe-DSL paths. Forward only: it
89
returns ``(out, lse)`` with ``lse`` in exactly the form ``triton_block_sparse_attn_forward``
@@ -29,12 +30,16 @@
2930
128: getattr(_C, "block_sparse_sm100a_blk128_fwd", None),
3031
}
3132
_HAS_VSA_SM100A = any(_FWD_BY_BLOCK.values())
33+
_HAS_VSA_SM103A = bool(getattr(_C, "_has_vsa_sm103a", False))
3234
except ImportError: # pragma: no cover - extension not built
3335
_C = None
3436
_FWD_BY_BLOCK = {}
3537
_HAS_VSA_SM100A = False
38+
_HAS_VSA_SM103A = False
3639

37-
_SUPPORTED_COMPUTE_CAPABILITIES = {(10, 0), (10, 3)}
40+
_SUPPORTED_COMPUTE_CAPABILITIES = {(10, 0)}
41+
if _HAS_VSA_SM103A:
42+
_SUPPORTED_COMPUTE_CAPABILITIES.add((10, 3))
3843
HEAD_DIM = 128
3944
# Must match the -DVSA_BHSD the extension was compiled with (see CMakeLists).
4045
BHSD = True

tests/test_fasth3_packaging.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,18 @@ def test_kernel_release_matrix_can_publish_data_center_blackwell_wheels():
3939
assert "arch=compute_100a,code=sm_100a" in cmake
4040
assert "arch=compute_103a,code=sm_103a" in cmake
4141
assert "patchelf==0.17.2.4" in workflow
42+
43+
44+
def test_sm103a_gencode_requires_cuda_12_9():
45+
cmake = (REPO_ROOT / "fastvideo-kernel" / "CMakeLists.txt").read_text(encoding="utf-8")
46+
extension = (REPO_ROOT / "fastvideo-kernel" / "csrc" / "common_extension.cpp").read_text(encoding="utf-8")
47+
backend = (REPO_ROOT / "fastvideo-kernel" / "python" / "fastvideo_kernel" /
48+
"block_sparse_attn_sm100a.py").read_text(encoding="utf-8")
49+
vsa_options = cmake.index("set(_VSA_COMPILE_OPTIONS")
50+
sm103_guard = cmake.index("if(NOT CUDAToolkit_VERSION VERSION_LESS 12.9)", vsa_options)
51+
sm103_gencode = cmake.index("arch=compute_103a,code=sm_103a", sm103_guard)
52+
53+
assert sm103_guard < sm103_gencode < cmake.index("endif()", sm103_guard)
54+
assert "list(APPEND COMPILE_DEFS TK_COMPILE_BLOCK_SPARSE_VSA_SM103A)" in cmake
55+
assert 'm.attr("_has_vsa_sm103a") = true' in extension
56+
assert 'getattr(_C, "_has_vsa_sm103a", False)' in backend

0 commit comments

Comments
 (0)