gpu_darwin.go 928 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. func GetGPUInfo() GpuInfoList {
  13. mem, _ := GetCPUMem()
  14. if runtime.GOARCH == "amd64" {
  15. return []GpuInfo{
  16. {
  17. Library: "cpu",
  18. Variant: GetCPUVariant(),
  19. memInfo: mem,
  20. },
  21. }
  22. }
  23. info := GpuInfo{
  24. Library: "metal",
  25. ID: "0",
  26. }
  27. info.TotalMemory = uint64(C.getRecommendedMaxVRAM())
  28. // TODO is there a way to gather actual allocated video memory? (currentAllocatedSize doesn't work)
  29. info.FreeMemory = info.TotalMemory
  30. info.MinimumMemory = 0
  31. return []GpuInfo{info}
  32. }
  33. func GetCPUMem() (memInfo, error) {
  34. return memInfo{
  35. TotalMemory: uint64(C.getPhysicalMemory()),
  36. FreeMemory: 0,
  37. }, nil
  38. }
  39. func (l GpuInfoList) GetVisibleDevicesEnv() (string, string) {
  40. // No-op on darwin
  41. return "", ""
  42. }