gpu_darwin.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //go:build darwin
  2. package gpu
  3. import "C"
  4. import (
  5. "runtime"
  6. "github.com/pbnjay/memory"
  7. )
  8. // CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
  9. func CheckVRAM() (int64, error) {
  10. if runtime.GOARCH == "amd64" {
  11. // gpu not supported, this may not be metal
  12. return 0, nil
  13. }
  14. // on macOS, there's already buffer for available vram (see below) so just return the total
  15. systemMemory := int64(memory.TotalMemory())
  16. // macOS limits how much memory is available to the GPU based on the amount of system memory
  17. // TODO: handle case where iogpu.wired_limit_mb is set to a higher value
  18. if systemMemory <= 36*1024*1024*1024 {
  19. systemMemory = systemMemory * 2 / 3
  20. } else {
  21. systemMemory = systemMemory * 3 / 4
  22. }
  23. return systemMemory, nil
  24. }
  25. func GetGPUInfo() GpuInfo {
  26. mem, _ := getCPUMem()
  27. return GpuInfo{
  28. Library: "default",
  29. memInfo: mem,
  30. }
  31. }
  32. func getCPUMem() (memInfo, error) {
  33. return memInfo{
  34. TotalMemory: 0,
  35. FreeMemory: 0,
  36. DeviceCount: 0,
  37. }, nil
  38. }
  39. func nativeInit() error {
  40. return nil
  41. }
  42. func GetCPUVariant() string {
  43. // We don't yet have CPU based builds for Darwin...
  44. return ""
  45. }