-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_topology.go
75 lines (63 loc) · 1.37 KB
/
show_topology.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/furiosa-ai/furiosa-smi-go/pkg/smi"
"github.com/jedib0t/go-pretty/v6/table"
)
func main() {
if err := smi.Init(); err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
devices, err := smi.ListDevices()
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
header := table.Row{"#"}
for _, device := range devices {
info, err := device.DeviceInfo()
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
header = append(header, filepath.Base(info.Name()))
}
t.AppendHeader(header)
for _, device1 := range devices {
info1, err := device1.DeviceInfo()
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
row := table.Row{filepath.Base(info1.Name())}
for _, device2 := range devices {
linkType, err := device1.DeviceToDeviceLinkType(device2)
if err != nil {
fmt.Printf("%s\n", err.Error())
os.Exit(1)
}
row = append(row, linkTypeToString(linkType))
}
t.AppendRow(row)
}
t.Render()
}
func linkTypeToString(linkType smi.LinkType) string {
switch linkType {
case smi.LinkTypeInterconnect:
return "Interconnect"
case smi.LinkTypeCpu:
return "CPU"
case smi.LinkTypeHostBridge:
return "Host Bridge"
case smi.LinkTypeNoc:
return "NoC"
default:
return "Unknown"
}
}