mirror of
https://github.com/Dao-AILab/flash-attention.git
synced 2026-10-12 02:01:54 +00:00
Fix Windows builds with CUDA 13 and PyTorch 2.15 (#2872)
* Add opt-in SM121 and fix Windows CUDA 13 builds Add explicit SM121 code generation while keeping it out of the default release targets. Select forward-compatible PTX from architectures supported by the installed toolkit and reject unsupported-only requests. Enable the conforming MSVC preprocessor and math constants on Windows. For C++20 builds on Windows, pass /permissive to both cl and nvcc's host compiler. /std:c++20 implies /permissive-, and MSVC 2022 (<19.50) then rejects CuTe templates (C3545 in cute/stride.hpp) with CUDA 13.x. This relaxes conformance checking for host code in that configuration only. * Update comments on C++20 and nvcc flags Clarify comments regarding MSVC 2022 and CUDA 13.x compatibility.
This commit is contained in:
@@ -105,17 +105,22 @@ def add_cuda_gencodes(cc_flag, archs, bare_metal_version):
|
||||
Adds -gencode flags based on nvcc capabilities:
|
||||
- sm_80/90 (regular)
|
||||
- sm_100/120 on CUDA >= 12.8
|
||||
- Use 100f on CUDA >= 12.9 (Blackwell family-specific)
|
||||
- sm_121 on CUDA >= 12.9
|
||||
- Use family-specific virtual architectures on CUDA >= 12.9
|
||||
- Map requested 110 -> 101 if CUDA < 13.0 (Thor rename)
|
||||
- Embed PTX for newest arch for forward compatibility
|
||||
- Embed PTX for the newest supported arch for forward compatibility
|
||||
"""
|
||||
supported_archs = []
|
||||
|
||||
# Always-regular 80
|
||||
if "80" in archs:
|
||||
cc_flag += ["-gencode", "arch=compute_80,code=sm_80"]
|
||||
supported_archs.append("80")
|
||||
|
||||
# Hopper 9.0 needs >= 11.8
|
||||
if bare_metal_version >= Version("11.8") and "90" in archs:
|
||||
cc_flag += ["-gencode", "arch=compute_90,code=sm_90"]
|
||||
supported_archs.append("90")
|
||||
|
||||
# Blackwell 10.x requires >= 12.8
|
||||
if bare_metal_version >= Version("12.8"):
|
||||
@@ -125,6 +130,7 @@ def add_cuda_gencodes(cc_flag, archs, bare_metal_version):
|
||||
cc_flag += ["-gencode", "arch=compute_100f,code=sm_100"]
|
||||
else:
|
||||
cc_flag += ["-gencode", "arch=compute_100,code=sm_100"]
|
||||
supported_archs.append("100")
|
||||
|
||||
if "120" in archs:
|
||||
# sm_120 is supported in CUDA 12.8/12.9+ toolkits
|
||||
@@ -132,23 +138,33 @@ def add_cuda_gencodes(cc_flag, archs, bare_metal_version):
|
||||
cc_flag += ["-gencode", "arch=compute_120f,code=sm_120"]
|
||||
else:
|
||||
cc_flag += ["-gencode", "arch=compute_120,code=sm_120"]
|
||||
supported_archs.append("120")
|
||||
|
||||
if bare_metal_version >= Version("12.9") and "121" in archs:
|
||||
cc_flag += ["-gencode", "arch=compute_121f,code=sm_121"]
|
||||
supported_archs.append("121")
|
||||
|
||||
# Thor rename: 12.9 uses sm_101; 13.0+ uses sm_110
|
||||
if "110" in archs:
|
||||
if bare_metal_version >= Version("13.0"):
|
||||
cc_flag += ["-gencode", "arch=compute_110f,code=sm_110"]
|
||||
supported_archs.append("110")
|
||||
else:
|
||||
# Provide Thor support for CUDA 12.9 via sm_101
|
||||
if bare_metal_version >= Version("12.8"):
|
||||
cc_flag += ["-gencode", "arch=compute_101,code=sm_101"]
|
||||
supported_archs.append("101")
|
||||
# else: no Thor support in older toolkits
|
||||
|
||||
# PTX for newest requested arch (forward-compat)
|
||||
numeric = [a for a in archs if a.isdigit()]
|
||||
if numeric:
|
||||
newest = max(numeric, key=int)
|
||||
cc_flag += ["-gencode", f"arch=compute_{newest},code=compute_{newest}"]
|
||||
if not supported_archs:
|
||||
raise RuntimeError(
|
||||
f"None of the requested CUDA architectures {sorted(archs)} "
|
||||
f"are supported by CUDA {bare_metal_version}"
|
||||
)
|
||||
|
||||
# PTX for newest supported requested arch (forward-compat)
|
||||
newest = max(supported_archs, key=int)
|
||||
cc_flag += ["-gencode", f"arch=compute_{newest},code=compute_{newest}"]
|
||||
|
||||
return cc_flag
|
||||
|
||||
@@ -362,8 +378,24 @@ if not SKIP_CUDA_BUILD and not IS_ROCM:
|
||||
compiler_cxx_flag = ["-O3", f"-std={cxx_standard}"]
|
||||
# Add Windows-specific flags
|
||||
if sys.platform == "win32" and os.getenv('DISTUTILS_USE_SDK') == '1':
|
||||
nvcc_flags.extend(["-Xcompiler", "/Zc:__cplusplus"])
|
||||
compiler_cxx_flag = ["-O2", f"/std:{cxx_standard}", "/Zc:__cplusplus"]
|
||||
nvcc_flags.extend([
|
||||
"-Xcompiler", "/Zc:__cplusplus",
|
||||
"-Xcompiler", "/Zc:preprocessor",
|
||||
"-D_USE_MATH_DEFINES",
|
||||
])
|
||||
compiler_cxx_flag = [
|
||||
"-O2",
|
||||
f"/std:{cxx_standard}",
|
||||
"/Zc:__cplusplus",
|
||||
"/Zc:preprocessor",
|
||||
"/D_USE_MATH_DEFINES",
|
||||
]
|
||||
# /std:c++20 implies /permissive-. MSVC 2022 (<19.50) then rejects CuTe
|
||||
# templates (C3545 in cute/stride.hpp) with CUDA 13.x, so relax conformance
|
||||
# for nvcc's host compilation only. Do not add it to the cl flags: torch's
|
||||
# C++20 headers fail to compile under /permissive (C2666/C2139).
|
||||
if cxx_standard == "c++20":
|
||||
nvcc_flags += ["-Xcompiler", "/permissive"]
|
||||
|
||||
# Opt-in: disable building dropout and its dependent headers (ATen philox/RNG
|
||||
# headers) from the FA2 build. This flag must be shared across both cxx and nvcc
|
||||
|
||||
Reference in New Issue
Block a user