public void WatcherWithCustomGpuGroupTest() { var gpuMetrics = new GpuMetrics(); var gpuIds = gpuMetrics.GetAllSupportedGpus(); // Create a custom GPU group containing only half of the actual number of GPUs on the system. var lastIdx = (int)Math.Ceiling((double)gpuIds.Length / 2); var expectedGpuIdList = gpuIds[0..lastIdx];
public void WatcherWithDefaultGpuGroupTest() { var gpuMetrics = new GpuMetrics(); var expectedGpuIdList = gpuMetrics.GetAllSupportedGpus(); using var watcher = gpuMetrics.GetWatcher("metrics", TimeSpan.FromMilliseconds(100)); var gpuGroup = watcher.GpuGroup; Assert.NotNull(gpuGroup); var groupInfo = gpuGroup.GetInfo(); var deviceIds = groupInfo.DeviceIds; // Verify that deviceIds value is not null or empty when GpuGroup.GetInfo() is called. Assert.NotNull(deviceIds); Assert.NotEmpty(deviceIds); // Verify that GPU group contains all GPU identifiers. Assert.Equal(expectedGpuIdList, deviceIds); }
public void GetAllSupportedGpusTest() { var gpuMetrics = new GpuMetrics(); var gpuIdList1 = gpuMetrics.GetAllSupportedGpus(); var gpuIdList2 = gpuMetrics.GetAllSupportedGpus(); var gpuIdList3 = gpuMetrics.GetAllSupportedGpus(); // Verify consistency between different calls to GpuMetrics.GetAllSupportedGpus() Assert.Equal(gpuIdList1, gpuIdList2); Assert.Equal(gpuIdList2, gpuIdList3); var startInfo = new ProcessStartInfo { FileName = "nvidia-smi", Arguments = "-q -x", RedirectStandardOutput = true, UseShellExecute = false, WorkingDirectory = Environment.CurrentDirectory, CreateNoWindow = false, }; /* * This test is only valid if all GPUs on the system are supported by DCGM (Data Center GPU Manager). * For more details on the supported GPUs please refer DCGM team. */ using var process = new Process() { StartInfo = startInfo }; process.Start(); string nvidiaSmiXml = process.StandardOutput.ReadToEnd(); var doc = new XmlDocument(); doc.LoadXml(nvidiaSmiXml); var expectedNumberOfGpus = doc.DocumentElement.SelectSingleNode("/nvidia_smi_log/attached_gpus")?.InnerText; // Verify number of GPUs reported by GpuMetrics.GetAllSupportedGpus() and nvidia-smi are same. Assert.Equal(expectedNumberOfGpus, gpuIdList1.Length.ToString()); }