gpu_darwin.go 1.0 KB

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