chore: memoize detected GPUs (#5385)

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2025-05-18 08:55:44 +02:00
committed by GitHub
parent cfc73c7773
commit 159388cce8

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) {