okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-mmq-default-off: build the engine without llama.cpp's MMQ kernels by default (-DSTRATA_MMQ=ON keeps the old path; linux-aarch64 unchanged)5649b9e52

main
4.9 KiB106 linesraw
1"""packaging/build_cuda_windows.py: the Windows NVIDIA engine package recipe (the release's configure line, the targets the build tree has).
2
3    python -m unittest tools.test_build_cuda_windows -v
4"""
5from __future__ import annotations
6
7import os
8import shutil
9import stat
10import subprocess
11import sys
12import tempfile
13import unittest
14from pathlib import Path
15
16ROOT = Path(__file__).resolve().parents[1]
17sys.path.insert(0, str(ROOT / "packaging"))
18import build_cuda_windows as B  # noqa: E402
19
20CUDA13 = Path("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0")
21CUDA12 = Path("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.9")
22
23
24class ConfigureLine(unittest.TestCase):
25    def test_cuda13_is_the_release_line(self):
26        # the 0.1.59 zips' line: 75;86;89;120 real + 120 PTX, portable, native experts, no tests (the K-quant and Q6_K options at their defaults)
27        got = B.configure_args(Path("S"), Path("Bd"), "cuda13", CUDA13, [])
28        self.assertEqual(got, ["-G", "Ninja", "-S", "S", "-B", "Bd", "-DCMAKE_BUILD_TYPE=Release", "-DSTRATA_ENABLE_CUDA=ON", "-DSTRATA_BUILD_TESTS=OFF",
29                               "-DSTRATA_NATIVE_EXPERTS=ON", "-DSTRATA_PORTABLE=ON", "-DSTRATA_MMQ=OFF",
30                               "-DCMAKE_CUDA_ARCHITECTURES=75-real;86-real;89-real;120-real;120-virtual",
31                               "-DCMAKE_CUDA_COMPILER=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/bin/nvcc.exe",
32                               "-DCUDAToolkit_ROOT=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0"])
33
34    def test_cuda12_is_the_pascal_and_volta_build(self):
35        got = B.configure_args(Path("S"), Path("Bd"), "cuda12", CUDA12, [])
36        self.assertIn("-DSTRATA_EXPERIMENTAL_SM60=ON", got)
37        self.assertIn("-DCMAKE_CUDA_ARCHITECTURES=60-real;61-real;70-real;75-real;80-real;86-real;89-real;89-virtual", got)
38        self.assertEqual(B.VARIANTS["cuda12"][2], "576.02")      # the 0.1.59 cuda12 zip's min_driver
39        self.assertEqual(B.VARIANTS["cuda13"][2], "580.65")
40
41    def test_extra_arguments_come_last_and_the_override_is_named(self):
42        got = B.configure_args(Path("S"), Path("Bd"), "cuda13", CUDA13, ["-DSTRATA_MMQ=ON"], ggml_dir="C:\\ref\\llama.cpp")
43        self.assertEqual(got[-2:], ["-DSTRATA_GGML_DIR=C:/ref/llama.cpp", "-DSTRATA_MMQ=ON"])
44        self.assertLess(got.index("-DSTRATA_MMQ=OFF"), got.index("-DSTRATA_MMQ=ON"))   # the A/B override wins (the last -D counts)
45
46    def test_an_arch_override_keeps_ptx_for_the_last(self):
47        self.assertEqual(B.parse_archs("120"), (120,))
48        self.assertEqual(B.parse_archs("86; 89,120"), (86, 89, 120))
49        got = B.configure_args(Path("S"), Path("Bd"), "cuda13", CUDA13, [], archs=(120,))
50        self.assertIn("-DCMAKE_CUDA_ARCHITECTURES=120-real;120-virtual", got)
51        for bad in ("", "sm_120", "120;x"):
52            with self.assertRaises(SystemExit):
53                B.parse_archs(bad)
54
55    def test_it_refuses_to_run_off_windows(self):
56        if os.name == "nt":
57            self.skipTest("Linux only")
58        with self.assertRaises(SystemExit):
59            B.main(["cuda13"])
60        self.assertEqual(B.main(["cuda11"]), 2)
61
62
63FAKE_CMAKE = """#!/bin/sh
64case "$FAKE_MODE" in
65  kq) exit 0 ;;
66  nokq) echo "ninja: error: unknown target 'strata_kq'" >&2; exit 1 ;;
67  *) echo "ninja: error: loading 'build.ninja': No such file or directory" >&2; exit 1 ;;
68esac
69"""
70
71
72@unittest.skipIf(os.name == "nt", "POSIX stand-in cmake")
73class Targets(unittest.TestCase):
74    def setUp(self):
75        self.tmp = Path(tempfile.mkdtemp())
76        self.cmake = self.tmp / "cmake"
77        self.cmake.write_text(FAKE_CMAKE, encoding="utf-8", newline="\n")
78        self.cmake.chmod(self.cmake.stat().st_mode | stat.S_IXUSR)
79
80    def tearDown(self):
81        shutil.rmtree(self.tmp, ignore_errors=True)
82
83    def call(self, mode):
84        return B.engine_targets(str(self.cmake), self.tmp, env=dict(os.environ, FAKE_MODE=mode))
85
86    def test_with_and_without_strata_kq(self):
87        self.assertEqual(self.call("kq"), ["strata", "strata_kq"])
88        self.assertEqual(self.call("nokq"), ["strata"])
89
90    def test_any_other_failure_stops(self):
91        with self.assertRaises(SystemExit):
92            self.call("broken")
93
94    @unittest.skipUnless(shutil.which("cmake") and shutil.which("ninja"), "cmake and ninja")
95    def test_real_ninja_trees(self):
96        for with_kq in (True, False):
97            src, build = self.tmp / ("s%d" % with_kq), self.tmp / ("b%d" % with_kq)
98            src.mkdir()
99            text = "cmake_minimum_required(VERSION 3.16)\nproject(t NONE)\nadd_custom_target(strata)\n" + ("add_custom_target(strata_kq)\n" if with_kq else "")
100            (src / "CMakeLists.txt").write_text(text, encoding="utf-8")
101            subprocess.run(["cmake", "-G", "Ninja", "-S", str(src), "-B", str(build)], check=True, capture_output=True, timeout=600)
102            self.assertEqual(B.engine_targets("cmake", build), ["strata", "strata_kq"] if with_kq else ["strata"])
103
104
105if __name__ == "__main__":
106    unittest.main()