From 3cd33d504c57d0ac5f931170b8102403fb90f5d2 Mon Sep 17 00:00:00 2001 From: pschaub <11846736+pschaub@users.noreply.github.com> Date: Mon, 26 Oct 2026 18:31:37 +0100 Subject: [PATCH] cmake: a CUDA build with no architecture option is for sm_120, and `native` builds the W4A4 unit for sm_120a (#4029, #4023) CMakeLists.txt tested "NOT DEFINED CMAKE_CUDA_ARCHITECTURES" after enable_language(CUDA). Since CMake 3.18 that call fills an unset variable with nvcc's default (sm_75 for CUDA 13), so the sm_120 default never applied: a hand build with no option was an sm_75 build. The default is now set before enable_language, unless the user gave -DCMAKE_CUDA_ARCHITECTURES or the CUDAARCHS environment variable, and the configure step prints a warning that says what to pass for another card (a recommendation, not a refusal). With -DCMAKE_CUDA_ARCHITECTURES=native, the one NVFP4 W4A4 unit (mmq_nvfp4_w4a4.cu) stayed on plain `native`, where ptxas refuses the FP4 MMA on an RTX 50. `native` is now replaced by CMAKE_CUDA_ARCHITECTURES_NATIVE (the detected architectures) before the 12x -> 12xa rewrite, as a list, so a mixed PC works too. docs/SOURCE_INSTALL.md says what `native` and the other values build. Release and setup builds pass their architectures explicitly and are unchanged. Configure matrix, CUDA 12.9 on Linux: none -> 120 (+ the warning), CUDAARCHS=86 -> 86, 89, "75;86;120" (w4a4 120a only for the 12x entry), native -> detected. Ported from PR #4029. --- CMakeLists.txt | 21 +++++++++++++++++++-- docs/SOURCE_INSTALL.md | 3 +++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d83fad8..1cf372d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,13 +174,24 @@ elseif(STRATA_ENABLE_CUDA) if(MSVC AND STRATA_EXPERIMENTAL_SM60 AND NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY) set(CMAKE_CUDA_RUNTIME_LIBRARY Shared) endif() + # #4023: the default below has to be set BEFORE enable_language(CUDA): since CMake 3.18 that call fills an unset + # CMAKE_CUDA_ARCHITECTURES with nvcc's own default (sm_75 for CUDA 13), so a test after it never saw "undefined" and + # a build with no option was an sm_75 build. -DCMAKE_CUDA_ARCHITECTURES and the CUDAARCHS environment variable win. + set(_strata_cuda_arch_defaulted OFF) + if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES AND NOT DEFINED ENV{CUDAARCHS}) + set(CMAKE_CUDA_ARCHITECTURES 120 CACHE STRING "CUDA architectures") + set(_strata_cuda_arch_defaulted ON) + endif() enable_language(CUDA) # `enable_language(CUDA)` gives the .cu compile rules but NOT the imported targets, so `CUDA::cudart` has to # be brought in explicitly for the host-side tests that call cudaMalloc themselves. find_package(CUDAToolkit REQUIRED) option(STRATA_EXPERIMENTAL_SM60 "community build for GPUs below compute capability 7.5: Pascal sm_60, Volta sm_70 (#236)" OFF) - if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) - set(CMAKE_CUDA_ARCHITECTURES 120 CACHE STRING "CUDA architectures" FORCE) + if(_strata_cuda_arch_defaulted) + # a recommendation, not a refusal: the release engine is built for 75;86;89;120, a hand build names its card + message(WARNING "Strata: CMAKE_CUDA_ARCHITECTURES was not set, so this build is for sm_120 (RTX 50) only. For another " + "card pass it: -DCMAKE_CUDA_ARCHITECTURES=native (the GPUs in this PC), 75 (RTX 20), 86 (RTX 30), " + "89 (RTX 40), or a list like \"86;120\".") endif() foreach(_a IN LISTS CMAKE_CUDA_ARCHITECTURES) string(REGEX REPLACE "-.*$" "" _base "${_a}") # 120-real / 120-virtual are still 120 @@ -1916,6 +1927,12 @@ if(STRATA_NATIVE_EXPERTS) # which exists only in the arch-specific target, so its one unit alone is built with 12x -> 12xa (the default # binary is unchanged and runs on sm_121; a card without that image falls back to W4A8 at run time) set(_strata_w4a4_archs ${CMAKE_CUDA_ARCHITECTURES}) + # `native` is first replaced by the detected architectures (e.g. 120-real), so the 12x -> 12xa rewrite below applies + # to it too: with plain sm_120 ptxas refuses the FP4 MMA of this one unit (#4023) + if("native" IN_LIST _strata_w4a4_archs AND CMAKE_CUDA_ARCHITECTURES_NATIVE) + list(REMOVE_ITEM _strata_w4a4_archs native) + list(APPEND _strata_w4a4_archs ${CMAKE_CUDA_ARCHITECTURES_NATIVE}) + endif() # (two steps: CMake before 3.29 rejects a \2 whose optional group did not match, "120" alone) list(TRANSFORM _strata_w4a4_archs REPLACE "^(12[0-9])$" "\\1a") list(TRANSFORM _strata_w4a4_archs REPLACE "^(12[0-9])-(real|virtual)$" "\\1a-\\2") diff --git a/docs/SOURCE_INSTALL.md b/docs/SOURCE_INSTALL.md index 1c0d7ec0..a4996c57 100644 --- a/docs/SOURCE_INSTALL.md +++ b/docs/SOURCE_INSTALL.md @@ -71,6 +71,9 @@ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DCMAKE_C cmake --build build --target strata -j8 ``` +`native` builds for the GPUs in this PC. Name the card instead for another one: `75` (RTX 20), `86` (RTX 30), `89` (RTX 40), +`120` (RTX 50), or a list such as `"86;120"`. Without the option the build is for RTX 50 only and the configure step says so. + Run against the resulting binary and the matching model config. Use the build instructions for [HIP](AMD_HIP.md), [SYCL](INTEL_ARC.md) or [Metal](MAC.md) when changing those backends. Follow [contribution validation requirements](../CONTRIBUTING.md) before requesting review.