-
Notifications
You must be signed in to change notification settings - Fork 3
/
fingerprint.go
58 lines (48 loc) · 1.42 KB
/
fingerprint.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
package device
import (
"context"
"fmt"
"github.com/hashicorp/nomad/plugins/device"
)
// doFingerprint is the long-running goroutine that detects device changes
func (d *NvidiaVgpuPlugin) doFingerprint(ctx context.Context, nvDevices <-chan *device.FingerprintResponse, virtDevices chan *device.FingerprintResponse) {
defer close(virtDevices)
for {
select {
case <-ctx.Done():
return
case nvDevice := <-nvDevices:
virtDevices <- d.nvDeviceToVirtDevices(ctx, nvDevice)
}
}
}
func (d *NvidiaVgpuPlugin) nvDeviceToVirtDevices(ctx context.Context, nvFpr *device.FingerprintResponse) *device.FingerprintResponse {
if nvFpr.Error != nil {
return nvFpr
}
d.deviceLock.Lock()
defer d.deviceLock.Unlock()
var devices []*device.DeviceGroup
for _, nvDeviceGroup := range nvFpr.Devices {
devGroup := &device.DeviceGroup{
Name: nvDeviceGroup.Name,
Attributes: nvDeviceGroup.Attributes,
Type: nvDeviceGroup.Type,
Vendor: vendor,
}
for _, nvDevice := range nvDeviceGroup.Devices {
for i := 0; i < d.vgpus; i++ {
dev := &device.Device{
ID: fmt.Sprintf("%s-%d", nvDevice.ID, i),
Healthy: nvDevice.Healthy,
HwLocality: nvDevice.HwLocality,
HealthDesc: nvDevice.HealthDesc,
}
d.devices[dev.ID] = struct{}{}
devGroup.Devices = append(devGroup.Devices, dev)
}
}
devices = append(devices, devGroup)
}
return device.NewFingerprint(devices...)
}