gpu_darwin.go 855 Bytes
Newer Older
1
2
//go:build darwin

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

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

24
func GetGPUInfo() GpuInfo {
25
	mem, _ := getCPUMem()
26
27
	if runtime.GOARCH == "amd64" {
		return GpuInfo{
28
			Library: "cpu",
29
30
31
32
			Variant: GetCPUVariant(),
			memInfo: mem,
		}
	}
33
	return GpuInfo{
34
		Library: "metal",
35
36
37
38
39
40
		memInfo: mem,
	}
}

func getCPUMem() (memInfo, error) {
	return memInfo{
41
42
		TotalMemory: 0,
		FreeMemory:  0,
43
		DeviceCount: 0,
44
	}, nil
45
}