2023-11-14 01:20:34 +00:00
|
|
|
//go:build darwin
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
package gpu
|
2023-11-14 01:20:34 +00:00
|
|
|
|
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-01-08 21:42:00 +00:00
|
|
|
"github.com/pbnjay/memory"
|
2023-11-14 01:20:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
|
|
|
|
func CheckVRAM() (int64, error) {
|
2024-01-08 21:42:00 +00:00
|
|
|
if runtime.GOARCH == "amd64" {
|
|
|
|
// gpu not supported, this may not be metal
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// on macOS, there's already buffer for available vram (see below) so just return the total
|
|
|
|
systemMemory := int64(memory.TotalMemory())
|
2023-11-14 01:20:34 +00:00
|
|
|
|
2024-01-08 21:42:00 +00:00
|
|
|
// macOS limits how much memory is available to the GPU based on the amount of system memory
|
|
|
|
// TODO: handle case where iogpu.wired_limit_mb is set to a higher value
|
|
|
|
if systemMemory <= 36*1024*1024*1024 {
|
|
|
|
systemMemory = systemMemory * 2 / 3
|
|
|
|
} else {
|
|
|
|
systemMemory = systemMemory * 3 / 4
|
|
|
|
}
|
|
|
|
|
|
|
|
return systemMemory, nil
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
func GetGPUInfo() GpuInfo {
|
2023-12-22 23:43:31 +00:00
|
|
|
mem, _ := getCPUMem()
|
2024-01-10 04:29:58 +00:00
|
|
|
if runtime.GOARCH == "amd64" {
|
|
|
|
return GpuInfo{
|
2024-01-11 22:43:16 +00:00
|
|
|
Library: "cpu",
|
2024-01-10 04:29:58 +00:00
|
|
|
Variant: GetCPUVariant(),
|
|
|
|
memInfo: mem,
|
|
|
|
}
|
|
|
|
}
|
2023-11-29 19:00:37 +00:00
|
|
|
return GpuInfo{
|
2024-01-10 04:29:58 +00:00
|
|
|
Library: "metal",
|
2023-12-22 23:43:31 +00:00
|
|
|
memInfo: mem,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getCPUMem() (memInfo, error) {
|
|
|
|
return memInfo{
|
2023-11-29 19:00:37 +00:00
|
|
|
TotalMemory: 0,
|
|
|
|
FreeMemory: 0,
|
2024-01-09 20:53:33 +00:00
|
|
|
DeviceCount: 0,
|
2023-12-22 23:43:31 +00:00
|
|
|
}, nil
|
2023-11-29 19:00:37 +00:00
|
|
|
}
|