okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
538acd098
main
1"""`bench.sh` (tools/strata_bench.py) has its own GPU probe, so the ROCm 7+ fix in strata_cli/bench_facts.py did not 2reach it: with no `rocm-smi` on the box it wrote the server's vendor stub as the card ("AMD Radeon", 3`...-community-unknown-...`) and `GPU driver: not read`. The strings below are the real answers of `amd-smi static 4--asic --json`, `static --driver --json` and `list --json` on one AI PRO R9700 (gfx1201) plus a Ryzen iGPU, with ROCm 510.1, trimmed to the fields the probe reads.""" 6from __future__import annotations 7 8import json 9import os 10import sys 11import tempfile 12import unittest 13from pathlib import Path 14from unittest import mock 15 16from tools import strata_bench as sb 17 18ASIC = {"gpu_data" : [{"gpu" :0 ,"asic" : {"market_name" :"AMD Radeon AI PRO R9700" ,"target_graphics_version" :"gfx1201" }}, 19 {"gpu" :1 ,"asic" : {"market_name" :"AMD Radeon Graphics" ,"target_graphics_version" :"gfx1036" }}]} 20DRIVER = {"gpu_data" : [{"gpu" :0 ,"driver" : {"name" :"amdgpu" ,"version" :"N/A" , 21"os_kernel_version" :"7.3.0-rc6-2-cachyos-rc" }}, 22 {"gpu" :1 ,"driver" : {"name" :"amdgpu" ,"version" :"6.16.4" }}]} 23LIST = [{"gpu" :0 ,"bdf" :"0000:03:00.0" ,"node_id" :1 }, {"gpu" :1 ,"bdf" :"0000:7c:00.0" ,"node_id" :2 }] 24BDF_TO_TOTAL = {"0000:03:00.0" :"34208743424" ,"0000:7c:00.0" :"805306368" } 25 26 27def run_cmd (cmd :list [str ],timeout :float = 15 )-> str : 28"""ROCm 10.1 answers, with `rocm-smi` missing entirely.""" 29if cmd [:1 ]== ["rocm-smi" ]or cmd [:1 ]== ["nvidia-smi" ]: 30return "" 31if cmd [:3 ]== ["amd-smi" ,"list" ,"--json" ]: 32return json .dumps (LIST ) 33if cmd [:2 ]== ["amd-smi" ,"static" ]: 34return json .dumps (DRIVER if "--driver" in cmd else ASIC ) 35return "" 36 37 38@ unittest . skipIf ( os . name == "nt" , "the probe is the non-Windows branch" ) 39class AmdSmiProbe (unittest .TestCase ): 40def setUp (self ): 41self .tmp = tempfile .TemporaryDirectory () 42self .addCleanup (self .tmp .cleanup ) 43# /sys/class/drm/cardN/device is a symlink whose target ends in the PCI address; the fake tree repeats the 44# shape, and the probe matches that address against `amd-smi list` 45root = Path (self .tmp .name ) 46drm = root / "drm" 47for card ,bdf in (("card1" ,"0000:03:00.0" ), ("card2" ,"0000:7c:00.0" )): 48real = root / "devices" / bdf 49real .mkdir (parents = True ) 50 (real / "mem_info_vram_total" ).write_text (BDF_TO_TOTAL [bdf ],encoding = "utf-8" ) 51drm .mkdir (parents = True ,exist_ok = True ) 52 (drm / card ).mkdir (exist_ok = True ) 53os .symlink (real ,drm / card / "device" ) 54self .drm = str (drm ) 55real_path = Path 56 57class DrmPath (real_path ): 58def __new__ (cls ,* a ,** kw ): 59return real_path (self .drm )if a == ("/sys/class/drm" ,)else real_path (* a ,** kw ) 60 61self .drm_patch = mock .patch .object (sb ,"Path" ,DrmPath ) 62self .drm_patch .start () 63self .addCleanup (self .drm_patch .stop ) 64self .cmd_patch = mock .patch .object (sb ,"run_cmd" ,run_cmd ) 65self .cmd_patch .start () 66self .addCleanup (self .cmd_patch .stop ) 67 68def test_the_probe_names_both_cards (self ): 69info = sb .gpu_info_local () 70self .assertEqual ([g ["name" ]for g in info ["gpus" ]], ["AMD Radeon AI PRO R9700" ,"AMD Radeon Graphics" ]) 71self .assertEqual ([g ["vram_mib" ]for g in info ["gpus" ]], [34208743424 >> 20 ,805306368 >> 20 ]) 72self .assertEqual ([g ["driver" ]for g in info ["gpus" ]], [None ,"6.16.4" ]) 73self .assertEqual (info .get ("rocm_driver" ),"6.16.4" ) 74 75def test_the_folder_names_the_card_it_used (self ): 76# the suite reports the card the engine runs on: the words gpu_slug drops are the vendor ones only 77self .assertEqual (sb .gpu_slug ({"gpu" : ["AMD Radeon AI PRO R9700" ]}),"ai-pro-r9700" ) 78 79def test_the_vendor_stub_does_not_replace_the_card (self ): 80metrics = {"hardware_static" : {"gpu_name" :"AMD Radeon" ,"cpu_name" :"AMD Ryzen 9 9950X3D" , 81"cores" :16 ,"threads" :32 },"engine" : {}} 82with mock .patch .object (sb ,"try_json" ,lambda base ,path ,key = "" ,timeout = 20 :metrics if path == "/metrics" else {}): 83m = sb .collect_machine ("http://127.0.0.1:1" ,"" ,None ) 84self .assertEqual (m ["gpu" ], ["AMD Radeon AI PRO R9700" ]) 85self .assertEqual (m ["gpu_vram_mib" ],34208743424 >> 20 ) 86self .assertEqual (m ["gpu_driver" ],None ) 87 88 89if __name__ == "__main__" : 90unittest .main ()