forked from rai-project/nvidia-smi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu_info.go
148 lines (133 loc) · 4.23 KB
/
gpu_info.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package nvidiasmi
import (
"strings"
"github.com/pkg/errors"
)
var (
archSMMapping = map[float64]int{
3.0: 192, // Kepler Generation (SM 3.0) GK10x class
3.2: 192, // Kepler Generation (SM 3.2) GK10x class
3.5: 192, // Kepler Generation (SM 3.5) GK11x class
3.7: 192, // Kepler Generation (SM 3.7) GK21x class
5.0: 128, // Maxwell Generation (SM 5.0) GM10x class
5.2: 128, // Maxwell Generation (SM 5.2) GM20x class
5.3: 128, // Maxwell Generation (SM 5.3) GM20x class
6.0: 64, // Pascal Generation (SM 6.0) GP100 class
6.1: 128, // Pascal Generation (SM 6.1) GP10x class
6.2: 128, // Pascal Generation (SM 6.2) GP10x class
7.0: 64, // Volta Generation (SM 7.0) GV100 class
7.2: 64, // Volta Generation (SM 7.2) GV11b class
7.5: 64, // Turing Generation (SM 7.5) TU1xx class
}
)
func (g GPU) NumCores() (int, error) {
sms, err := g.NumSMs()
if err != nil {
return 0, errors.Wrap(err, "unable to get num cores because cannot get num sms")
}
computeCapability, err := g.ComputeCapability()
if err != nil {
return 0, errors.Wrap(err, "unable to get num cores because cannot get compute capability")
}
cores, ok := archSMMapping[computeCapability]
if ok {
return cores * sms, nil
}
return 0, errors.Errorf("unable to find num of cores for compute capability %v", computeCapability)
}
func (g GPU) NumSMs() (int, error) {
name := strings.ToLower(g.ProductName)
for _, info := range NvidiaGPUs {
if strings.ToLower(info.Name) == name {
if info.NumSMs == 0 {
panic("expecting a non-zero num sms")
}
return info.NumSMs, nil
}
}
return 0, errors.Errorf("cannot find num of sms for %v", g.ProductName)
}
func (g GPU) Architecture() (string, error) {
name := strings.ToLower(g.ProductName)
for _, info := range NvidiaGPUs {
if strings.ToLower(info.Name) == name {
if info.Architecture == "" {
panic("expecting a non-zero architecture")
}
return info.Architecture, nil
}
}
return "", errors.Errorf("cannot find architecture name for %v", g.ProductName)
}
func (g GPU) ClockRate() (int64, error) {
name := strings.ToLower(g.ProductName)
for _, info := range NvidiaGPUs {
if strings.ToLower(info.Name) == name {
if info.ClockRate == 0 {
panic("expecting a non-zero clock rate")
}
return info.ClockRate, nil
}
}
return 0, errors.Errorf("cannot find clock rate for %v", g.ProductName)
}
func (g GPU) ComputeCapability() (float64, error) {
name := strings.ToLower(g.ProductName)
for _, info := range NvidiaGPUs {
if strings.ToLower(info.Name) == name {
if info.ComputeCapability == 0 {
panic("expecting a non-zero compute capability")
}
return info.ComputeCapability, nil
}
}
return 0, errors.Errorf("cannot find compute capability for %v", g.ProductName)
}
func (g GPU) TheoreticalGFlops() (int64, error) {
name := strings.ToLower(g.ProductName)
for _, info := range NvidiaGPUs {
if strings.ToLower(info.Name) == name {
if info.PeekGFlops == 0 {
panic("expecting a non-zero peek gflops")
}
return info.PeekGFlops, nil
}
}
return 0, errors.Errorf("cannot find theoretical peak gflops for %v", g.ProductName)
}
func (g GPU) MemoryBandwidth() (float64, error) {
name := strings.ToLower(g.ProductName)
for _, info := range NvidiaGPUs {
if strings.ToLower(info.Name) == name {
if info.MemoryBandwidth == 0 {
panic("expecting a non-zero memory bandwidth")
}
return info.MemoryBandwidth, nil
}
}
return 0, errors.Errorf("cannot find memory bandwidth for %v", g.ProductName)
}
func (g GPU) InterconnectName() (string, error) {
name := strings.ToLower(g.ProductName)
for _, info := range NvidiaGPUs {
if strings.ToLower(info.Name) == name {
if info.Interconnect.Name() == "" {
panic("expecting a non-zero name")
}
return info.Interconnect.Name(), nil
}
}
return "", errors.Errorf("cannot find interconnect name for %v", g.ProductName)
}
func (g GPU) InterconnectBandwidth() (float64, error) {
name := strings.ToLower(g.ProductName)
for _, info := range NvidiaGPUs {
if strings.ToLower(info.Name) == name {
if info.Interconnect.Bandwidth() == 0 {
panic("expecting a non-zero bandwidth")
}
return info.Interconnect.Bandwidth(), nil
}
}
return 0, errors.Errorf("cannot find interconnect bandwidth for %v", g.ProductName)
}