forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu.go
67 lines (60 loc) · 1.34 KB
/
gpu.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
//
// 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"
)
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
// Topology nodes that the graphics card is affined to. Will be nil if the
// architecture is not NUMA.
Node *TopologyNode
}
func (card *GraphicsCard) String() string {
deviceStr := card.Address
if card.DeviceInfo != nil {
deviceStr = card.DeviceInfo.String()
}
nodeStr := ""
if card.Node != nil {
nodeStr = fmt.Sprintf(" [affined to NUMA node %d]", card.Node.Id)
}
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,
)
}