MCPcopy
hub / github.com/mudler/LocalAI / GetResourceInfo

Function GetResourceInfo

pkg/xsysinfo/gpu.go:924–969  ·  view source on GitHub ↗

GetResourceInfo returns GPU info if available, otherwise system RAM info

()

Source from the content-addressed store, hash-verified

922
923// GetResourceInfo returns GPU info if available, otherwise system RAM info
924func GetResourceInfo() ResourceInfo {
925 gpus := GetGPUMemoryUsage()
926
927 if len(gpus) > 0 {
928 // GPU available - return GPU info
929 aggregate := GetGPUAggregateInfo()
930 return ResourceInfo{
931 Type: "gpu",
932 Available: true,
933 GPUs: gpus,
934 RAM: nil,
935 Aggregate: AggregateMemoryInfo{
936 TotalMemory: aggregate.TotalVRAM,
937 UsedMemory: aggregate.UsedVRAM,
938 FreeMemory: aggregate.FreeVRAM,
939 UsagePercent: aggregate.UsagePercent,
940 GPUCount: aggregate.GPUCount,
941 },
942 }
943 }
944
945 // No GPU - fall back to system RAM
946 ramInfo, err := GetSystemRAMInfo()
947 if err != nil {
948 xlog.Debug("failed to get system RAM info", "error", err)
949 return ResourceInfo{
950 Type: "ram",
951 Available: false,
952 Aggregate: AggregateMemoryInfo{},
953 }
954 }
955
956 return ResourceInfo{
957 Type: "ram",
958 Available: true,
959 GPUs: nil,
960 RAM: ramInfo,
961 Aggregate: AggregateMemoryInfo{
962 TotalMemory: ramInfo.Total,
963 UsedMemory: ramInfo.Used,
964 FreeMemory: ramInfo.Free,
965 UsagePercent: ramInfo.UsagePercent,
966 GPUCount: 0,
967 },
968 }
969}
970
971// GetResourceAggregateInfo returns aggregate memory info (GPU if available, otherwise RAM)
972// This is used by the memory reclaimer to check memory usage

Callers 2

RegisterUIAPIRoutesFunction · 0.92
GetResourceAggregateInfoFunction · 0.85

Calls 3

GetGPUMemoryUsageFunction · 0.85
GetGPUAggregateInfoFunction · 0.85
GetSystemRAMInfoFunction · 0.85

Tested by

no test coverage detected