@@ -1476,40 +1476,94 @@ func filesystemFieldValuesFromOutput(outputs map[string]script.ScriptOutput) []F
14761476}
14771477
14781478type GPU struct {
1479- Manufacturer string
1480- Model string
1481- PCIID string
1479+ Manufacturer string
1480+ Model string
1481+ PCIID string
1482+ LogicalName string
1483+ BusInfo string
1484+ Version string
1485+ Width string
1486+ Clock string
1487+ Capabilities string
1488+ Configuration string
1489+ Resources string
14821490}
14831491
14841492func gpuInfoFromOutput (outputs map [string ]script.ScriptOutput ) []GPU {
14851493 gpus := []GPU {}
1486- gpusLshw := valsArrayFromRegexSubmatch (outputs [script .LshwScriptName ].Stdout , `^pci.*?\s+display\s+(\w+).*?\s+\[(\w+):(\w+)]$` )
1487- idxMfgName := 0
1488- idxMfgID := 1
1489- idxDevID := 2
1490- for _ , gpu := range gpusLshw {
1491- // Find GPU in GPU defs, note the model
1492- var model string
1493- for _ , intelGPU := range gpuDefinitions {
1494- if gpu [idxMfgID ] == intelGPU .MfgID {
1495- model = intelGPU .Model
1496- break
1497- }
1498- re := regexp .MustCompile (intelGPU .DevID )
1499- if re .FindString (gpu [idxDevID ]) != "" {
1500- model = intelGPU .Model
1501- break
1494+
1495+ // Parse the lshw -class display output
1496+ lshwGPUOutput := outputs [script .LshwGPUScriptName ].Stdout
1497+ if lshwGPUOutput == "" {
1498+ return gpus
1499+ }
1500+
1501+ // Parse each GPU device from the lshw output
1502+ // The output is in a format like:
1503+ // *-display
1504+ // description: VGA compatible controller
1505+ // product: ...
1506+ // vendor: ...
1507+ // ...
1508+
1509+ lines := strings .Split (lshwGPUOutput , "\n " )
1510+ var currentGPU * GPU
1511+
1512+ for _ , line := range lines {
1513+ trimmedLine := strings .TrimSpace (line )
1514+
1515+ // Start of a new GPU device
1516+ if strings .HasPrefix (trimmedLine , "*-" ) {
1517+ if currentGPU != nil {
1518+ gpus = append (gpus , * currentGPU )
15021519 }
1520+ currentGPU = & GPU {}
1521+ continue
15031522 }
1504- if model == "" {
1505- if gpu [idxMfgID ] == "8086" {
1506- model = "Unknown Intel"
1507- } else {
1508- model = "Unknown"
1523+
1524+ if currentGPU == nil {
1525+ continue
1526+ }
1527+
1528+ // Parse the fields
1529+ if strings .HasPrefix (trimmedLine , "product:" ) {
1530+ product := strings .TrimSpace (strings .TrimPrefix (trimmedLine , "product:" ))
1531+ // Try to find a matching model from GPU definitions
1532+ // Extract vendor and device IDs if present in bus info
1533+ currentGPU .Model = product
1534+ } else if strings .HasPrefix (trimmedLine , "vendor:" ) {
1535+ currentGPU .Manufacturer = strings .TrimSpace (strings .TrimPrefix (trimmedLine , "vendor:" ))
1536+ } else if strings .HasPrefix (trimmedLine , "bus info:" ) {
1537+ busInfo := strings .TrimSpace (strings .TrimPrefix (trimmedLine , "bus info:" ))
1538+ currentGPU .BusInfo = busInfo
1539+
1540+ // Extract PCI ID from bus info (e.g., pci@0000:00:02.0)
1541+ if strings .HasPrefix (busInfo , "pci@" ) {
1542+ pciAddr := strings .TrimPrefix (busInfo , "pci@" )
1543+ currentGPU .PCIID = pciAddr
15091544 }
1545+ } else if strings .HasPrefix (trimmedLine , "logical name:" ) {
1546+ currentGPU .LogicalName = strings .TrimSpace (strings .TrimPrefix (trimmedLine , "logical name:" ))
1547+ } else if strings .HasPrefix (trimmedLine , "version:" ) {
1548+ currentGPU .Version = strings .TrimSpace (strings .TrimPrefix (trimmedLine , "version:" ))
1549+ } else if strings .HasPrefix (trimmedLine , "width:" ) {
1550+ currentGPU .Width = strings .TrimSpace (strings .TrimPrefix (trimmedLine , "width:" ))
1551+ } else if strings .HasPrefix (trimmedLine , "clock:" ) {
1552+ currentGPU .Clock = strings .TrimSpace (strings .TrimPrefix (trimmedLine , "clock:" ))
1553+ } else if strings .HasPrefix (trimmedLine , "capabilities:" ) {
1554+ currentGPU .Capabilities = strings .TrimSpace (strings .TrimPrefix (trimmedLine , "capabilities:" ))
1555+ } else if strings .HasPrefix (trimmedLine , "configuration:" ) {
1556+ currentGPU .Configuration = strings .TrimSpace (strings .TrimPrefix (trimmedLine , "configuration:" ))
1557+ } else if strings .HasPrefix (trimmedLine , "resources:" ) {
1558+ currentGPU .Resources = strings .TrimSpace (strings .TrimPrefix (trimmedLine , "resources:" ))
15101559 }
1511- gpus = append (gpus , GPU {Manufacturer : gpu [idxMfgName ], Model : model , PCIID : gpu [idxMfgID ] + ":" + gpu [idxDevID ]})
15121560 }
1561+
1562+ // Don't forget the last GPU
1563+ if currentGPU != nil {
1564+ gpus = append (gpus , * currentGPU )
1565+ }
1566+
15131567 return gpus
15141568}
15151569
0 commit comments