okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
99866a47a
main
1"""A PC with only the amdgpu driver (no rocm-smi, no setup module) still counts every AMD card, from a fake sysfs. 2 3python -m unittest tools.test_kfd_gpus 4""" 5import sys 6import tempfile 7import unittest 8from pathlib import Path 9 10ROOT = Path (__file__ ).resolve ().parents [1 ] 11sys .path .insert (0 ,str (ROOT )) 12sys .path .insert (0 ,str (ROOT / "tools" )) 13import strata_mcp as M # noqa: E402 14 15 16def node (root :Path ,i :int ,ver :int ,simd :int ,minor :int ,vram :int = 0 ,name :str | None = None ): 17n = root / "class/kfd/kfd/topology/nodes" / str (i ) 18n .mkdir (parents = True ) 19 (n / "properties" ).write_text (f"cpu_cores_count { 0 if simd else 12 } \nsimd_count { simd } \ngfx_target_version { ver } \ndrm_render_minor { minor } \n" ) 20if simd : 21d = root / f"class/drm/renderD { minor } /device" 22d .mkdir (parents = True ) 23 (d / "mem_info_vram_total" ).write_text (str (vram )) 24if name : 25 (d / "product_name" ).write_text (name + "\n" ) 26 27 28class KfdGpus (unittest .TestCase ): 29def test_four_cards_and_the_cpu_node (self ): 30with tempfile .TemporaryDirectory ()as tmp : 31root = Path (tmp ) 32node (root ,0 ,0 ,0 ,0 ) 33for k in range (4 ): 34node (root ,k + 1 ,120001 ,128 ,128 + k ,32 << 30 ,"AMD Radeon AI PRO R9700" ) 35gpus = M .kfd_gpus (tmp ) 36self .assertEqual ([g ["index" ]for g in gpus ], [0 ,1 ,2 ,3 ]) 37self .assertTrue (all (g ["usable" ]and g ["arch" ]== "gfx1201" and g ["vram_gb" ]== 32.0 for g in gpus )) 38 39def test_an_unlisted_architecture_is_named_not_hidden (self ): 40with tempfile .TemporaryDirectory ()as tmp : 41node (Path (tmp ),0 ,90010 ,60 ,128 ,8 << 30 ) 42 (g ,)= M .kfd_gpus (tmp ) 43self .assertFalse (g ["usable" ]) 44self .assertIn ("gfx90a" ,g ["problem" ]) 45 46def test_no_amd_driver_is_an_empty_list (self ): 47with tempfile .TemporaryDirectory ()as tmp : 48self .assertEqual (M .kfd_gpus (tmp ), []) 49 50 51if __name__ == "__main__" : 52unittest .main ()