@@ -39,7 +39,13 @@ const (
3939// MigMinor represents the minor number of a MIG device
4040type MigMinor int
4141
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
4349type MigCap string
4450
4551// MigCaps stores a map of MIG cap file paths to MIG minors
@@ -57,6 +63,31 @@ func NewComputeInstanceCap(gpu, gi, ci int) MigCap {
5763 return MigCap (fmt .Sprintf ("gpu%d/gi%d/ci%d/access" , gpu , gi , ci ))
5864}
5965
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+
6091// GetCapDevicePath returns the path to the cap device for the specified cap.
6192// An error is returned if the cap is invalid.
6293func (m MigCaps ) GetCapDevicePath (cap MigCap ) (string , error ) {
0 commit comments