Skip to content

Commit 7730970

Browse files
author
Piotr Stankiewicz
committed
Use nv-gpu-info on Windows to get VRAM size
Signed-off-by: Piotr Stankiewicz <piotr.stankiewicz@docker.com>
1 parent f9ff5fd commit 7730970

File tree

7 files changed

+38
-103
lines changed

7 files changed

+38
-103
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func main() {
9090
log.Fatalf("unable to initialize %s backend: %v", llamacpp.Name, err)
9191
}
9292

93-
gpuInfo := gpuinfo.New()
93+
gpuInfo := gpuinfo.New(llamaServerPath)
9494

9595
scheduler := scheduling.NewScheduler(
9696
log,

pkg/gpuinfo/gpuinfo.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package gpuinfo
22

3-
type GPUInfo struct{}
3+
type GPUInfo struct {
4+
// modelRuntimeInstallPath is the location where DMR installed it's llama-server
5+
// and accompanying tools
6+
modelRuntimeInstallPath string
7+
}
48

5-
func New() *GPUInfo {
6-
return &GPUInfo{}
9+
func New(modelRuntimeInstallPath string) *GPUInfo {
10+
return &GPUInfo{
11+
modelRuntimeInstallPath: modelRuntimeInstallPath,
12+
}
713
}
814

915
func (g *GPUInfo) GetVRAMSize() (uint64, error) {
10-
return getVRAMSize()
16+
return getVRAMSize(g.modelRuntimeInstallPath)
1117
}

pkg/gpuinfo/memory_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "C"
88
import "errors"
99

1010
// getVRAMSize returns total system GPU memory in bytes
11-
func getVRAMSize() (uint64, error) {
11+
func getVRAMSize(_ string) (uint64, error) {
1212
vramSize := C.getVRAMSize()
1313
if vramSize == 0 {
1414
return 0, errors.New("could not get metal VRAM size")

pkg/gpuinfo/memory_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "C"
88
import "errors"
99

1010
// getVRAMSize returns total system GPU memory in bytes
11-
func getVRAMSize() (uint64, error) {
11+
func getVRAMSize(_ string) (uint64, error) {
1212
vramSize := C.getVRAMSize()
1313
if vramSize == 0 {
1414
return 0, errors.New("could not get nvidia VRAM size")

pkg/gpuinfo/memory_windows.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
package gpuinfo
22

3-
/*
4-
#include "nvapi.h"
5-
*/
6-
import "C"
7-
import "errors"
3+
import (
4+
"bufio"
5+
"context"
6+
"errors"
7+
"os/exec"
8+
"path/filepath"
9+
"strconv"
10+
"strings"
11+
)
812

913
// getVRAMSize returns total system GPU memory in bytes
10-
func getVRAMSize() (uint64, error) {
11-
vramSize := C.getVRAMSize()
12-
if vramSize == 0 {
13-
return 0, errors.New("could not get nvapi VRAM size")
14+
func getVRAMSize(ctx context.Context, modelRuntimeInstallPath string) (uint64, error) {
15+
nvGPUInfoBin := filepath.Join(modelRuntimeInstallPath, "com.docker.nv-gpu-info.exe")
16+
17+
cmd := exec.CommandContext(ctx, nvGPUInfoBin)
18+
out, err := cmd.CombinedOutput()
19+
if err != nil {
20+
return 0, err
21+
}
22+
sc := bufio.NewScanner(strings.NewReader(string(out)))
23+
for sc.Scan() {
24+
vram, found := strings.CutPrefix(sc.Text(), "GPU[0]: dedicated memory:")
25+
if found {
26+
vram = strings.TrimSpace(vram)
27+
return strconv.ParseUint(vram, 10, 64)
28+
}
1429
}
15-
return uint64(vramSize), nil
30+
return 0, errors.New("unexpected nv-gpu-info output format")
1631
}

pkg/gpuinfo/nvapi.c

Lines changed: 0 additions & 80 deletions
This file was deleted.

pkg/gpuinfo/nvapi.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)