"docs/EN/vscode:/vscode.git/clone" did not exist on "abf365933def1cebdfa3a48d9df439c536161f01"
gpu_darwin.go 1.16 KB
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
15
16
17

	"github.com/ollama/ollama/format"
)

const (
Daniel Hiltgen's avatar
Daniel Hiltgen committed
18
	metalMinimumMemory = 512 * format.MebiByte
19
20
)

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

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

41
	info.MinimumMemory = metalMinimumMemory
Daniel Hiltgen's avatar
Daniel Hiltgen committed
42
	return []GpuInfo{info}
43
44
}

45
46
47
48
49
50
51
52
53
54
55
func GetCPUInfo() GpuInfoList {
	mem, _ := GetCPUMem()
	return []GpuInfo{
		{
			Library: "cpu",
			Variant: GetCPUVariant(),
			memInfo: mem,
		},
	}
}

Daniel Hiltgen's avatar
Daniel Hiltgen committed
56
func GetCPUMem() (memInfo, error) {
57
	return memInfo{
58
		TotalMemory: uint64(C.getPhysicalMemory()),
59
		FreeMemory:  0,
60
	}, nil
61
}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
62
63
64
65
66

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