"megatron/vscode:/vscode.git/clone" did not exist on "6529003325ebd5c19e6aa62ef2df4fdf2676c8f4"
gpu_darwin.go 1.1 KB
Newer Older
1
2
//go:build darwin

3
package gpu
4

5
import "C"
6
import (
Daniel Hiltgen's avatar
Daniel Hiltgen committed
7
8
	"runtime"

9
	"github.com/pbnjay/memory"
10
11
12
13
)

// CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
func CheckVRAM() (int64, error) {
14
15
16
17
18
19
20
	if runtime.GOARCH == "amd64" {
		// gpu not supported, this may not be metal
		return 0, nil
	}

	// on macOS, there's already buffer for available vram (see below) so just return the total
	systemMemory := int64(memory.TotalMemory())
21

22
23
24
25
26
27
28
29
30
	// macOS limits how much memory is available to the GPU based on the amount of system memory
	// TODO: handle case where iogpu.wired_limit_mb is set to a higher value
	if systemMemory <= 36*1024*1024*1024 {
		systemMemory = systemMemory * 2 / 3
	} else {
		systemMemory = systemMemory * 3 / 4
	}

	return systemMemory, nil
31
32
}

33
func GetGPUInfo() GpuInfo {
34
	mem, _ := getCPUMem()
35
36
37
38
39
40
41
	if runtime.GOARCH == "amd64" {
		return GpuInfo{
			Library: "default",
			Variant: GetCPUVariant(),
			memInfo: mem,
		}
	}
42
	return GpuInfo{
43
		Library: "metal",
44
45
46
47
48
49
		memInfo: mem,
	}
}

func getCPUMem() (memInfo, error) {
	return memInfo{
50
51
		TotalMemory: 0,
		FreeMemory:  0,
52
		DeviceCount: 0,
53
	}, nil
54
}