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