forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpu.go
More file actions
77 lines (70 loc) · 1.48 KB
/
gpu.go
File metadata and controls
77 lines (70 loc) · 1.48 KB
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
76
77
//
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
package ghw
import (
"fmt"
"strconv"
)
type GraphicsCard struct {
// the PCI address where the graphics card can be found
Address string
// The "index" of the card on the bus (generally not useful information,
// but might as well include it)
Index int
// pointer to a PCIDevice struct that describes the vendor and product
// model, etc
DeviceInfo *PCIDevice
// Array of topology nodes that the graphics card is affined to. Will be empty
// if the architecture is not NUMA.
Nodes []*TopologyNode
}
func (card *GraphicsCard) String() string {
deviceStr := card.Address
if card.DeviceInfo != nil {
deviceStr = card.DeviceInfo.String()
}
nodeStr := ""
if len(card.Nodes) > 0 {
x := 0
nodeStr = " NUMA nodes ["
for _, node := range card.Nodes {
if x > 0 {
nodeStr += ","
}
nodeStr += strconv.Itoa(int(node.Id))
x++
}
nodeStr += "] "
}
return fmt.Sprintf(
"card #%d %s@%s",
card.Index,
nodeStr,
deviceStr,
)
}
type GPUInfo struct {
GraphicsCards []*GraphicsCard
}
func GPU() (*GPUInfo, error) {
info := &GPUInfo{}
err := gpuFillInfo(info)
if err != nil {
return nil, err
}
return info, nil
}
func (i *GPUInfo) String() string {
numCardsStr := "cards"
if len(i.GraphicsCards) == 1 {
numCardsStr = "card"
}
return fmt.Sprintf(
"gpu (%d graphics %s)",
len(i.GraphicsCards),
numCardsStr,
)
}