@@ -36,8 +36,12 @@ const (
36
36
nvcapsDevicePath = "/dev/nvidia-caps"
37
37
)
38
38
39
+ // An Index represents a gpu, ci, or gi index.
40
+ // We use uint32 as this typically maps to a device minor number.
41
+ type Index uint32
42
+
39
43
// MigMinor represents the minor number of a MIG device
40
- type MigMinor uint32
44
+ type MigMinor Index
41
45
42
46
// MigCap represents the path to a MIG cap file.
43
47
// These are listed in /proc/driver/nvidia-caps/mig-minors and have one of the
@@ -53,30 +57,30 @@ type MigCaps map[MigCap]MigMinor
53
57
54
58
// NewGPUInstanceCap creates a MigCap for the specified MIG GPU instance.
55
59
// A GPU instance is uniquely defined by the GPU minor number and GI instance ID.
56
- func NewGPUInstanceCap (gpu , gi int ) MigCap {
60
+ func NewGPUInstanceCap [ T uint32 | int | Index ] (gpu , gi T ) MigCap {
57
61
return MigCap (fmt .Sprintf ("gpu%d/gi%d/access" , gpu , gi ))
58
62
}
59
63
60
64
// NewComputeInstanceCap creates a MigCap for the specified MIG Compute instance.
61
65
// A GPU instance is uniquely defined by the GPU minor number, GI instance ID, and CI instance ID.
62
- func NewComputeInstanceCap (gpu , gi , ci int ) MigCap {
66
+ func NewComputeInstanceCap [ T uint32 | int | Index ] (gpu , gi , ci T ) MigCap {
63
67
return MigCap (fmt .Sprintf ("gpu%d/gi%d/ci%d/access" , gpu , gi , ci ))
64
68
}
65
69
66
70
// FilterForGPU limits the MIG Caps to those associated with a particular GPU.
67
- func (m MigCaps ) FilterForGPU (gpu int ) MigCaps {
71
+ func (m MigCaps ) FilterForGPU (gpu Index ) MigCaps {
68
72
if m == nil {
69
73
return nil
70
74
}
71
75
filtered := make (MigCaps )
72
- for gi := 0 ; ; gi ++ {
76
+ for gi := Index ( 0 ) ; ; gi ++ {
73
77
giCap := NewGPUInstanceCap (gpu , gi )
74
78
giMinor , exist := m [giCap ]
75
79
if ! exist {
76
80
break
77
81
}
78
82
filtered [giCap ] = giMinor
79
- for ci := 0 ; ; ci ++ {
83
+ for ci := Index ( 0 ) ; ; ci ++ {
80
84
ciCap := NewComputeInstanceCap (gpu , gi , ci )
81
85
ciMinor , exist := m [ciCap ]
82
86
if ! exist {
0 commit comments