2023-11-14 01:20:34 +00:00
|
|
|
//go:build darwin
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
package gpu
|
2024-03-07 00:53:51 +00:00
|
|
|
|
2024-02-25 23:16:45 +00:00
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -x objective-c
|
|
|
|
#cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
|
|
|
|
#include "gpu_info_darwin.h"
|
|
|
|
*/
|
2023-11-29 19:00:37 +00:00
|
|
|
import "C"
|
2023-11-14 01:20:34 +00:00
|
|
|
import (
|
2023-12-19 21:32:24 +00:00
|
|
|
"runtime"
|
2024-05-01 15:46:03 +00:00
|
|
|
|
|
|
|
"github.com/ollama/ollama/format"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-05-10 16:15:28 +00:00
|
|
|
metalMinimumMemory = 512 * format.MebiByte
|
2023-11-14 01:20:34 +00:00
|
|
|
)
|
|
|
|
|
2024-03-30 16:50:05 +00:00
|
|
|
func GetGPUInfo() GpuInfoList {
|
|
|
|
mem, _ := GetCPUMem()
|
2024-01-10 04:29:58 +00:00
|
|
|
if runtime.GOARCH == "amd64" {
|
2024-03-30 16:50:05 +00:00
|
|
|
return []GpuInfo{
|
|
|
|
{
|
|
|
|
Library: "cpu",
|
2024-06-05 19:07:20 +00:00
|
|
|
Variant: GetCPUCapability(),
|
2024-03-30 16:50:05 +00:00
|
|
|
memInfo: mem,
|
|
|
|
},
|
2024-01-10 04:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-30 16:50:05 +00:00
|
|
|
info := GpuInfo{
|
2024-01-10 04:29:58 +00:00
|
|
|
Library: "metal",
|
2024-03-30 16:50:05 +00:00
|
|
|
ID: "0",
|
2023-12-22 23:43:31 +00:00
|
|
|
}
|
2024-03-30 16:50:05 +00: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 15:46:03 +00:00
|
|
|
info.MinimumMemory = metalMinimumMemory
|
2024-03-30 16:50:05 +00:00
|
|
|
return []GpuInfo{info}
|
2023-12-22 23:43:31 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 02:09:23 +00:00
|
|
|
func GetCPUInfo() GpuInfoList {
|
|
|
|
mem, _ := GetCPUMem()
|
|
|
|
return []GpuInfo{
|
|
|
|
{
|
|
|
|
Library: "cpu",
|
2024-06-05 19:07:20 +00:00
|
|
|
Variant: GetCPUCapability(),
|
2024-06-04 02:09:23 +00:00
|
|
|
memInfo: mem,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-30 16:50:05 +00:00
|
|
|
func GetCPUMem() (memInfo, error) {
|
2023-12-22 23:43:31 +00:00
|
|
|
return memInfo{
|
2024-04-16 18:22:38 +00:00
|
|
|
TotalMemory: uint64(C.getPhysicalMemory()),
|
2024-07-06 23:35:04 +00:00
|
|
|
FreeMemory: uint64(C.getFreeMemory()),
|
2023-12-22 23:43:31 +00:00
|
|
|
}, nil
|
2023-11-29 19:00:37 +00:00
|
|
|
}
|
2024-03-30 16:50:05 +00:00
|
|
|
|
|
|
|
func (l GpuInfoList) GetVisibleDevicesEnv() (string, string) {
|
|
|
|
// No-op on darwin
|
|
|
|
return "", ""
|
|
|
|
}
|