package discovery import ( "reflect" "testing" ) func TestGPUProcessesOfEveryKindAreListedByIndex(t *testing.T) { report := ` 580.65.06 Tesla V100-SXM2-32GB Tesla V100-SXM2-32GB 4100Cllama-server 4300Gllama-server 4200C+G ` got, err := parseGPUProcesses([]byte(report)) if err != nil { t.Fatal(err) } // A Vulkan engine is a graphics process ("G") and is on its GPU all the // same; a compute-only query would have missed it. want := map[int][]int{1: {4100, 4300}, 2: {4200}} if !reflect.DeepEqual(got, want) { t.Errorf("got %v, want %v", got, want) } if _, err := parseGPUProcesses([]byte("not xml")); err == nil { t.Error("a report that does not parse was read as no processes") } } func TestGPUMemoryIsReadPerProcess(t *testing.T) { report := ` Quadro RTX 6000 24576 MiB14514 MiB10062 MiB 71315C4932 MiB 4100C9500 MiB N/A ` got, err := parseGPUMemory([]byte(report)) if err != nil { t.Fatal(err) } want := []GPUMemory{ {Index: 0, UsedMB: 14514, Procs: []GPUProcess{{PID: 71315, UsedMB: 4932}, {PID: 4100, UsedMB: 9500}}}, {Index: 1}, } if !reflect.DeepEqual(got, want) { t.Errorf("got %+v, want %+v", got, want) } } func TestForeignMemoryBelowTheToleranceIsNoProblem(t *testing.T) { // A CUDA context that has let go of its model still holds a few hundred // MiB: ComfyUI after /free held 324. if p := ForeignMemoryProblem(330); p != "" { t.Errorf("330 MiB is a problem: %q", p) } p := ForeignMemoryProblem(5014) if !IsForeignMemoryProblem(p) || IsForeignMemoryProblem("2 uncorrected ECC errors") { t.Errorf("%q is not recognised as the foreign memory problem, or ECC is", p) } }