okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
552c56f7a
main
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 ): 24def test_a_card_without_a_memory_figure_is_unlisted_on_x86_as_before (self ): 25with mock .patch .object (setup ,"out" ,return_value = GB10 ),mock .patch .object (setup ,"is_arm64" ,return_value = False ): 26self .assertEqual (setup .gpus (), []) 27 28def test_gb10_is_a_unified_memory_gpu_with_the_ram_less_the_os_share (self ): 29with mock .patch .object (setup ,"out" ,return_value = GB10 ),mock .patch .object (setup ,"is_arm64" ,return_value = True ), \ 30mock .patch .object (setup ,"ram_gb" ,return_value = 130000000 / 1024.0 / 1024.0 ): 31found = setup .gpus () 32self .assertEqual (len (found ),1 ) 33self .assertEqual (found [0 ]["name" ],"NVIDIA GB10" ) 34self .assertEqual (found [0 ]["arch" ],"121" ) 35usable = 130000000 / 1024.0 / 1024.0 - setup .UMA_OS_LEFT_GB 36self .assertAlmostEqual (found [0 ]["vram_gb" ],usable ,places = 3 ) 37self .assertTrue (found [0 ]["uma" ]) 38self .assertEqual (found [0 ]["dedicated_gb" ],0.0 )# none of it is room beside the RAM: the low-RAM rules must not count it twice 39self .assertAlmostEqual (found [0 ]["shared_gb" ],usable ,places = 3 ) 40self .assertEqual (setup .low_ram_vram (found [0 ]),0.0 ) 41 42def test_the_spark_settings_are_for_the_gb10_only (self ): 43gb10 = {"uma" :True ,"arch" :"121" ,"name" :"NVIDIA GB10" } 44with mock .patch .object (setup ,"is_arm64" ,return_value = True ),mock .patch .object (setup .sys ,"platform" ,"linux" ): 45self .assertTrue (setup .is_gb10 (gb10 )) 46self .assertFalse (setup .is_gb10 ({** gb10 ,"arch" :"110" }))# another unified-memory NVIDIA part: not measured 47self .assertFalse (setup .is_gb10 ({"uma" :False ,"arch" :"121" })) 48self .assertFalse (setup .is_gb10 ({"arch" :"121" })) 49with mock .patch .object (setup ,"is_arm64" ,return_value = False ): 50self .assertFalse (setup .is_gb10 (gb10 )) 51self .assertFalse (setup .is_gb10 (None )) 52 53def test_a_normal_x86_card_is_never_a_gb10 (self ): 54self .assertFalse (setup .is_gb10 ({"arch" :"121" ,"vram_gb" :32.0 ,"name" :"a discrete card" })) 55 56def test_a_normal_card_is_unchanged (self ): 57with mock .patch .object (setup ,"out" ,return_value = "0, NVIDIA GeForce RTX 5070, 12227, 12.0, 580.1\n" ): 58found = setup .gpus () 59self .assertAlmostEqual (found [0 ]["vram_gb" ],12227 / 1024.0 ,places = 6 ) 60 61 62class ArmCpu (unittest .TestCase ): 63def test_an_arm_cpuinfo_without_the_x86_flags_line_does_not_crash (self ): 64with mock .patch .object (setup ,"WIN" ,False ),mock .patch ("builtins.open" ,mock .mock_open (read_data = ARM_CPUINFO )): 65name ,avx2 ,avx512 = setup .cpu_info () 66self .assertFalse (avx2 ) 67self .assertFalse (avx512 ) 68 69def test_an_arm_cpu_is_named_from_lscpu (self ): 70lscpu = "Architecture: aarch64\nModel name: Cortex-X925\nModel name: Cortex-A725\nModel name: Cortex-X925\n" 71with mock .patch .object (setup ,"WIN" ,False ),mock .patch ("builtins.open" ,mock .mock_open (read_data = ARM_CPUINFO )), \ 72mock .patch .object (setup ,"out" ,return_value = lscpu ): 73name ,avx2 ,avx512 = setup .cpu_info () 74self .assertEqual (name ,"Cortex-X925 + Cortex-A725" ) 75self .assertEqual ((avx2 ,avx512 ), (False ,False )) 76 77def test_an_x86_cpuinfo_is_read_as_before (self ): 78text = "flags\t\t: fpu avx avx2 avx512f avx512bw avx512vl avx512_vnni avx512vbmi\nmodel name\t: Test CPU\n" 79with mock .patch .object (setup ,"WIN" ,False ),mock .patch ("builtins.open" ,mock .mock_open (read_data = text )): 80name ,avx2 ,avx512 = setup .cpu_info () 81self .assertEqual ((name ,avx2 ,avx512 ), ("Test CPU" ,True ,True )) 82 83def test_no_older_cpu_floor_on_arm (self ): 84with mock .patch .dict (os .environ , {"STRATA_ISA_FLOOR" :"" }),mock .patch .object (setup ,"is_arm64" ,return_value = True ): 85self .assertEqual (setup .cpu_floor (False ),"" ) 86 87def test_the_floor_on_x86_without_avx2_is_still_asked_for (self ): 88with mock .patch .dict (os .environ , {"STRATA_ISA_FLOOR" :"" }),mock .patch .object (setup ,"is_arm64" ,return_value = False ), \ 89mock .patch .object (setup ,"WIN" ,False ), \ 90mock .patch ("builtins.open" ,mock .mock_open (read_data = "flags\t: fpu sse4_2 popcnt avx\n" )): 91self .assertEqual (setup .cpu_floor (False ),"avx" ) 92 93 94if __name__ == "__main__" : 95unittest .main ()