Files
strata/tests/terminal/test_setup_arm64.py
T
ferstar a4c41a92ee Build the engine for ARM64 (DGX Spark / GB10) without changing the x86 build (#3622)
The engine did not build on aarch64: the CPU expert path assumed the x86 AVX
kernels, the CPUID probes and the x86 spin/fence intrinsics. After this change
the strata target compiles on aarch64 (CUDA host code, native GGUF packs).
On x86 nothing is selected differently.

What changed:
- CMake: STRATA_CPU_X86 is decided from CMAKE_SYSTEM_PROCESSOR (an unset
  processor stays the x86 build). On aarch64 src/kernels/cpu/portable.cpp
  stands in for the AVX kernel sources; native experts run on ggml-cpu's NEON
  dot products. -ffp-contract=off on aarch64. STRATA_ISA_FLOOR is ignored with
  a warning there.
- include/strata/platform/cpu_relax.hpp: strata_cpu_pause / strata_store_fence
  map to _mm_pause / _mm_sfence on x86 and to yield / dmb oshst on aarch64.
  verify.cpp, pool.cpp, session.cpp, mtp.cpp and graph.cpp use them.
- expert_layout.cpp: the CPUID/XCR0 probes compile on x86 only and report no
  AVX on other CPUs.
- generate.cpp: --cpu-oracle-q8-0 is rejected on a non-x86 CPU.
- setup.py: nvidia-smi's "[N/A]" memory on GB10 (unified memory) takes the
  pool size from /proc/meminfo on ARM64 only; the CPU probe no longer needs
  the x86 "flags" line; setup warns that the ARM64 engine is compiled on the
  PC and which packs work.

Changes to the contributor's patch, found while moving it onto the 0.2.7 line:
- portable.cpp had no iq512x_rows / iq512x_supported / iq512_gather_on (added
  to the x86 kernels after the PR was written): the aarch64 link would fail.
- The Metal build (Apple silicon) shares these files. It keeps its barrier
  (dmb ishst), its plain router loop (its bf16_rows_dot_multi is a stub), its
  Metal start-up block in generate.cpp and its "unknown" CPU name.
- The CPU side of the GPU doorbell: strata_load_fence() after the spins that
  wait for a flag the GPU raised (dmb ishld on ARM, nothing on x86 and on
  Apple silicon), so the data written before the flag is not read early.
- A card whose memory nvidia-smi does not report stays unlisted on x86 (the
  new fallback is for ARM64 only).
- tests/terminal/test_setup_arm64.py.

Checked: with the x86 CUDA build (sm_86, gcc 13 -O3, z440) the objects of
verify, session, mtp, graph, expert_source, pool, expert_layout and generate
are byte-identical before and after (the x86 wrappers are macros for the same
intrinsics). Every C++ file of the strata target compiles for aarch64 with
clang, and the symbols of the CPU kernel library link up (syntax and symbols
only: no ARM machine, no ARM run). The Metal-shared files compile for
aarch64-macos with STRATA_GPU_METAL.

Not covered: no ARM hardware here. The tests that include x86 headers
(iq_avx2_parity and the other AVX parity tools) and the DeepSeek target do
not build on aarch64; the strata target does not need them. Memory ordering
on ARM is reasoned, not run. The Q2_0 and Gyro packs need the x86 kernels.
2026-10-27 01:11:53 +01:00

69 lines
3.2 KiB
Python

"""setup.py on an ARM64 machine (DGX Spark / GB10, #3622): the GPU line, the CPU probe and the older-CPU floor.
x86 machines must keep their old answers: a card whose memory nvidia-smi does not report stays unlisted there."""
from __future__ import annotations
import os
import sys
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT))
import setup # noqa: E402
GB10 = "0, NVIDIA GB10, [N/A], 12.1, 580.95.05\n"
MEMINFO = "MemTotal: 130000000 kB\nMemFree: 1000000 kB\n"
ARM_CPUINFO = ("processor\t: 0\nBogoMIPS\t: 2000.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics\n"
"CPU implementer\t: 0x41\n")
class UnifiedMemoryCard(unittest.TestCase):
def test_a_card_without_a_memory_figure_is_unlisted_on_x86_as_before(self):
with mock.patch.object(setup, "out", return_value=GB10), mock.patch.object(setup, "is_arm64", return_value=False):
self.assertEqual(setup.gpus(), [])
def test_gb10_takes_the_pool_size_from_the_machine_ram(self):
with mock.patch.object(setup, "out", return_value=GB10), mock.patch.object(setup, "is_arm64", return_value=True), \
mock.patch("builtins.open", mock.mock_open(read_data=MEMINFO)):
found = setup.gpus()
self.assertEqual(len(found), 1)
self.assertEqual(found[0]["name"], "NVIDIA GB10")
self.assertEqual(found[0]["arch"], "121")
self.assertAlmostEqual(found[0]["vram_gb"], 130000000 / 1024.0 / 1024.0, places=3)
def test_a_normal_card_is_unchanged(self):
with mock.patch.object(setup, "out", return_value="0, NVIDIA GeForce RTX 5070, 12227, 12.0, 580.1\n"):
found = setup.gpus()
self.assertAlmostEqual(found[0]["vram_gb"], 12227 / 1024.0, places=6)
class ArmCpu(unittest.TestCase):
def test_an_arm_cpuinfo_without_the_x86_flags_line_does_not_crash(self):
with mock.patch.object(setup, "WIN", False), mock.patch("builtins.open", mock.mock_open(read_data=ARM_CPUINFO)):
name, avx2, avx512 = setup.cpu_info()
self.assertFalse(avx2)
self.assertFalse(avx512)
def test_an_x86_cpuinfo_is_read_as_before(self):
text = "flags\t\t: fpu avx avx2 avx512f avx512bw avx512vl avx512_vnni avx512vbmi\nmodel name\t: Test CPU\n"
with mock.patch.object(setup, "WIN", False), mock.patch("builtins.open", mock.mock_open(read_data=text)):
name, avx2, avx512 = setup.cpu_info()
self.assertEqual((name, avx2, avx512), ("Test CPU", True, True))
def test_no_older_cpu_floor_on_arm(self):
with mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": ""}), mock.patch.object(setup, "is_arm64", return_value=True):
self.assertEqual(setup.cpu_floor(False), "")
def test_the_floor_on_x86_without_avx2_is_still_asked_for(self):
with mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": ""}), mock.patch.object(setup, "is_arm64", return_value=False), \
mock.patch.object(setup, "WIN", False), \
mock.patch("builtins.open", mock.mock_open(read_data="flags\t: fpu sse4_2 popcnt avx\n")):
self.assertEqual(setup.cpu_floor(False), "avx")
if __name__ == "__main__":
unittest.main()