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