mirror of
https://github.com/clearml/go-nvlib
synced 2025-01-31 02:47:02 +00:00
Cache mig profiles in devicelib, not just each device
Signed-off-by: Kevin Klues <kklues@nvidia.com>
This commit is contained in:
parent
13b333d4a6
commit
500a464b22
@ -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{}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user