mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 02:24:59 +00:00
chore: memoize detected GPUs
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
6d5bde860b
commit
0c859addce
1 changed files with 17 additions and 6 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue