2023-11-13 20:20:34 -05:00
|
|
|
//go:build darwin
|
|
|
|
|
2023-11-29 14:00:37 -05:00
|
|
|
package gpu
|
2024-03-06 19:53:51 -05:00
|
|
|
|
2024-02-25 18:16:45 -05:00
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -x objective-c
|
|
|
|
#cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
|
|
|
|
#include "gpu_info_darwin.h"
|
|
|
|
*/
|
2023-11-29 14:00:37 -05:00
|
|
|
import "C"
|
2023-11-13 20:20:34 -05:00
|
|
|
import (
|
2024-03-06 19:53:51 -05:00
|
|
|
"fmt"
|
|
|
|
"log/slog"
|
|
|
|
"os"
|
2023-12-19 16:32:24 -05:00
|
|
|
"runtime"
|
2024-03-06 19:53:51 -05:00
|
|
|
"strconv"
|
2023-11-13 20:20:34 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
|
|
|
|
func CheckVRAM() (int64, error) {
|
2024-03-06 19:53:51 -05:00
|
|
|
userLimit := os.Getenv("OLLAMA_MAX_VRAM")
|
|
|
|
if userLimit != "" {
|
|
|
|
avail, err := strconv.ParseInt(userLimit, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf("Invalid OLLAMA_MAX_VRAM setting %s: %s", userLimit, err)
|
|
|
|
}
|
|
|
|
slog.Info(fmt.Sprintf("user override OLLAMA_MAX_VRAM=%d", avail))
|
|
|
|
return avail, nil
|
|
|
|
}
|
|
|
|
|
2024-01-08 16:42:00 -05:00
|
|
|
if runtime.GOARCH == "amd64" {
|
|
|
|
// gpu not supported, this may not be metal
|
|
|
|
return 0, nil
|
|
|
|
}
|
2024-02-25 18:16:45 -05:00
|
|
|
recommendedMaxVRAM := int64(C.getRecommendedMaxVRAM())
|
|
|
|
return recommendedMaxVRAM, nil
|
2023-11-13 20:20:34 -05:00
|
|
|
}
|
|
|
|
|
2023-11-29 14:00:37 -05:00
|
|
|
func GetGPUInfo() GpuInfo {
|
2023-12-22 18:43:31 -05:00
|
|
|
mem, _ := getCPUMem()
|
2024-01-09 23:29:58 -05:00
|
|
|
if runtime.GOARCH == "amd64" {
|
|
|
|
return GpuInfo{
|
2024-01-11 17:43:16 -05:00
|
|
|
Library: "cpu",
|
2024-01-09 23:29:58 -05:00
|
|
|
Variant: GetCPUVariant(),
|
|
|
|
memInfo: mem,
|
|
|
|
}
|
|
|
|
}
|
2023-11-29 14:00:37 -05:00
|
|
|
return GpuInfo{
|
2024-01-09 23:29:58 -05:00
|
|
|
Library: "metal",
|
2023-12-22 18:43:31 -05:00
|
|
|
memInfo: mem,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getCPUMem() (memInfo, error) {
|
|
|
|
return memInfo{
|
2023-11-29 14:00:37 -05:00
|
|
|
TotalMemory: 0,
|
|
|
|
FreeMemory: 0,
|
2024-01-09 15:53:33 -05:00
|
|
|
DeviceCount: 0,
|
2023-12-22 18:43:31 -05:00
|
|
|
}, nil
|
2023-11-29 14:00:37 -05:00
|
|
|
}
|