-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnvlm_test.go
218 lines (185 loc) · 4.99 KB
/
nvlm_test.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package nvml
import (
"math"
"strconv"
"strings"
"testing"
"github.com/ahmyth/gonvlm/nvsmi"
)
func check(err error, t *testing.T) {
if err != nil {
t.Errorf("%v\n", err)
}
}
func TestDeviceCount(t *testing.T) {
Init()
defer Shutdown()
count, err := GetDeviceCount()
check(err, t)
query := "count"
c := nvsmi.DeviceCount(query)
if c != count {
t.Errorf("Device Count from nvml is wrong, got %d, want: %d", count, c)
}
}
func BenchmarkDeviceCount1(b *testing.B) {
Init()
b.StartTimer()
for n := 0; n < b.N; n++ {
GetDeviceCount()
}
b.StopTimer()
Shutdown()
}
func TestDriverVersion(t *testing.T) {
Init()
defer Shutdown()
driverVersion, err := GetDriverVersion()
check(err, t)
// assuming device count check to be passed before this test
id := "0"
query := "driver_version"
res := nvsmi.Query(id, query)
if strings.Compare(res, driverVersion) != 0 {
t.Errorf("Driver version from nvml is wrong, got: %v, want: %v", driverVersion, res)
}
}
func TestDeviceInfo(t *testing.T) {
Init()
defer Shutdown()
fields := []string{
"uuid",
"name",
"pci.bus_id",
"power.limit",
"clocks.max.sm",
"clocks.max.memory",
}
count, err := GetDeviceCount()
check(err, t)
for i := uint(0); i < count; i++ {
device, err := NewDevice(i)
check(err, t)
id := strconv.FormatUint(uint64(i), 10)
for _, val := range fields {
var msg, output string
res := nvsmi.Query(id, val)
switch val {
case "uuid":
msg = "Device UUID"
output = device.UUID
case "name":
msg = "Device model"
output = *device.Model
case "pci.bus_id":
msg = "Device bus id"
output = device.PCI.BusID
case "power.limit":
msg = "Device power limit"
output = strconv.FormatUint(uint64(*device.Power), 10)
power, err := strconv.ParseFloat(res, 64)
check(err, t)
res = strconv.FormatUint(uint64(math.Round(power)), 10)
case "clocks.max.sm":
msg = "Device max sm clocks"
output = strconv.FormatUint(uint64(*device.Clocks.Cores), 10)
case "clocks.max.memory":
msg = "Device max mem clocks"
output = strconv.FormatUint(uint64(*device.Clocks.Memory), 10)
}
if strings.Compare(res, output) != 0 {
t.Errorf("%v from nvml is wrong, got: %v, want: %v", msg, output, res)
}
}
}
}
func BenchmarkDeviceInfo1(b *testing.B) {
Init()
b.StartTimer()
for n := 0; n < b.N; n++ {
// assuming there will be atleast 1 GPU attached
NewDevice(uint(0))
}
b.StopTimer()
Shutdown()
}
func TestDeviceStatus(t *testing.T) {
Init()
defer Shutdown()
fields := []string{
"power.draw",
"temperature.gpu",
"utilization.gpu",
"utilization.memory",
"encoder.stats.averageFps",
"clocks.current.sm",
"clocks.current.memory",
"pstate",
"ecc.errors.uncorrected.volatile.device_memory",
"ecc.errors.uncorrected.volatile.l1_cache",
"ecc.errors.uncorrected.volatile.l2_cache",
}
count, err := GetDeviceCount()
check(err, t)
for i := uint(0); i < count; i++ {
device, err := NewDevice(i)
check(err, t)
status, err := device.Status()
check(err, t)
id := strconv.FormatUint(uint64(i), 10)
for _, val := range fields {
var msg, output string = "", "[Not Supported]"
res := nvsmi.Query(id, val)
switch val {
case "power.draw":
msg = "Device power utilization"
output = strconv.FormatUint(uint64(*status.Power), 10)
power, err := strconv.ParseFloat(res, 64)
check(err, t)
res = strconv.FormatUint(uint64(power), 10)
case "temperature.gpu":
msg = "Device temperature"
output = strconv.FormatUint(uint64(*status.Temperature), 10)
case "utilization.gpu":
msg = "Device gpu utilization"
output = strconv.FormatUint(uint64(*status.Utilization.GPU), 10)
case "utilization.memory":
msg = "Device memory utilization"
output = strconv.FormatUint(uint64(*status.Utilization.Memory), 10)
case "encoder.stats.averageFps":
msg = "Device encoder utilization"
output = strconv.FormatUint(uint64(*status.Utilization.Encoder), 10)
case "clocks.current.sm":
msg = "Device sm clock"
output = strconv.FormatUint(uint64(*status.Clocks.Cores), 10)
case "clocks.current.memory":
msg = "Device mem clock"
output = strconv.FormatUint(uint64(*status.Clocks.Memory), 10)
case "pstate":
msg = "Device performance state"
output = status.Performance.String()
case "ecc.errors.uncorrected.volatile.device_memory":
msg = "ecc error in device memory"
ecc := status.Memory.ECCErrors.Device
if ecc != nil {
output = strconv.FormatUint(*ecc, 10)
}
case "ecc.errors.uncorrected.volatile.l1_cache":
msg = "ecc error in l1 cache"
ecc := status.Memory.ECCErrors.L1Cache
if ecc != nil {
output = strconv.FormatUint(*ecc, 10)
}
case "ecc.errors.uncorrected.volatile.l2_cache":
msg = "ecc error in l2 cache"
ecc := status.Memory.ECCErrors.L2Cache
if ecc != nil {
output = strconv.FormatUint(*ecc, 10)
}
}
if strings.Compare(res, output) != 0 {
t.Errorf("%v from nvml is wrong, got: %v, want: %v", msg, output, res)
}
}
}
}