types.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package gpu
  2. type memInfo struct {
  3. TotalMemory uint64 `json:"total_memory,omitempty"`
  4. FreeMemory uint64 `json:"free_memory,omitempty"`
  5. }
  6. // Beginning of an `ollama info` command
  7. type GpuInfo struct {
  8. memInfo
  9. Library string `json:"library,omitempty"`
  10. // Optional variant to select (e.g. versions, cpu feature flags)
  11. Variant string `json:"variant,omitempty"`
  12. // MinimumMemory represents the minimum memory required to use the GPU
  13. MinimumMemory uint64 `json:"-"`
  14. // Any extra PATH/LD_LIBRARY_PATH dependencies required for the Library to operate properly
  15. DependencyPath string `json:"lib_path,omitempty"`
  16. // GPU information
  17. ID string `json:"gpu_id"` // string to use for selection of this specific GPU
  18. Name string `json:"name"` // user friendly name if available
  19. Major int `json:"major,omitempty"` // Major compatibility version (CC or gfx)
  20. Minor int `json:"minor,omitempty"` // Minor compatibility version (CC or gfx)
  21. Patch int `json:"patch,omitempty"` // Patch compatibility only matters on AMD
  22. // TODO other performance capability info to help in scheduling decisions
  23. }
  24. type GpuInfoList []GpuInfo
  25. // Split up the set of gpu info's by Library and variant
  26. func (l GpuInfoList) ByLibrary() []GpuInfoList {
  27. resp := []GpuInfoList{}
  28. libs := []string{}
  29. for _, info := range l {
  30. found := false
  31. requested := info.Library
  32. if info.Variant != "" {
  33. requested += "_" + info.Variant
  34. }
  35. for i, lib := range libs {
  36. if lib == requested {
  37. resp[i] = append(resp[i], info)
  38. found = true
  39. break
  40. }
  41. }
  42. if !found {
  43. libs = append(libs, info.Library)
  44. resp = append(resp, []GpuInfo{info})
  45. }
  46. }
  47. return resp
  48. }
  49. // Sort by Free Space
  50. type ByFreeMemory []GpuInfo
  51. func (a ByFreeMemory) Len() int { return len(a) }
  52. func (a ByFreeMemory) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
  53. func (a ByFreeMemory) Less(i, j int) bool { return a[i].FreeMemory < a[j].FreeMemory }