2023-11-14 01:20:34 +00:00
|
|
|
//go:build darwin
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
package gpu
|
2024-03-07 00:53:51 +00:00
|
|
|
|
2024-02-25 23:16:45 +00:00
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -x objective-c
|
|
|
|
#cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
|
|
|
|
#include "gpu_info_darwin.h"
|
|
|
|
*/
|
2023-11-29 19:00:37 +00:00
|
|
|
import "C"
|
2023-11-14 01:20:34 +00:00
|
|
|
import (
|
2024-03-07 00:53:51 +00:00
|
|
|
"fmt"
|
|
|
|
"log/slog"
|
|
|
|
"os"
|
2023-12-19 21:32:24 +00:00
|
|
|
"runtime"
|
2024-03-07 00:53:51 +00:00
|
|
|
"strconv"
|
2023-11-14 01:20:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
|
2024-04-05 21:50:38 +00:00
|
|
|
func CheckVRAM() (uint64, error) {
|
2024-03-07 00:53:51 +00: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))
|
2024-04-05 21:50:38 +00:00
|
|
|
return uint64(avail), nil
|
2024-03-07 00:53:51 +00:00
|
|
|
}
|
|
|
|
|
2024-01-08 21:42:00 +00:00
|
|
|
if runtime.GOARCH == "amd64" {
|
|
|
|
// gpu not supported, this may not be metal
|
|
|
|
return 0, nil
|
|
|
|
}
|
2024-04-05 21:50:38 +00:00
|
|
|
return uint64(C.getRecommendedMaxVRAM()), nil
|
2023-11-14 01:20:34 +00:00
|
|
|
}
|
|
|
|
|
2023-11-29 19:00:37 +00:00
|
|
|
func GetGPUInfo() GpuInfo {
|
2023-12-22 23:43:31 +00:00
|
|
|
mem, _ := getCPUMem()
|
2024-01-10 04:29:58 +00:00
|
|
|
if runtime.GOARCH == "amd64" {
|
|
|
|
return GpuInfo{
|
2024-01-11 22:43:16 +00:00
|
|
|
Library: "cpu",
|
2024-01-10 04:29:58 +00:00
|
|
|
Variant: GetCPUVariant(),
|
|
|
|
memInfo: mem,
|
|
|
|
}
|
|
|
|
}
|
2023-11-29 19:00:37 +00:00
|
|
|
return GpuInfo{
|
2024-01-10 04:29:58 +00:00
|
|
|
Library: "metal",
|
2023-12-22 23:43:31 +00:00
|
|
|
memInfo: mem,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getCPUMem() (memInfo, error) {
|
|
|
|
return memInfo{
|
2023-11-29 19:00:37 +00:00
|
|
|
TotalMemory: 0,
|
|
|
|
FreeMemory: 0,
|
2024-01-09 20:53:33 +00:00
|
|
|
DeviceCount: 0,
|
2023-12-22 23:43:31 +00:00
|
|
|
}, nil
|
2023-11-29 19:00:37 +00:00
|
|
|
}
|