2023-11-14 01:20:34 +00:00
|
|
|
//go:build darwin
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
package gpu
|
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"
|
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
|
|
|
|
}
|
2024-02-25 23:16:45 +00:00
|
|
|
recommendedMaxVRAM := int64(C.getRecommendedMaxVRAM())
|
|
|
|
return recommendedMaxVRAM, 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
|
|
|
}
|