Cache mig profiles in devicelib, not just each device

Signed-off-by: Kevin Klues <kklues@nvidia.com>
This commit is contained in:
Kevin Klues 2023-03-25 18:48:18 +00:00
parent 13b333d4a6
commit 500a464b22
2 changed files with 10 additions and 0 deletions

View File

@ -40,6 +40,7 @@ type devicelib struct {
nvml nvml.Interface nvml nvml.Interface
skippedDevices map[string]struct{} skippedDevices map[string]struct{}
verifySymbols *bool verifySymbols *bool
migProfiles []MigProfile
} }
var _ Interface = &devicelib{} var _ Interface = &devicelib{}

View File

@ -385,6 +385,12 @@ func (d *devicelib) GetMigDevices() ([]MigDevice, error) {
// GetMigProfiles gets the set of unique MIG profiles across all top-level devices // GetMigProfiles gets the set of unique MIG profiles across all top-level devices
func (d *devicelib) GetMigProfiles() ([]MigProfile, error) { func (d *devicelib) GetMigProfiles() ([]MigProfile, error) {
// Return the cached list if available
if d.migProfiles != nil {
return d.migProfiles, nil
}
// Otherwise generate it...
var profiles []MigProfile var profiles []MigProfile
err := d.VisitMigProfiles(func(p MigProfile) error { err := d.VisitMigProfiles(func(p MigProfile) error {
profiles = append(profiles, p) profiles = append(profiles, p)
@ -393,6 +399,9 @@ func (d *devicelib) GetMigProfiles() ([]MigProfile, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// And cache it before returning
d.migProfiles = profiles
return profiles, nil return profiles, nil
} }