gpu_darwin.go 1.01 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
}

Daniel Hiltgen's avatar
Daniel Hiltgen committed
45
func GetCPUMem() (memInfo, error) {
46
	return memInfo{
47
		TotalMemory: uint64(C.getPhysicalMemory()),
48
		FreeMemory:  0,
49
	}, nil
50
}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
51
52
53
54
55

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