gpu_darwin.go 855 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //go:build darwin
  2. package gpu
  3. /*
  4. #cgo CFLAGS: -x objective-c
  5. #cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
  6. #include "gpu_info_darwin.h"
  7. */
  8. import "C"
  9. import (
  10. "runtime"
  11. )
  12. // CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
  13. func CheckVRAM() (int64, error) {
  14. if runtime.GOARCH == "amd64" {
  15. // gpu not supported, this may not be metal
  16. return 0, nil
  17. }
  18. recommendedMaxVRAM := int64(C.getRecommendedMaxVRAM())
  19. return recommendedMaxVRAM, nil
  20. }
  21. func GetGPUInfo() GpuInfo {
  22. mem, _ := getCPUMem()
  23. if runtime.GOARCH == "amd64" {
  24. return GpuInfo{
  25. Library: "cpu",
  26. Variant: GetCPUVariant(),
  27. memInfo: mem,
  28. }
  29. }
  30. return GpuInfo{
  31. Library: "metal",
  32. memInfo: mem,
  33. }
  34. }
  35. func getCPUMem() (memInfo, error) {
  36. return memInfo{
  37. TotalMemory: 0,
  38. FreeMemory: 0,
  39. DeviceCount: 0,
  40. }, nil
  41. }