Check if device is MIG Capable when visiting MIG devices

This change updates Device.VisitMigDevices to align with
Device.VisitMigProfiles in than the function is skipped for
non-MIG-capable devices. This allows the function to always
be a no-op on older drivers where MIG is not supported.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-05-22 13:24:11 +02:00
parent 18ad7cd513
commit 62eb401f91

View File

@ -188,6 +188,14 @@ func (d *device) IsMigEnabled() (bool, error) {
// VisitMigDevices walks a top-level device and invokes a callback function for each MIG device configured on it // VisitMigDevices walks a top-level device and invokes a callback function for each MIG device configured on it
func (d *device) VisitMigDevices(visit func(int, MigDevice) error) error { func (d *device) VisitMigDevices(visit func(int, MigDevice) error) error {
capable, err := d.IsMigCapable()
if err != nil {
return fmt.Errorf("error checking if GPU is MIG capable: %v", err)
}
if !capable {
return nil
}
count, ret := nvml.Device(d).GetMaxMigDeviceCount() count, ret := nvml.Device(d).GetMaxMigDeviceCount()
if ret != nvml.SUCCESS { if ret != nvml.SUCCESS {
return fmt.Errorf("error getting max MIG device count: %v", ret) return fmt.Errorf("error getting max MIG device count: %v", ret)