"vscode:/vscode.git/clone" did not exist on "d44b7283cbf27d7b68153fda00058c76e7ccd064"
gpu_darwin.go 928 Bytes
Newer Older
1
2
//go:build darwin

3
package gpu
4

5
6
7
8
9
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
#include "gpu_info_darwin.h"
*/
10
import "C"
11
import (
Daniel Hiltgen's avatar
Daniel Hiltgen committed
12
	"runtime"
13
14
)

Daniel Hiltgen's avatar
Daniel Hiltgen committed
15
16
func GetGPUInfo() GpuInfoList {
	mem, _ := GetCPUMem()
17
	if runtime.GOARCH == "amd64" {
Daniel Hiltgen's avatar
Daniel Hiltgen committed
18
19
20
21
22
23
		return []GpuInfo{
			{
				Library: "cpu",
				Variant: GetCPUVariant(),
				memInfo: mem,
			},
24
25
		}
	}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
26
	info := GpuInfo{
27
		Library: "metal",
Daniel Hiltgen's avatar
Daniel Hiltgen committed
28
		ID:      "0",
29
	}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
30
31
32
33
34
35
36
	info.TotalMemory = uint64(C.getRecommendedMaxVRAM())

	// TODO is there a way to gather actual allocated video memory? (currentAllocatedSize doesn't work)
	info.FreeMemory = info.TotalMemory

	info.MinimumMemory = 0
	return []GpuInfo{info}
37
38
}

Daniel Hiltgen's avatar
Daniel Hiltgen committed
39
func GetCPUMem() (memInfo, error) {
40
	return memInfo{
41
		TotalMemory: uint64(C.getPhysicalMemory()),
42
		FreeMemory:  0,
43
	}, nil
44
}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
45
46
47
48
49

func (l GpuInfoList) GetVisibleDevicesEnv() (string, string) {
	// No-op on darwin
	return "", ""
}