okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
53623e56f
main
1#!/usr/bin/env python3 2"""The PCIe path of every GPU, read from sysfs (no root needed). 3 4Walks from each display card up through its bridges to the root port and prints 5every hop's negotiated and maximum link speed and width. The card's own 6`current_link_*` attributes are printed too; on this PC they claim x16 Gen4 for 7both cards while the upstream ports of one of them are all 8.0 GT/s x4, so the 8bridge chain is the reading that agrees with the engine's own probe. 9 10Also prints the DRM slot, subsystem id and rocm-smi's view of each card. 11""" 12import os 13import subprocess 14import sys 15from pathlib import Path 16 17 18def r (path ,name ): 19try : 20return Path (path ,name ).read_text ().strip () 21except OSError : 22return '?' 23 24 25def main (): 26out = sys .stdout 27smi = subprocess .run (['rocm-smi' ,'--showbus' ,'--showid' ], 28capture_output = True ,text = True ).stdout 29for line in smi .splitlines (): 30if 'PCI Bus' in line or 'Subsystem' in line or 'Device ID' in line : 31line ,file = out ) 32for dev in sorted (Path ('/sys/bus/pci/devices' ).glob ('*' )): 33if not (dev / 'class' ).exists ()or r (dev ,'class' )!= '0x030000' : 34continue 35real = os .path .realpath (dev ) 36# which DRM card is this endpoint? 37card = '?' 38for c in sorted (Path ('/sys/class/drm' ).glob ('card[0-9]*' )): 39if c .name .count ('-' )== 0 and os .path .realpath (c / 'device' )== real : 40card = c .name 41f'\n=== { dev . name } drm { card } subsystem { r ( dev , "device" ) } ' ,file = out ) 42f' realpath { real } ' ,file = out ) 43p = real 44while p and p != '/sys/devices' and p != '/' : 45name = os .path .basename (p ) 46f' { name :15 } class= { r ( p , "class" ) } device= { r ( p , "device" ):<7 } ' 47f'current= { r ( p , "current_link_speed" ) } x { r ( p , "current_link_width" ) } ' 48f'max= { r ( p , "max_link_speed" ) } x { r ( p , "max_link_width" ) } ' ,file = out ) 49p = os .path .dirname (p ) 50 51 52if __name__ == '__main__' : 53main ()