mirror of
https://github.com/Heretek-AI/Strata.git
synced 2026-11-09 17:16:49 -10:00
- CMake: STRATA_ISA_FLOOR (empty by default) builds ggml-cpu for AVX (Sandy/Ivy Bridge) or SSE4.2
(Nehalem/Westmere) instead of the build host or AVX2; every other ggml ISA option off. Strata's own
AVX2/AVX-512 kernels stay in the binary behind their CPU checks. Excludes STRATA_PORTABLE. The ggml
block follows the Strata_Dirigo fork's (rwkeyes).
- STRATA_FORCE_ISA=avx2|avx|sse caps the engine's CPU probes, so the older-CPU paths run on any PC
(how this was tested here: no old CPU). cpu_sse42_ok(), isa_floor_build().
- The engine: a normal build still refuses a CPU without AVX2, now pointing at the experimental build;
a floor build checks its own floor (AVX, or SSE4.2 + POPCNT) and warns that it is experimental and
slow (or, on an AVX2 CPU, that the normal build is faster).
- setup: a CPU without AVX2 warns ("experimental, slow") and compiles the engine on the PC with the
floor it has, instead of failing (#595's idea); the prebuilt AVX2 engine is not used there. Recorded
in BUILD.json; a build folder for another floor is configured afresh. STRATA_ISA_FLOOR=avx|none asks
for it on any PC. Windows + AMD has no source build: a clear stop. The MCP server's recommendation
notes it instead of refusing.
- tools/test_setup_oldcpu.py.
Default build: nothing changes (no new CMake definitions, the probes answer as before without the env).
96 lines
4.0 KiB
Python
96 lines
4.0 KiB
Python
"""Tests for setup.py's experimental older-CPU build (#394 #595 #623): which floor a CPU without AVX2 gets, the CMake
|
|
definition, a build folder configured afresh when the floor changes, and the MCP server's note instead of a refusal.
|
|
No compiler, no GPU.
|
|
|
|
python -m unittest tools.test_setup_oldcpu
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
sys.path.insert(0, str(ROOT / "tools"))
|
|
import setup # noqa: E402
|
|
|
|
|
|
def cpuinfo(flags: str):
|
|
return mock.patch("builtins.open", lambda *a, **k: io.StringIO(f"model name\t: Old Xeon\nflags\t\t: {flags}\n"))
|
|
|
|
|
|
class FloorTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.env = mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": ""})
|
|
self.env.start()
|
|
|
|
def tearDown(self):
|
|
self.env.stop()
|
|
|
|
def test_avx2_cpu_gets_the_normal_engine(self):
|
|
self.assertEqual(setup.cpu_floor(True), "")
|
|
|
|
def test_linux_flags(self):
|
|
with mock.patch.object(setup, "WIN", False):
|
|
with cpuinfo("fpu sse4_1 sse4_2 popcnt avx xsave"):
|
|
self.assertEqual(setup.cpu_floor(False), "avx")
|
|
with cpuinfo("fpu sse4_1 sse4_2 popcnt"):
|
|
self.assertEqual(setup.cpu_floor(False), "none")
|
|
with cpuinfo("fpu sse3 ssse3"):
|
|
self.assertEqual(setup.cpu_floor(False), "unsupported")
|
|
|
|
def test_windows_probe(self):
|
|
with mock.patch.object(setup, "WIN", True):
|
|
for probe, want in (("avx", "avx"), ("sse4.2", "none"), ("", "unsupported")):
|
|
with mock.patch.object(setup, "_cpuid_floor", lambda p=probe: p):
|
|
self.assertEqual(setup.cpu_floor(False), want)
|
|
|
|
def test_env_asks_for_a_floor_build_on_any_cpu(self):
|
|
for v in ("avx", "none", "AVX"):
|
|
with mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": v}):
|
|
self.assertEqual(setup.cpu_floor(True), v.lower())
|
|
with mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": "bogus"}):
|
|
self.assertEqual(setup.cpu_floor(True), "")
|
|
|
|
@unittest.skipUnless(os.name == "nt", "the CPUID stub runs on Windows")
|
|
def test_this_pc_probe(self):
|
|
self.assertIn(setup._cpuid_floor(), ("avx", "sse4.2")) # any x86-64 PC that runs the tests
|
|
|
|
|
|
class DefsTest(unittest.TestCase):
|
|
def test_defs_and_fresh_configure(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
b = Path(d)
|
|
cache = b / "CMakeCache.txt"
|
|
self.assertEqual(setup.isa_floor_defs("", b, {}), []) # the normal build: nothing added
|
|
cache.write_text("x")
|
|
self.assertEqual(setup.isa_floor_defs("avx", b, {"isa_floor": "avx"}), ["-DSTRATA_ISA_FLOOR=avx"])
|
|
self.assertTrue(cache.exists()) # same floor: the folder is kept
|
|
self.assertEqual(setup.isa_floor_defs("none", b, {"isa_floor": "avx"}), ["-DSTRATA_ISA_FLOOR=none"])
|
|
self.assertFalse(cache.exists()) # another floor: configured afresh
|
|
cache.write_text("x")
|
|
self.assertEqual(setup.isa_floor_defs("", b, {"isa_floor": "none"}), [])
|
|
self.assertFalse(cache.exists()) # back to the normal build
|
|
cache.write_text("x")
|
|
setup.isa_floor_defs("", b, {})
|
|
self.assertTrue(cache.exists()) # the normal build's folder untouched
|
|
|
|
|
|
class McpTest(unittest.TestCase):
|
|
def test_no_avx2_is_a_note_not_a_refusal(self):
|
|
import strata_mcp as M
|
|
s = M.Strata(ROOT)
|
|
gpu = [{"index": 0, "name": "x", "vram_gb": 24.0, "usable": True, "vendor": "nvidia"}]
|
|
r = s.recommend({"ram_gb": 64, "gpus": gpu, "cpu": {"avx2": False}})
|
|
self.assertIsNotNone(r["model"])
|
|
self.assertTrue(any("no AVX2" in n and "EXPERIMENTAL" in n for n in r["notes"]))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|