okami.mom/strata

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

Niko1221setup.py on a DGX Spark: unified-memory GB10, its engine from the signed feed, the measured run-config settings552c56f7a

main
5.0 KiB95 linesraw
1"""setup.py on an ARM64 machine (DGX Spark / GB10, #3622): the GPU line, the CPU probe and the older-CPU floor.
2x86 machines must keep their old answers: a card whose memory nvidia-smi does not report stays unlisted there."""
3
4from __future__ import annotations
5
6import os
7import sys
8import unittest
9from pathlib import Path
10from unittest import mock
11
12ROOT = Path(__file__).resolve().parents[2]
13sys.path.insert(0, str(ROOT))
14
15import setup  # noqa: E402
16
17GB10 = "0, NVIDIA GB10, [N/A], 12.1, 580.95.05\n"
18MEMINFO = "MemTotal:       130000000 kB\nMemFree:         1000000 kB\n"
19ARM_CPUINFO = ("processor\t: 0\nBogoMIPS\t: 2000.00\nFeatures\t: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics\n"
20               "CPU implementer\t: 0x41\n")
21
22
23class UnifiedMemoryCard(unittest.TestCase):
24    def test_a_card_without_a_memory_figure_is_unlisted_on_x86_as_before(self):
25        with mock.patch.object(setup, "out", return_value=GB10), mock.patch.object(setup, "is_arm64", return_value=False):
26            self.assertEqual(setup.gpus(), [])
27
28    def test_gb10_is_a_unified_memory_gpu_with_the_ram_less_the_os_share(self):
29        with mock.patch.object(setup, "out", return_value=GB10), mock.patch.object(setup, "is_arm64", return_value=True), \
30                mock.patch.object(setup, "ram_gb", return_value=130000000 / 1024.0 / 1024.0):
31            found = setup.gpus()
32        self.assertEqual(len(found), 1)
33        self.assertEqual(found[0]["name"], "NVIDIA GB10")
34        self.assertEqual(found[0]["arch"], "121")
35        usable = 130000000 / 1024.0 / 1024.0 - setup.UMA_OS_LEFT_GB
36        self.assertAlmostEqual(found[0]["vram_gb"], usable, places=3)
37        self.assertTrue(found[0]["uma"])
38        self.assertEqual(found[0]["dedicated_gb"], 0.0)       # none of it is room beside the RAM: the low-RAM rules must not count it twice
39        self.assertAlmostEqual(found[0]["shared_gb"], usable, places=3)
40        self.assertEqual(setup.low_ram_vram(found[0]), 0.0)
41
42    def test_the_spark_settings_are_for_the_gb10_only(self):
43        gb10 = {"uma": True, "arch": "121", "name": "NVIDIA GB10"}
44        with mock.patch.object(setup, "is_arm64", return_value=True), mock.patch.object(setup.sys, "platform", "linux"):
45            self.assertTrue(setup.is_gb10(gb10))
46            self.assertFalse(setup.is_gb10({**gb10, "arch": "110"}))               # another unified-memory NVIDIA part: not measured
47            self.assertFalse(setup.is_gb10({"uma": False, "arch": "121"}))
48            self.assertFalse(setup.is_gb10({"arch": "121"}))
49        with mock.patch.object(setup, "is_arm64", return_value=False):
50            self.assertFalse(setup.is_gb10(gb10))
51        self.assertFalse(setup.is_gb10(None))
52
53    def test_a_normal_x86_card_is_never_a_gb10(self):
54        self.assertFalse(setup.is_gb10({"arch": "121", "vram_gb": 32.0, "name": "a discrete card"}))
55
56    def test_a_normal_card_is_unchanged(self):
57        with mock.patch.object(setup, "out", return_value="0, NVIDIA GeForce RTX 5070, 12227, 12.0, 580.1\n"):
58            found = setup.gpus()
59        self.assertAlmostEqual(found[0]["vram_gb"], 12227 / 1024.0, places=6)
60
61
62class ArmCpu(unittest.TestCase):
63    def test_an_arm_cpuinfo_without_the_x86_flags_line_does_not_crash(self):
64        with mock.patch.object(setup, "WIN", False), mock.patch("builtins.open", mock.mock_open(read_data=ARM_CPUINFO)):
65            name, avx2, avx512 = setup.cpu_info()
66        self.assertFalse(avx2)
67        self.assertFalse(avx512)
68
69    def test_an_arm_cpu_is_named_from_lscpu(self):
70        lscpu = "Architecture: aarch64\nModel name:          Cortex-X925\nModel name:          Cortex-A725\nModel name:          Cortex-X925\n"
71        with mock.patch.object(setup, "WIN", False), mock.patch("builtins.open", mock.mock_open(read_data=ARM_CPUINFO)), \
72                mock.patch.object(setup, "out", return_value=lscpu):
73            name, avx2, avx512 = setup.cpu_info()
74        self.assertEqual(name, "Cortex-X925 + Cortex-A725")
75        self.assertEqual((avx2, avx512), (False, False))
76
77    def test_an_x86_cpuinfo_is_read_as_before(self):
78        text = "flags\t\t: fpu avx avx2 avx512f avx512bw avx512vl avx512_vnni avx512vbmi\nmodel name\t: Test CPU\n"
79        with mock.patch.object(setup, "WIN", False), mock.patch("builtins.open", mock.mock_open(read_data=text)):
80            name, avx2, avx512 = setup.cpu_info()
81        self.assertEqual((name, avx2, avx512), ("Test CPU", True, True))
82
83    def test_no_older_cpu_floor_on_arm(self):
84        with mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": ""}), mock.patch.object(setup, "is_arm64", return_value=True):
85            self.assertEqual(setup.cpu_floor(False), "")
86
87    def test_the_floor_on_x86_without_avx2_is_still_asked_for(self):
88        with mock.patch.dict(os.environ, {"STRATA_ISA_FLOOR": ""}), mock.patch.object(setup, "is_arm64", return_value=False), \
89                mock.patch.object(setup, "WIN", False), \
90                mock.patch("builtins.open", mock.mock_open(read_data="flags\t: fpu sse4_2 popcnt avx\n")):
91            self.assertEqual(setup.cpu_floor(False), "avx")
92
93
94if __name__ == "__main__":
95    unittest.main()