chore: memoize detected GPUs

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto 2025-05-17 22:10:10 +02:00
parent 6d5bde860b
commit 0c859addce

View file

@ -2,18 +2,29 @@ package xsysinfo
import ( import (
"strings" "strings"
"sync"
"github.com/jaypipes/ghw" "github.com/jaypipes/ghw"
"github.com/jaypipes/ghw/pkg/gpu" "github.com/jaypipes/ghw/pkg/gpu"
) )
func GPUs() ([]*gpu.GraphicsCard, error) { var (
gpu, err := ghw.GPU() gpuCache []*gpu.GraphicsCard
if err != nil { gpuCacheOnce sync.Once
return nil, err gpuCacheErr error
} )
return gpu.GraphicsCards, nil func GPUs() ([]*gpu.GraphicsCard, error) {
gpuCacheOnce.Do(func() {
gpu, err := ghw.GPU()
if err != nil {
gpuCacheErr = err
return
}
gpuCache = gpu.GraphicsCards
})
return gpuCache, gpuCacheErr
} }
func TotalAvailableVRAM() (uint64, error) { func TotalAvailableVRAM() (uint64, error) {