@@ -44,6 +44,7 @@ find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
4444# ---------------------------------------------------------------------------
4545if (NOT GPU_BACKEND STREQUAL "ROCM" )
4646 if (DEFINED ENV{TORCH_CUDA_ARCH_LIST})
47+ set (TORCH_CUDA_ARCH_LIST "$ENV{TORCH_CUDA_ARCH_LIST} " )
4748 message (STATUS "CUDA arch: TORCH_CUDA_ARCH_LIST=$ENV{TORCH_CUDA_ARCH_LIST} (from environment)" )
4849 elseif (TORCH_CUDA_ARCH_LIST)
4950 set (ENV{TORCH_CUDA_ARCH_LIST} "${TORCH_CUDA_ARCH_LIST} " )
@@ -52,14 +53,14 @@ if(NOT GPU_BACKEND STREQUAL "ROCM")
5253 set (_FV_ARCH_LIST "" )
5354 if (_FASTVIDEO_USER_CUDA_ARCH)
5455 # Caller pinned -DCMAKE_CUDA_ARCHITECTURES (which torch ignores); translate it
55- # to the TORCH_CUDA_ARCH_LIST spelling: "121 " -> "12.1 ", "90a" -> "9.0a".
56+ # to the TORCH_CUDA_ARCH_LIST spelling: "121a " -> "12.1a ", "90a" -> "9.0a".
5657 # Only numeric spellings translate; keywords like "native"/"all" would
5758 # otherwise be mangled into nonsense ("nativ.e").
5859 foreach (_fv_arch IN LISTS _FASTVIDEO_USER_CUDA_ARCH)
5960 if (NOT _fv_arch MATCHES "^[0-9]+[af]?$" )
6061 message (FATAL_ERROR
6162 "fastvideo-kernel: CMAKE_CUDA_ARCHITECTURES='${_fv_arch} ' is not "
62- "supported. Use a numeric arch (e.g. 90a, 121 ), set "
63+ "supported. Use a numeric arch (e.g. 90a, 121a ), set "
6364 "TORCH_CUDA_ARCH_LIST directly (e.g. 9.0a), or unset both to "
6465 "auto-detect from the visible GPU." )
6566 endif ()
@@ -93,14 +94,26 @@ if(NOT GPU_BACKEND STREQUAL "ROCM")
9394 "fastvideo-kernel: could not determine the target CUDA architecture.\n "
9495 "Refusing to let torch auto-detect an arch that may not run on this GPU. "
9596 "Fix with one of:\n "
96- " - set TORCH_CUDA_ARCH_LIST (e.g. 12.1 , or 9.0a for Hopper), or\n "
97- " - pass -DCMAKE_CUDA_ARCHITECTURES=<arch> (e.g. 121 ), or\n "
97+ " - set TORCH_CUDA_ARCH_LIST (e.g. 12.1a , or 9.0a for Hopper), or\n "
98+ " - pass -DCMAKE_CUDA_ARCHITECTURES=<arch> (e.g. 121a ), or\n "
9899 " - build where the target GPU is visible to torch.\n "
99100 "Note: 'pip/uv pip install' builds under build isolation, which hides the "
100101 "GPU; set TORCH_CUDA_ARCH_LIST or add --no-build-isolation. "
101102 "fastvideo-kernel/build.sh sets all of this for you." )
102103 endif ()
103104 endif ()
105+
106+ string (REGEX MATCH "(^|[; ,])((12\\ .0a)|(120a)|(sm_120a))([; ,]|$)"
107+ _FV_HAS_120A "${TORCH_CUDA_ARCH_LIST} " )
108+ string (REGEX MATCH "(^|[; ,])((12\\ .1a)|(121a)|(sm_121a))([; ,]|$)"
109+ _FV_HAS_121A "${TORCH_CUDA_ARCH_LIST} " )
110+ if (_FV_HAS_121A AND CUDAToolkit_VERSION VERSION_LESS 13.0)
111+ message (FATAL_ERROR
112+ "fastvideo-kernel: sm_121a requires CUDA Toolkit 13.0+, but found "
113+ "${CUDAToolkit_VERSION} . Architecture-specific sm_120a code is not "
114+ "compatible with sm_121; use CUDA 13 or remove 12.1a from "
115+ "TORCH_CUDA_ARCH_LIST." )
116+ endif ()
104117endif ()
105118
106119# Robustly find Torch include paths using Python
@@ -268,13 +281,7 @@ else()
268281 set (_WANTS_ATTN_QAT_INFER ON )
269282 elseif (FASTVIDEO_KERNEL_BUILD_ATTN_QAT_INFER STREQUAL "AUTO" )
270283 if (TORCH_CUDA_ARCH_LIST)
271- # Consumer/workstation Blackwell: sm_120a (RTX 5090 / PRO 6000) and
272- # sm_121a (DGX Spark GB10). The block-scaled FP4 MMA is valid on both
273- # (GB10-verified: cos ~0.98 vs bf16 SDPA across shapes).
274- string (REGEX MATCH
275- "(^|[; ,])((12\\ .0a)|(120a)|(sm_120a)|(12\\ .1a)|(121a)|(sm_121a))([; ,]|$)"
276- _HAS_BLACKWELL_FP4 "${TORCH_CUDA_ARCH_LIST} " )
277- if (_HAS_BLACKWELL_FP4)
284+ if (_FV_HAS_120A OR _FV_HAS_121A)
278285 set (_WANTS_ATTN_QAT_INFER ON )
279286 endif ()
280287 else ()
@@ -302,6 +309,18 @@ else()
302309 endif ()
303310
304311 if (ENABLE_ATTN_QAT_INFER)
312+ set (FASTVIDEO_FP4_CUDA_ARCHS "" )
313+ if (_FV_HAS_120A)
314+ list (APPEND FASTVIDEO_FP4_CUDA_ARCHS "120a" )
315+ endif ()
316+ if (_FV_HAS_121A)
317+ list (APPEND FASTVIDEO_FP4_CUDA_ARCHS "121a" )
318+ endif ()
319+ if (NOT FASTVIDEO_FP4_CUDA_ARCHS)
320+ message (FATAL_ERROR
321+ "FASTVIDEO_KERNEL_BUILD_ATTN_QAT_INFER=ON requires 12.0a or "
322+ "12.1a in TORCH_CUDA_ARCH_LIST; got '${TORCH_CUDA_ARCH_LIST} '." )
323+ endif ()
305324 message (STATUS "attn_qat_infer kernels: ENABLED" )
306325 else ()
307326 message (STATUS
@@ -333,14 +352,6 @@ if(ENABLE_ATTN_QAT_INFER AND TORCH_CUDA_ARCH_LIST)
333352 set (FASTVIDEO_MAIN_CUDA_ARCHS "${TORCH_CUDA_ARCH_LIST} " )
334353 string (REPLACE "sm_" "" FASTVIDEO_MAIN_CUDA_ARCHS "${FASTVIDEO_MAIN_CUDA_ARCHS} " )
335354 string (REPLACE "." "" FASTVIDEO_MAIN_CUDA_ARCHS "${FASTVIDEO_MAIN_CUDA_ARCHS} " )
336- # sm_121a needs CUDA 13's ptxas. On older toolchains, downgrade any requested
337- # 121a to 120a for the *main* extension too (not just the fp4* targets below),
338- # so a CUDA-12.x build with 12.1a in the arch list doesn't fail to compile —
339- # sm_120a PTX forward-JITs to sm_121 at runtime.
340- if (CUDAToolkit_VERSION VERSION_LESS 13.0)
341- string (REPLACE "121a" "120a" FASTVIDEO_MAIN_CUDA_ARCHS "${FASTVIDEO_MAIN_CUDA_ARCHS} " )
342- list (REMOVE_DUPLICATES FASTVIDEO_MAIN_CUDA_ARCHS)
343- endif ()
344355 message (STATUS "[per-arch] main extension archs=${FASTVIDEO_MAIN_CUDA_ARCHS} , fp4* archs set per-target below" )
345356endif ()
346357
@@ -526,15 +537,8 @@ if(ENABLE_ATTN_QAT_INFER)
526537 $<$<COMPILE_LANGUAGE :CXX >:-O3 -std =c ++17>
527538 $<$<COMPILE_LANGUAGE :CUDA >:${ATTN_QAT_INFER_CUDA_FLAGS} >
528539 )
529- # FP4 kernels target consumer/workstation Blackwell: sm_120a (RTX 5090 /
530- # PRO 6000) and sm_121a (DGX Spark GB10). sm_121a needs CUDA 13's ptxas
531- # (CUDA 12.x lacks it), so it is added only on CUDA >= 13.0 — older
532- # toolchains keep the original sm_120a-only build unchanged. sm_121a
533- # GB10-verified (cos ~0.98 vs bf16).
534- set (FASTVIDEO_FP4_CUDA_ARCHS "120a" )
535- if (NOT CUDAToolkit_VERSION VERSION_LESS 13.0)
536- list (APPEND FASTVIDEO_FP4_CUDA_ARCHS "121a" )
537- endif ()
540+ # Compile only the FP4 architectures requested by the caller. The large
541+ # template translation units use 8-12 GiB each, so an extra target matters.
538542 message (STATUS "fp4* CUDA architectures: ${FASTVIDEO_FP4_CUDA_ARCHS} " )
539543 set_target_properties (fp4attn_cuda PROPERTIES
540544 CUDA_ARCHITECTURES "${FASTVIDEO_FP4_CUDA_ARCHS} "
@@ -576,6 +580,6 @@ message(STATUS "TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST}")
576580message (STATUS "fastvideo_kernel_ops: ON (turbodiffusion int8-gemm/quant/rmsnorm/layernorm, all listed archs)" )
577581message (STATUS " + TK sta/block_sparse (sm_90a only): ${ENABLE_TK_KERNELS} " )
578582message (STATUS " + Ulysses NCCL-device all-to-all: ${ENABLE_ULYSSES_A2A} " )
579- message (STATUS "fp4attn/fp4quant (sm_120a/sm_121a, CUDA >= 12.8): ${ENABLE_ATTN_QAT_INFER} " )
583+ message (STATUS "fp4attn/fp4quant (sm_120a CUDA >= 12.8; sm_121a CUDA >= 13 ): ${ENABLE_ATTN_QAT_INFER} " )
580584message (STATUS "Triton fallbacks ship in python/fastvideo_kernel/triton_kernels regardless." )
581585message (STATUS "============================================================" )
0 commit comments