types.go 1.91 KB
Newer Older
1
2
package gpu

3
type memInfo struct {
4
5
	TotalMemory uint64 `json:"total_memory,omitempty"`
	FreeMemory  uint64 `json:"free_memory,omitempty"`
6
7
8
9
10
11
}

// Beginning of an `ollama info` command
type GpuInfo struct {
	memInfo
	Library string `json:"library,omitempty"`
12

13
14
15
	// Optional variant to select (e.g. versions, cpu feature flags)
	Variant string `json:"variant,omitempty"`

Michael Yang's avatar
Michael Yang committed
16
	// MinimumMemory represents the minimum memory required to use the GPU
Michael Yang's avatar
Michael Yang committed
17
	MinimumMemory uint64 `json:"-"`
Michael Yang's avatar
Michael Yang committed
18

Daniel Hiltgen's avatar
Daniel Hiltgen committed
19
20
21
22
23
24
25
26
27
28
29
	// Any extra PATH/LD_LIBRARY_PATH dependencies required for the Library to operate properly
	DependencyPath string `json:"lib_path,omitempty"`

	// GPU information
	ID    string `json:"gpu_id"`          // string to use for selection of this specific GPU
	Name  string `json:"name"`            // user friendly name if available
	Major int    `json:"major,omitempty"` // Major compatibility version (CC or gfx)
	Minor int    `json:"minor,omitempty"` // Minor compatibility version (CC or gfx)
	Patch int    `json:"patch,omitempty"` // Patch compatibility only matters on AMD

	// TODO other performance capability info to help in scheduling decisions
30
}
31

Daniel Hiltgen's avatar
Daniel Hiltgen committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
type GpuInfoList []GpuInfo

// Split up the set of gpu info's by Library and variant
func (l GpuInfoList) ByLibrary() []GpuInfoList {
	resp := []GpuInfoList{}
	libs := []string{}
	for _, info := range l {
		found := false
		requested := info.Library
		if info.Variant != "" {
			requested += "_" + info.Variant
		}
		for i, lib := range libs {
			if lib == requested {
				resp[i] = append(resp[i], info)
				found = true
				break
			}
		}
		if !found {
			libs = append(libs, info.Library)
			resp = append(resp, []GpuInfo{info})
		}
	}
	return resp
57
}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
58
59
60
61
62
63
64

// Sort by Free Space
type ByFreeMemory []GpuInfo

func (a ByFreeMemory) Len() int           { return len(a) }
func (a ByFreeMemory) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByFreeMemory) Less(i, j int) bool { return a[i].FreeMemory < a[j].FreeMemory }