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 (
"strings"
"sync"
"github.com/jaypipes/ghw"
"github.com/jaypipes/ghw/pkg/gpu"
)
func GPUs() ([]*gpu.GraphicsCard, error) {
gpu, err := ghw.GPU()
if err != nil {
return nil, err
}
var (
gpuCache []*gpu.GraphicsCard
gpuCacheOnce sync.Once
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) {