"src/targets/vscode:/vscode.git/clone" did not exist on "09e3822dd2e7b33f61e1f35bce4ad6a8ec878574"
gpu_darwin.go 1.17 KB
Newer Older
1
package discover
2

3
4
5
6
7
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
#include "gpu_info_darwin.h"
*/
8
import "C"
Michael Yang's avatar
lint  
Michael Yang committed
9

10
import (
11
12
	"log/slog"
	"syscall"
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
func GetCPUMem() (memInfo, error) {
22
	return memInfo{
23
		TotalMemory: uint64(C.getPhysicalMemory()),
24
		FreeMemory:  uint64(C.getFreeMemory()),
25
		// FreeSwap omitted as Darwin uses dynamic paging
26
	}, nil
27
}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
28

29
func GetCPUDetails() []CPU {
30
31
32
33
34
35
36
37
38
39
40
41
	query := "hw.perflevel0.physicalcpu"
	perfCores, err := syscall.SysctlUint32(query)
	if err != nil {
		slog.Warn("failed to discover physical CPU details", "query", query, "error", err)
	}
	query = "hw.perflevel1.physicalcpu"
	efficiencyCores, _ := syscall.SysctlUint32(query) // On x86 xeon this wont return data

	// Determine thread count
	query = "hw.logicalcpu"
	logicalCores, _ := syscall.SysctlUint32(query)

42
43
44
45
46
	return []CPU{
		{
			CoreCount:           int(perfCores + efficiencyCores),
			EfficiencyCoreCount: int(efficiencyCores),
			ThreadCount:         int(logicalCores),
47
48
49
		},
	}
}
50
51
52
53
54

func IsNUMA() bool {
	// numa support in ggml is linux only
	return false
}