setup: Visual Studio 2026 is accepted for the build with CUDA 13.3 or newer (#985)

find_vcvars looked for versions [16.0,18.0) only, because CUDA 13.0-13.2 refuse a newer Visual Studio. The range now goes up to 19.0 when the toolkit found is 13.3 or newer (the reporter built with VS 18 and CUDA 13.3); older toolkits stay on 2019 and 2022.
This commit is contained in:
Niko1221 committed 2026-10-06 15:57:39 +02:00
1 parent 0d73237632
commit 13c1fcb628
3 files changed
+28 -8

No files matched your search

+9 -6
View File
@@ -1228,13 +1228,16 @@ def find_nvcc(below=None):
return best
def find_vcvars():
def find_vcvars(cuda_v=None):
"""Visual Studio's vcvars64.bat. #985: CUDA 13.0-13.2 accept Visual Studio 2019 and 2022 only, so a newer one
(2026 = version 18) is taken only with CUDA 13.3 or newer (`cuda_v`, the toolkit's (major, minor))."""
vswhere = Path(os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)")) / "Microsoft Visual Studio/Installer/vswhere.exe"
if not vswhere.exists():
return None
# CUDA 13 accepts Visual Studio 2019 and 2022 only: a newer one (2026 = version 18) installed next to them
# must not be picked ("unsupported Microsoft Visual Studio version"); with only a newer one there is none
p = out([str(vswhere), "-latest", "-products", "*", "-version", "[16.0,18.0)", "-requires",
upper = "19.0" if cuda_v is not None and tuple(cuda_v) >= (13, 3) else "18.0"
p = out([str(vswhere), "-latest", "-products", "*", "-version", f"[16.0,{upper})", "-requires",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-property", "installationPath"]).strip()
v = Path(p) / "VC/Auxiliary/Build/vcvars64.bat" if p else None
return v if v and v.exists() else None
@@ -2652,7 +2655,7 @@ def install_build_tools(gpu, yes):
"and run it again (STRATA_NVCC=<its nvcc> picks one toolkit)")
# RTX 50 (sm_120): CUDA 13.0 - an engine built with 12.8 crashed in the prompt path on Linux (#220)
need_cuda = need12 if old else (13, 0) if max(archs) >= 120 else (12, 0)
vcvars = find_vcvars() if WIN else None
vcvars = find_vcvars(cuda_v) if WIN else None
have_cc = vcvars is not None if WIN else shutil.which("g++") is not None
missing = []
if not have_cc:
@@ -2679,7 +2682,7 @@ def install_build_tools(gpu, yes):
check=False)
if nvcc is None or cuda_v < need_cuda:
run([*wg, "--id", "Nvidia.CUDA", "--version", "13.0"], check=False)
vcvars = find_vcvars()
vcvars = find_vcvars(cuda_v)
else:
apt = shutil.which("apt-get")
if apt is None:
@@ -2701,12 +2704,12 @@ def install_build_tools(gpu, yes):
run(["sudo", "apt-get", "update"])
run(["sudo", "apt-get", "install", "-y", "cuda-toolkit-13-0"])
nvcc, cuda_v = find_nvcc(below=(13, 0)) if old else find_nvcc()
if (WIN and find_vcvars() is None) or (not WIN and shutil.which("g++") is None):
if (WIN and find_vcvars(cuda_v) is None) or (not WIN and shutil.which("g++") is None):
fail("the C++ build tools did not install", "install them by hand (README.md) and run it again")
if nvcc is None or cuda_v < need_cuda:
fail("the CUDA Toolkit did not install", "install it from https://developer.nvidia.com/cuda-downloads, then run it again")
ok(f"build tools installed (CUDA {cuda_v[0]}.{cuda_v[1]})")
return nvcc, find_vcvars() if WIN else None
return nvcc, find_vcvars(cuda_v) if WIN else None
def cmake_build(src, bdir, target, defs, vcvars, bat_name):
+18 -1
View File
@@ -184,6 +184,23 @@ class ReadOnlyGgufDir(unittest.TestCase):
self.assertFalse(setup.done(Path(tmp) / "x.gguf"))
class VsRange(unittest.TestCase):
"""#985: Visual Studio 2026 (version 18) is looked for only with CUDA 13.3 or newer."""
def asked(self, cuda_v):
seen = []
with mock.patch.object(setup.Path, "exists", lambda self: True), mock.patch.object(setup, "out", lambda cmd, *a, **k: seen.append(cmd) or "C:/VS"):
setup.find_vcvars(cuda_v)
return seen[0][seen[0].index("-version") + 1]
def test_the_range_follows_the_toolkit(self):
self.assertEqual(self.asked(None), "[16.0,18.0)")
self.assertEqual(self.asked((13, 0)), "[16.0,18.0)")
self.assertEqual(self.asked((13, 2)), "[16.0,18.0)")
self.assertEqual(self.asked((13, 3)), "[16.0,19.0)")
self.assertEqual(self.asked((14, 0)), "[16.0,19.0)")
class ExperimentalSm60(unittest.TestCase):
"""#295: Pascal (6.x) and Volta (7.0) only with STRATA_EXPERIMENTAL_SM60=1, built with -DSTRATA_EXPERIMENTAL_SM60=ON
and a CUDA 12.x toolkit; nothing changes without the variable."""
@@ -248,7 +265,7 @@ class ExperimentalSm60(unittest.TestCase):
seen.append(below)
return nvcc(below)
with mock.patch.object(setup, "find_nvcc", find), mock.patch.object(setup, "find_vcvars", lambda: "vcvars"), \
with mock.patch.object(setup, "find_nvcc", find), mock.patch.object(setup, "find_vcvars", lambda cuda_v=None: "vcvars"), \
mock.patch.object(setup.shutil, "which", lambda n: "/usr/bin/" + n):
got, _ = quiet(setup.install_build_tools, {"arch": str(archs[0]), "archs": archs}, True)
return got, seen
+1 -1
View File
@@ -135,7 +135,7 @@ class BuildTools(unittest.TestCase):
seen.append(below)
return nvcc(below)
with mock.patch.object(setup, "find_nvcc", find), mock.patch.object(setup, "find_vcvars", lambda: "vcvars"), \
with mock.patch.object(setup, "find_nvcc", find), mock.patch.object(setup, "find_vcvars", lambda cuda_v=None: "vcvars"), \
mock.patch.object(setup.shutil, "which", lambda n: "/usr/bin/" + n):
got, text = quiet(setup.install_build_tools, gpu, True)
return got, seen, text