Skip to content

Commit 0c859ad

Browse files
committed
chore: memoize detected GPUs
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 6d5bde8 commit 0c859ad

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

pkg/xsysinfo/gpu.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@ package xsysinfo
22

33
import (
44
"strings"
5+
"sync"
56

67
"github.com/jaypipes/ghw"
78
"github.com/jaypipes/ghw/pkg/gpu"
89
)
910

11+
var (
12+
gpuCache []*gpu.GraphicsCard
13+
gpuCacheOnce sync.Once
14+
gpuCacheErr error
15+
)
16+
1017
func GPUs() ([]*gpu.GraphicsCard, error) {
11-
gpu, err := ghw.GPU()
12-
if err != nil {
13-
return nil, err
14-
}
18+
gpuCacheOnce.Do(func() {
19+
gpu, err := ghw.GPU()
20+
if err != nil {
21+
gpuCacheErr = err
22+
return
23+
}
24+
gpuCache = gpu.GraphicsCards
25+
})
1526

16-
return gpu.GraphicsCards, nil
27+
return gpuCache, gpuCacheErr
1728
}
1829

1930
func TotalAvailableVRAM() (uint64, error) {

0 commit comments

Comments
 (0)