setup: pass CC/CXX/CUDAHOSTCXX to the CUDA build's cmake (#1645)

CUDA 12 refuses a GCC newer than 14, and the docs already tell the user
to run CXX=g++-14 ./setup.sh - but the environment only reaches CMake on
a build folder's FIRST configure, so on a retry (or the encoder's own
folder) the flag never landed: the reporter's run died at the last step.

host_compiler_defs() maps them onto -DCMAKE_C_COMPILER /
-DCMAKE_CXX_COMPILER / -DCMAKE_CUDA_HOST_COMPILER for the engine and the
CUDA image encoder; CUDAHOSTCXX defaults to CXX, as CMake's does.  A
C++-only build (the CPU encoder) is not given the CUDA one.
This commit is contained in:
nekomario28 authored and Niko1221 committed 2026-10-09 15:17:13 +02:00
1 parent c396dc9c39
commit 092fc3c5c6
3 files changed
+66 -3

No files matched your search

+2 -1
View File
@@ -52,7 +52,8 @@ Install what it names (links are printed), then run it again. Everything already
**Linux: the engine does not compile (`unsupported GNU version`, or `exception specification is incompatible` for
`cospi`/`sinpi`/`rsqrt`).** Two known mismatches between the CUDA toolkit and a new Linux (#601):
- gcc newer than 14 (Ubuntu 26.04's default 15): CUDA 12.x and 13.0 refuse it. Install g++-14 and run
`CXX=g++-14 CUDAHOSTCXX=g++-14 ./setup.sh`.
`CXX=g++-14 ./setup.sh` (CC, CXX and CUDAHOSTCXX name the build's compilers; setup passes them to CMake itself,
so an already-configured build folder picks them up too, #1645).
- glibc 2.43 with CUDA 12.9: the toolkit's math headers clash with glibc's, already in CMake's first test compile.
Use CUDA 12.8 or 13.x instead. Setup takes the newest toolkit it finds; `STRATA_NVCC=/usr/local/cuda-12.8/bin/nvcc
./setup.sh` makes it use that one (only that one).
+16 -2
View File
@@ -3298,6 +3298,20 @@ def isa_floor_defs(floor: str, bdir: Path, meta: dict) -> list:
return [f"-DSTRATA_ISA_FLOOR={floor}"] if floor else []
def host_compiler_defs(cuda: bool) -> list:
"""CC / CXX / CUDAHOSTCXX pick the host compilers of a build - as -D definitions, so an existing build folder
takes them too (the environment reaches CMake only on a folder's first configure, which is why CXX=g++-14 alone
could die at the last step, #1645). CUDAHOSTCXX is nvcc's host compiler (-ccbin); it defaults to CXX, as
CMake's does. `cuda`: the project compiles CUDA (the host-compiler definition means nothing to a C++-only
one)."""
cc = os.environ.get("CC", "").strip()
cxx = os.environ.get("CXX", "").strip()
hostcxx = os.environ.get("CUDAHOSTCXX", "").strip() or cxx
return ([f"-DCMAKE_C_COMPILER={cc}"] if cc else []) + \
([f"-DCMAKE_CXX_COMPILER={cxx}"] if cxx else []) + \
([f"-DCMAKE_CUDA_HOST_COMPILER={hostcxx}"] if cuda and hostcxx else [])
def toolkit_root_defs(nvcc) -> list:
"""CUDAToolkit_ROOT for the toolkit whose nvcc builds the engine. Without it CMake can take cudart and cuBLAS from
another toolkit: with STRATA_NVCC=/opt/cuda-13.0/bin/nvcc on Ubuntu 24.04 that also has the distribution's CUDA
@@ -3367,14 +3381,14 @@ def build_engine(gpu, vision, yes, llama, toolkit=None) -> Path:
cmake_build(ROOT, bdir, "strata",
["-DSTRATA_ENABLE_CUDA=ON", "-DSTRATA_BUILD_TESTS=OFF", f"-DCMAKE_CUDA_ARCHITECTURES={cuda_archs}",
f"-DCMAKE_CUDA_COMPILER={nvcc}", *toolkit_root_defs(nvcc), f"-DSTRATA_GGML_DIR={llama}",
*engine_defs(archs, toolkit),
*host_compiler_defs(True), *engine_defs(archs, toolkit),
*isa_floor_defs(floor, bdir, meta)],
vcvars, "build-strata-cuda12.bat" if t12 else "build-strata.bat")
shutil.copy2(bdir / EXE, eng / EXE)
if not vision_ok:
say(" Compiling the image encoder" + (" with CUDA (10-20 minutes, once) ..." if vision == "gpu" else " ..."))
defs = [f"-DLLAMA_DIR={llama}", f"-DSTRATA_VISION_CUDA={'ON' if vision == 'gpu' else 'OFF'}",
"-DSTRATA_PORTABLE=OFF"] # built here, for this PC: native, like the engine
"-DSTRATA_PORTABLE=OFF", *host_compiler_defs(vision == "gpu")] # native, like the engine
if vision == "gpu":
defs += [f"-DCMAKE_CUDA_ARCHITECTURES={cuda_archs}", f"-DCMAKE_CUDA_COMPILER={nvcc}",
*toolkit_root_defs(nvcc)]
+48
View File
@@ -553,5 +553,53 @@ class SwiftIq3s(unittest.TestCase):
"Swift-Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf"])
class HostCompilers(unittest.TestCase):
"""#1645: CC / CXX / CUDAHOSTCXX name the build's compilers - handed to CMake as -D, so a build folder that is
already configured picks them up too (CXX alone reaches CMake only on the first configure: the reporter's
`CXX=g++-14` run died at the last step). CUDAHOSTCXX is nvcc's host compiler and defaults to CXX."""
def test_env_names_the_compilers(self):
with mock.patch.dict(os.environ, {"CC": "gcc-14", "CXX": "g++-14", "CUDAHOSTCXX": "g++-14-alt"}):
self.assertEqual(setup.host_compiler_defs(True), ["-DCMAKE_C_COMPILER=gcc-14",
"-DCMAKE_CXX_COMPILER=g++-14",
"-DCMAKE_CUDA_HOST_COMPILER=g++-14-alt"])
def test_cudahostcxx_defaults_to_cxx_and_needs_cuda(self):
with mock.patch.dict(os.environ, {"CC": "", "CXX": "g++-14", "CUDAHOSTCXX": ""}):
self.assertEqual(setup.host_compiler_defs(True), ["-DCMAKE_CXX_COMPILER=g++-14",
"-DCMAKE_CUDA_HOST_COMPILER=g++-14"])
self.assertEqual(setup.host_compiler_defs(False), ["-DCMAKE_CXX_COMPILER=g++-14"]) # a C++-only project
def test_unset_adds_nothing(self):
with mock.patch.dict(os.environ, {"CC": "", "CXX": "", "CUDAHOSTCXX": ""}):
self.assertEqual(setup.host_compiler_defs(True), [])
def test_the_defs_reach_cmake(self):
"""The engine's and the CUDA encoder's configure both take them."""
with tempfile.TemporaryDirectory() as d:
root = Path(d)
eng = root / "engine"
eng.mkdir()
(eng / "BUILD.json").write_text(json.dumps({"source": "local", "archs": [86], "src": "old"}))
built = []
def cmake_build(src_dir, bdir, target, defs, vcvars, bat):
built.append((target, defs))
(bdir / "bin").mkdir(parents=True, exist_ok=True)
(bdir / "bin" / setup.VEXE).write_bytes(b"vision")
(bdir / setup.EXE).write_bytes(b"engine")
env = {"CC": "gcc-14", "CXX": "g++-14", "CUDAHOSTCXX": ""}
with mock.patch.dict(os.environ, env), mock.patch.object(setup, "ROOT", root), \
mock.patch.object(setup, "cmake_build", cmake_build), \
mock.patch.object(setup, "source_hash", lambda p: "V" if p == setup.VISION_SOURCES else "new"), \
mock.patch.object(setup, "install_build_tools", lambda gpu, yes: (str(root / "nvcc"), None)), \
mock.patch.object(setup, "source_version", lambda: "test"):
quiet(setup.build_engine, {"arch": "86"}, "gpu", True, "llama")
for target, defs in built:
self.assertIn("-DCMAKE_CXX_COMPILER=g++-14", defs, target)
self.assertIn("-DCMAKE_CUDA_HOST_COMPILER=g++-14", defs, target)
if __name__ == "__main__":
unittest.main()