@@ -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
@@ -208,13 +221,7 @@ else()
208221 set (_WANTS_ATTN_QAT_INFER ON )
209222 elseif (FASTVIDEO_KERNEL_BUILD_ATTN_QAT_INFER STREQUAL "AUTO" )
210223 if (TORCH_CUDA_ARCH_LIST)
211- # Consumer/workstation Blackwell: sm_120a (RTX 5090 / PRO 6000) and
212- # sm_121a (DGX Spark GB10). The block-scaled FP4 MMA is valid on both
213- # (GB10-verified: cos ~0.98 vs bf16 SDPA across shapes).
214- string (REGEX MATCH
215- "(^|[; ,])((12\\ .0a)|(120a)|(sm_120a)|(12\\ .1a)|(121a)|(sm_121a))([; ,]|$)"
216- _HAS_BLACKWELL_FP4 "${TORCH_CUDA_ARCH_LIST} " )
217- if (_HAS_BLACKWELL_FP4)
224+ if (_FV_HAS_120A OR _FV_HAS_121A)
218225 set (_WANTS_ATTN_QAT_INFER ON )
219226 endif ()
220227 else ()
@@ -242,6 +249,18 @@ else()
242249 endif ()
243250
244251 if (ENABLE_ATTN_QAT_INFER)
252+ set (FASTVIDEO_FP4_CUDA_ARCHS "" )
253+ if (_FV_HAS_120A)
254+ list (APPEND FASTVIDEO_FP4_CUDA_ARCHS "120a" )
255+ endif ()
256+ if (_FV_HAS_121A)
257+ list (APPEND FASTVIDEO_FP4_CUDA_ARCHS "121a" )
258+ endif ()
259+ if (NOT FASTVIDEO_FP4_CUDA_ARCHS)
260+ message (FATAL_ERROR
261+ "FASTVIDEO_KERNEL_BUILD_ATTN_QAT_INFER=ON requires 12.0a or "
262+ "12.1a in TORCH_CUDA_ARCH_LIST; got '${TORCH_CUDA_ARCH_LIST} '." )
263+ endif ()
245264 message (STATUS "attn_qat_infer kernels: ENABLED" )
246265 else ()
247266 message (STATUS
@@ -273,14 +292,6 @@ if(ENABLE_ATTN_QAT_INFER AND TORCH_CUDA_ARCH_LIST)
273292 set (FASTVIDEO_MAIN_CUDA_ARCHS "${TORCH_CUDA_ARCH_LIST} " )
274293 string (REPLACE "sm_" "" FASTVIDEO_MAIN_CUDA_ARCHS "${FASTVIDEO_MAIN_CUDA_ARCHS} " )
275294 string (REPLACE "." "" FASTVIDEO_MAIN_CUDA_ARCHS "${FASTVIDEO_MAIN_CUDA_ARCHS} " )
276- # sm_121a needs CUDA 13's ptxas. On older toolchains, downgrade any requested
277- # 121a to 120a for the *main* extension too (not just the fp4* targets below),
278- # so a CUDA-12.x build with 12.1a in the arch list doesn't fail to compile —
279- # sm_120a PTX forward-JITs to sm_121 at runtime.
280- if (CUDAToolkit_VERSION VERSION_LESS 13.0)
281- string (REPLACE "121a" "120a" FASTVIDEO_MAIN_CUDA_ARCHS "${FASTVIDEO_MAIN_CUDA_ARCHS} " )
282- list (REMOVE_DUPLICATES FASTVIDEO_MAIN_CUDA_ARCHS)
283- endif ()
284295 message (STATUS "[per-arch] main extension archs=${FASTVIDEO_MAIN_CUDA_ARCHS} , fp4* archs set per-target below" )
285296endif ()
286297
@@ -421,15 +432,8 @@ if(ENABLE_ATTN_QAT_INFER)
421432 $<$<COMPILE_LANGUAGE :CXX >:-O3 -std =c ++17>
422433 $<$<COMPILE_LANGUAGE :CUDA >:${ATTN_QAT_INFER_CUDA_FLAGS} >
423434 )
424- # FP4 kernels target consumer/workstation Blackwell: sm_120a (RTX 5090 /
425- # PRO 6000) and sm_121a (DGX Spark GB10). sm_121a needs CUDA 13's ptxas
426- # (CUDA 12.x lacks it), so it is added only on CUDA >= 13.0 — older
427- # toolchains keep the original sm_120a-only build unchanged. sm_121a
428- # GB10-verified (cos ~0.98 vs bf16).
429- set (FASTVIDEO_FP4_CUDA_ARCHS "120a" )
430- if (NOT CUDAToolkit_VERSION VERSION_LESS 13.0)
431- list (APPEND FASTVIDEO_FP4_CUDA_ARCHS "121a" )
432- endif ()
435+ # Compile only the FP4 architectures requested by the caller. The large
436+ # template translation units use 8-12 GiB each, so an extra target matters.
433437 message (STATUS "fp4* CUDA architectures: ${FASTVIDEO_FP4_CUDA_ARCHS} " )
434438 set_target_properties (fp4attn_cuda PROPERTIES
435439 CUDA_ARCHITECTURES "${FASTVIDEO_FP4_CUDA_ARCHS} "
@@ -470,6 +474,6 @@ message(STATUS "host / backend: ${CMAKE_SYSTEM_PROCESSOR} / ${GPU_BACKEND}
470474message (STATUS "TORCH_CUDA_ARCH_LIST: ${TORCH_CUDA_ARCH_LIST} " )
471475message (STATUS "fastvideo_kernel_ops: ON (turbodiffusion int8-gemm/quant/rmsnorm/layernorm, all listed archs)" )
472476message (STATUS " + TK sta/block_sparse (sm_90a only): ${ENABLE_TK_KERNELS} " )
473- message (STATUS "fp4attn/fp4quant (sm_120a/sm_121a, CUDA >= 12.8): ${ENABLE_ATTN_QAT_INFER} " )
477+ message (STATUS "fp4attn/fp4quant (sm_120a CUDA >= 12.8; sm_121a CUDA >= 13 ): ${ENABLE_ATTN_QAT_INFER} " )
474478message (STATUS "Triton fallbacks ship in python/fastvideo_kernel/triton_kernels regardless." )
475479message (STATUS "============================================================" )
0 commit comments