2024-10-17 08:45:00 +08:00
|
|
|
package discover
|
2024-03-07 08:53:51 +08:00
|
|
|
|
2024-02-26 07:16:45 +08:00
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -x objective-c
|
|
|
|
#cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
|
|
|
|
#include "gpu_info_darwin.h"
|
|
|
|
*/
|
2023-11-30 03:00:37 +08:00
|
|
|
import "C"
|
2024-08-02 05:52:15 +08:00
|
|
|
|
2023-11-14 09:20:34 +08:00
|
|
|
import (
|
2024-10-16 02:36:08 +08:00
|
|
|
"log/slog"
|
|
|
|
"syscall"
|
2024-05-01 23:46:03 +08:00
|
|
|
|
|
|
|
"github.com/ollama/ollama/format"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-05-11 00:15:28 +08:00
|
|
|
metalMinimumMemory = 512 * format.MebiByte
|
2023-11-14 09:20:34 +08:00
|
|
|
)
|
|
|
|
|
2024-03-31 00:50:05 +08:00
|
|
|
func GetCPUMem() (memInfo, error) {
|
2023-12-23 07:43:31 +08:00
|
|
|
return memInfo{
|
2024-04-17 02:22:38 +08:00
|
|
|
TotalMemory: uint64(C.getPhysicalMemory()),
|
2024-07-07 07:35:04 +08:00
|
|
|
FreeMemory: uint64(C.getFreeMemory()),
|
2024-07-12 07:42:57 +08:00
|
|
|
// FreeSwap omitted as Darwin uses dynamic paging
|
2023-12-23 07:43:31 +08:00
|
|
|
}, nil
|
2023-11-30 03:00:37 +08:00
|
|
|
}
|
2024-03-31 00:50:05 +08:00
|
|
|
|
2025-10-02 06:12:32 +08:00
|
|
|
func GetCPUDetails() []CPU {
|
2024-10-16 02:36:08 +08:00
|
|
|
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)
|
|
|
|
|
2025-10-02 06:12:32 +08:00
|
|
|
return []CPU{
|
|
|
|
{
|
|
|
|
CoreCount: int(perfCores + efficiencyCores),
|
|
|
|
EfficiencyCoreCount: int(efficiencyCores),
|
|
|
|
ThreadCount: int(logicalCores),
|
2024-10-15 07:26:45 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2025-10-02 06:12:32 +08:00
|
|
|
|
|
|
|
func IsNUMA() bool {
|
|
|
|
// numa support in ggml is linux only
|
|
|
|
return false
|
|
|
|
}
|