@@ -39,7 +39,13 @@ const (
39
39
// MigMinor represents the minor number of a MIG device
40
40
type MigMinor int
41
41
42
- // MigCap represents the path to a MIG cap file
42
+ // MigCap represents the path to a MIG cap file.
43
+ // These are listed in /proc/driver/nvidia-caps/mig-minors and have one of the
44
+ // follown forms:
45
+ // - config
46
+ // - monitor
47
+ // - gpu{{ .gpuIndex }}/gi{{ .gi }}/access
48
+ // - gpu{{ .gpuIndex }}/gi{{ .gi }}/ci {{ .ci }}/access
43
49
type MigCap string
44
50
45
51
// MigCaps stores a map of MIG cap file paths to MIG minors
@@ -57,6 +63,31 @@ func NewComputeInstanceCap(gpu, gi, ci int) MigCap {
57
63
return MigCap (fmt .Sprintf ("gpu%d/gi%d/ci%d/access" , gpu , gi , ci ))
58
64
}
59
65
66
+ // FilterForGPU limits the MIG Caps to those associated with a particular GPU.
67
+ func (m MigCaps ) FilterForGPU (gpu int ) MigCaps {
68
+ if m == nil {
69
+ return nil
70
+ }
71
+ filtered := make (MigCaps )
72
+ for gi := 0 ; ; gi ++ {
73
+ giCap := NewGPUInstanceCap (gpu , gi )
74
+ giMinor , exist := m [giCap ]
75
+ if ! exist {
76
+ break
77
+ }
78
+ filtered [giCap ] = giMinor
79
+ for ci := 0 ; ; ci ++ {
80
+ ciCap := NewComputeInstanceCap (gpu , gi , ci )
81
+ ciMinor , exist := m [ciCap ]
82
+ if ! exist {
83
+ break
84
+ }
85
+ filtered [ciCap ] = ciMinor
86
+ }
87
+ }
88
+ return filtered
89
+ }
90
+
60
91
// GetCapDevicePath returns the path to the cap device for the specified cap.
61
92
// An error is returned if the cap is invalid.
62
93
func (m MigCaps ) GetCapDevicePath (cap MigCap ) (string , error ) {
0 commit comments