gpu_darwin.go 909 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package gpu
  2. /*
  3. #cgo CFLAGS: -x objective-c
  4. #cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
  5. #include "gpu_info_darwin.h"
  6. */
  7. import "C"
  8. import (
  9. "runtime"
  10. )
  11. func GetGPUInfo() GpuInfoList {
  12. mem, _ := GetCPUMem()
  13. if runtime.GOARCH == "amd64" {
  14. return []GpuInfo{
  15. {
  16. Library: "cpu",
  17. Variant: GetCPUVariant(),
  18. memInfo: mem,
  19. },
  20. }
  21. }
  22. info := GpuInfo{
  23. Library: "metal",
  24. ID: "0",
  25. }
  26. info.TotalMemory = uint64(C.getRecommendedMaxVRAM())
  27. // TODO is there a way to gather actual allocated video memory? (currentAllocatedSize doesn't work)
  28. info.FreeMemory = info.TotalMemory
  29. info.MinimumMemory = 0
  30. return []GpuInfo{info}
  31. }
  32. func GetCPUMem() (memInfo, error) {
  33. return memInfo{
  34. TotalMemory: uint64(C.getPhysicalMemory()),
  35. FreeMemory: 0,
  36. }, nil
  37. }
  38. func (l GpuInfoList) GetVisibleDevicesEnv() (string, string) {
  39. // No-op on darwin
  40. return "", ""
  41. }