2023-11-14 09:20:34 +08:00
|
|
|
//go:build darwin
|
|
|
|
|
|
2023-11-30 03:00:37 +08:00
|
|
|
package gpu
|
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 (
|
2023-12-20 05:32:24 +08:00
|
|
|
"runtime"
|
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 GetGPUInfo() GpuInfoList {
|
|
|
|
|
mem, _ := GetCPUMem()
|
2024-01-10 12:29:58 +08:00
|
|
|
if runtime.GOARCH == "amd64" {
|
2024-03-31 00:50:05 +08:00
|
|
|
return []GpuInfo{
|
|
|
|
|
{
|
|
|
|
|
Library: "cpu",
|
2024-05-31 12:54:07 +08:00
|
|
|
Variant: GetCPUCapability().String(),
|
2024-03-31 00:50:05 +08:00
|
|
|
memInfo: mem,
|
|
|
|
|
},
|
2024-01-10 12:29:58 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-31 00:50:05 +08:00
|
|
|
info := GpuInfo{
|
2024-01-10 12:29:58 +08:00
|
|
|
Library: "metal",
|
2024-03-31 00:50:05 +08:00
|
|
|
ID: "0",
|
2023-12-23 07:43:31 +08:00
|
|
|
}
|
2024-03-31 00:50:05 +08:00
|
|
|
info.TotalMemory = uint64(C.getRecommendedMaxVRAM())
|
|
|
|
|
|
|
|
|
|
// TODO is there a way to gather actual allocated video memory? (currentAllocatedSize doesn't work)
|
|
|
|
|
info.FreeMemory = info.TotalMemory
|
|
|
|
|
|
2024-05-01 23:46:03 +08:00
|
|
|
info.MinimumMemory = metalMinimumMemory
|
2024-03-31 00:50:05 +08:00
|
|
|
return []GpuInfo{info}
|
2023-12-23 07:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 10:09:23 +08:00
|
|
|
func GetCPUInfo() GpuInfoList {
|
|
|
|
|
mem, _ := GetCPUMem()
|
|
|
|
|
return []GpuInfo{
|
|
|
|
|
{
|
|
|
|
|
Library: "cpu",
|
2024-05-31 12:54:07 +08:00
|
|
|
Variant: GetCPUCapability().String(),
|
2024-06-04 10:09:23 +08:00
|
|
|
memInfo: mem,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
func (l GpuInfoList) GetVisibleDevicesEnv() (string, string) {
|
|
|
|
|
// No-op on darwin
|
|
|
|
|
return "", ""
|
|
|
|
|
}
|
2024-10-15 07:26:45 +08:00
|
|
|
|
|
|
|
|
func GetSystemInfo() SystemInfo {
|
|
|
|
|
mem, _ := GetCPUMem()
|
|
|
|
|
return SystemInfo{
|
|
|
|
|
System: CPUInfo{
|
|
|
|
|
GpuInfo: GpuInfo{
|
|
|
|
|
memInfo: mem,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
GPUs: GetGPUInfo(),
|
|
|
|
|
}
|
|
|
|
|
}
|