gpu_darwin.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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: GetCPUCapability(),
  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 GetCPUInfo() GpuInfoList {
  38. mem, _ := GetCPUMem()
  39. return []GpuInfo{
  40. {
  41. Library: "cpu",
  42. Variant: GetCPUCapability(),
  43. memInfo: mem,
  44. },
  45. }
  46. }
  47. func GetCPUMem() (memInfo, error) {
  48. return memInfo{
  49. TotalMemory: uint64(C.getPhysicalMemory()),
  50. FreeMemory: uint64(C.getFreeMemory()),
  51. }, nil
  52. }
  53. func (l GpuInfoList) GetVisibleDevicesEnv() (string, string) {
  54. // No-op on darwin
  55. return "", ""
  56. }