2023-11-29 19:00:37 +00:00
|
|
|
package gpu
|
|
|
|
|
2023-12-22 23:43:31 +00:00
|
|
|
type memInfo struct {
|
2023-11-29 19:00:37 +00:00
|
|
|
TotalMemory uint64 `json:"total_memory,omitempty"`
|
|
|
|
FreeMemory uint64 `json:"free_memory,omitempty"`
|
2023-12-22 23:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Beginning of an `ollama info` command
|
|
|
|
type GpuInfo struct {
|
|
|
|
memInfo
|
|
|
|
Library string `json:"library,omitempty"`
|
2023-11-29 19:00:37 +00:00
|
|
|
|
2024-01-05 20:13:08 +00:00
|
|
|
// Optional variant to select (e.g. versions, cpu feature flags)
|
|
|
|
Variant string `json:"variant,omitempty"`
|
|
|
|
|
2024-03-18 09:45:22 +00:00
|
|
|
// MinimumMemory represents the minimum memory required to use the GPU
|
2024-04-05 21:50:38 +00:00
|
|
|
MinimumMemory uint64 `json:"-"`
|
2024-03-18 09:45:22 +00:00
|
|
|
|
2024-03-30 16:50:05 +00:00
|
|
|
// 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
|
2023-11-29 19:00:37 +00:00
|
|
|
}
|
2024-02-11 22:50:06 +00:00
|
|
|
|
2024-03-30 16:50:05 +00:00
|
|
|
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
|
2024-02-11 22:50:06 +00:00
|
|
|
}
|
2024-03-30 16:50:05 +00:00
|
|
|
|
|
|
|
// 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 }
|