types.go 1.87 KB
Newer Older
1
package discover
2

Daniel Hiltgen's avatar
Daniel Hiltgen committed
3
4
import (
	"log/slog"
5
	"path/filepath"
6
	"sort"
7
	"strings"
Daniel Hiltgen's avatar
Daniel Hiltgen committed
8
9

	"github.com/ollama/ollama/format"
10
	"github.com/ollama/ollama/ml"
Daniel Hiltgen's avatar
Daniel Hiltgen committed
11
12
)

13
type memInfo struct {
14
15
	TotalMemory uint64 `json:"total_memory,omitempty"`
	FreeMemory  uint64 `json:"free_memory,omitempty"`
16
	FreeSwap    uint64 `json:"free_swap,omitempty"` // TODO split this out for system only
17
18
}

19
20
21
22
23
24
25
26
// CPU type represents a CPU Package occupying a socket
type CPU struct {
	ID                  string `cpuinfo:"processor"`
	VendorID            string `cpuinfo:"vendor_id"`
	ModelName           string `cpuinfo:"model name"`
	CoreCount           int
	EfficiencyCoreCount int // Performance = CoreCount - Efficiency
	ThreadCount         int
27
28
}

29
func LogDetails(devices []ml.DeviceInfo) {
30
	sort.Sort(sort.Reverse(ml.ByFreeMemory(devices))) // Report devices in order of scheduling preference
31
32
33
34
35
36
37
38
39
40
41
	for _, dev := range devices {
		var libs []string
		for _, dir := range dev.LibraryPath {
			if strings.Contains(dir, filepath.Join("lib", "ollama")) {
				libs = append(libs, filepath.Base(dir))
			}
		}
		typeStr := "discrete"
		if dev.Integrated {
			typeStr = "iGPU"
		}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
42
		slog.Info("inference compute",
43
			"id", dev.ID,
44
			"filter_id", dev.FilterID,
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
			"library", dev.Library,
			"compute", dev.Compute(),
			"name", dev.Name,
			"description", dev.Description,
			"libdirs", strings.Join(libs, ","),
			"driver", dev.Driver(),
			"pci_id", dev.PCIID,
			"type", typeStr,
			"total", format.HumanBytes2(dev.TotalMemory),
			"available", format.HumanBytes2(dev.FreeMemory),
		)
	}
	// CPU inference
	if len(devices) == 0 {
		dev, _ := GetCPUMem()
		slog.Info("inference compute",
			"id", "cpu",
			"library", "cpu",
			"compute", "",
			"name", "cpu",
			"description", "cpu",
			"libdirs", "ollama",
			"driver", "",
			"pci_id", "",
			"type", "",
			"total", format.HumanBytes2(dev.TotalMemory),
			"available", format.HumanBytes2(dev.FreeMemory),
Daniel Hiltgen's avatar
Daniel Hiltgen committed
72
73
74
		)
	}
}