Skip to content

Commit 166ea5c

Browse files
Copilotharp-intel
andcommitted
Add enhanced GPU details from lshw -class display
- Added new LshwGPUScriptName script for lshw -class display - Updated GPU struct with additional fields: LogicalName, BusInfo, Version, Width, Clock, Capabilities, Configuration, Resources - Modified gpuInfoFromOutput to parse detailed lshw output - Updated gpuTableValues to display all new GPU fields - Changed GPU table to use new lshw gpu script instead of generic lshw Co-authored-by: harp-intel <[email protected]>
1 parent 57cc1ce commit 166ea5c

File tree

3 files changed

+103
-26
lines changed

3 files changed

+103
-26
lines changed

internal/report/table_defs.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ var tableDefinitions = map[string]TableDefinition{
408408
HasRows: true,
409409
MenuLabel: DevicesMenuLabel,
410410
ScriptNames: []string{
411-
script.LshwScriptName,
411+
script.LshwGPUScriptName,
412412
},
413413
FieldsFunc: gpuTableValues},
414414
GaudiTableName: {
@@ -1781,11 +1781,27 @@ func gpuTableValues(outputs map[string]script.ScriptOutput) []Field {
17811781
{Name: "Manufacturer"},
17821782
{Name: "Model"},
17831783
{Name: "PCI ID"},
1784+
{Name: "Logical Name"},
1785+
{Name: "Bus Info"},
1786+
{Name: "Version"},
1787+
{Name: "Width"},
1788+
{Name: "Clock"},
1789+
{Name: "Capabilities"},
1790+
{Name: "Configuration"},
1791+
{Name: "Resources"},
17841792
}
17851793
for _, gpuInfo := range gpuInfos {
17861794
fields[0].Values = append(fields[0].Values, gpuInfo.Manufacturer)
17871795
fields[1].Values = append(fields[1].Values, gpuInfo.Model)
17881796
fields[2].Values = append(fields[2].Values, gpuInfo.PCIID)
1797+
fields[3].Values = append(fields[3].Values, gpuInfo.LogicalName)
1798+
fields[4].Values = append(fields[4].Values, gpuInfo.BusInfo)
1799+
fields[5].Values = append(fields[5].Values, gpuInfo.Version)
1800+
fields[6].Values = append(fields[6].Values, gpuInfo.Width)
1801+
fields[7].Values = append(fields[7].Values, gpuInfo.Clock)
1802+
fields[8].Values = append(fields[8].Values, gpuInfo.Capabilities)
1803+
fields[9].Values = append(fields[9].Values, gpuInfo.Configuration)
1804+
fields[10].Values = append(fields[10].Values, gpuInfo.Resources)
17891805
}
17901806
return fields
17911807
}

internal/report/table_helpers.go

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,40 +1476,94 @@ func filesystemFieldValuesFromOutput(outputs map[string]script.ScriptOutput) []F
14761476
}
14771477

14781478
type 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

14841492
func 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

internal/script/script_defs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const (
7070
IaaDevicesScriptName = "iaa devices"
7171
DsaDevicesScriptName = "dsa devices"
7272
LshwScriptName = "lshw"
73+
LshwGPUScriptName = "lshw gpu"
7374
UncoreMaxFromMSRScriptName = "uncore max from msr"
7475
UncoreMinFromMSRScriptName = "uncore min from msr"
7576
UncoreMaxFromTPMIScriptName = "uncore max from tpmi"
@@ -726,6 +727,12 @@ rdmsr 0x2FFE
726727
Depends: []string{"lshw"},
727728
Superuser: true,
728729
},
730+
LshwGPUScriptName: {
731+
Name: LshwGPUScriptName,
732+
ScriptTemplate: "timeout 30 lshw -class display",
733+
Depends: []string{"lshw"},
734+
Superuser: true,
735+
},
729736
MeminfoScriptName: {
730737
Name: MeminfoScriptName,
731738
ScriptTemplate: "cat /proc/meminfo",

0 commit comments

Comments
 (0)