예제 #1
0
        public static List <UserGPU> GetAtiGPUInformation()
        {
            var resultList = new List <UserGPU>();

            try
            {
                Computer thisComputer = new Computer();
                thisComputer.GPUEnabled = true;
                thisComputer.Open();
                foreach (var hardwareItem in thisComputer.Hardware)
                {
                    if (hardwareItem.HardwareType == HardwareType.GpuAti)
                    {
                        var gpu = new UserGPU();
                        gpu.ID   = "-1";
                        gpu.Name = hardwareItem.Name;

                        var sensorList = hardwareItem.Sensors;

                        foreach (var sensor in sensorList)
                        {
                            switch (sensor.SensorType)
                            {
                            case SensorType.Control:
                                if (sensor.Name.Equals("GPU Fan"))
                                {
                                    gpu.FanSpeed = (int)sensor.Value;
                                }
                                break;

                            case SensorType.Temperature:
                                if (sensor.Name.Equals("GPU Core"))
                                {
                                    gpu.Temperature = (int)sensor.Value;
                                }
                                break;

                            case SensorType.Load:
                                if (sensor.Name.Equals("GPU Core"))
                                {
                                    gpu.MemoryUsage = (float)sensor.Value;
                                }
                                break;
                            }
                        }
                        resultList.Add(gpu);
                    }
                }
                thisComputer.Close();
            }
            catch (Exception ex)
            {
                EventLogger.WriteLog("READ ATI GPU ERROR", ex.ToString());
            }
            return(resultList);
        }
예제 #2
0
 private void UpdateGPUMenu(UserGPU gpu, System.Windows.Forms.MenuItem menu)
 {
     menu.MenuItems.Add("Temperature: " + gpu.Temperature.ToString() + "°C");
     menu.MenuItems.Add("Fan Speed: " + gpu.FanSpeed.ToString() + "%");
     menu.MenuItems.Add("Used Memory: " + ((gpu.MemoryUsage.ToString().Length >= 4) ? gpu.MemoryUsage.ToString().Substring(0, 4) + "%" : gpu.MemoryUsage.ToString() + "%"));
     if (gpu.Name.ToLower().Contains("nvidia"))
     {
         menu.MenuItems.Add("Power Usage: " + gpu.PowerUsage.ToString() + "W");
         menu.MenuItems.Add("Power Limit: " + gpu.PowerLimit.ToString() + "W");
         menu.MenuItems.Add("Memory Total: " + gpu.MemoryTotal.ToString() + "MB");
         menu.MenuItems.Add("Utilization: " + gpu.MemoryUtilization.ToString() + "%");
     }
 }
예제 #3
0
        public static List <UserGPU> GetNvidiaGPUInformation()
        {
            var gpuList    = GetAllNvidiaGPUName();
            var resultList = new List <UserGPU>();

            if (gpuList != null)
            {
                var infoProc   = new ProcessInvoker(@"C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe");
                var infoResult = infoProc.GetProcessOutput();
                //The start of GPU information row in the table
                int currentRow = 8;
                try
                {
                    foreach (var gpu in gpuList)
                    {
                        //GPU 0: GeForce GTX 750 Ti(UUID: GPU - 73c10860 - 789a - f96f - 6a61 - 023499306183)
                        var gpuIdList = gpu.Replace(")", " ").Replace("(", " ").Replace("UUID", "").Split(':');
                        var gpuName   = gpuIdList[1].Trim();
                        var gpuID     = gpuIdList[2].Trim();
                        //Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
                        //29%   40C    P8     1W /  38W |    298MiB /  2048MiB |      0%      Default
                        // 0    1       2      3     4          5       6               7       8
                        var     gpuInfoList = infoResult[currentRow].Replace("|", " ").Replace("/", " ").Split(' ').Where(item => !item.Equals("")).ToList();
                        UserGPU thisGPU     = new UserGPU
                        {
                            ID                = "-1",
                            Name              = "NVIDIA " + gpuName,
                            FanSpeed          = Regex.Match(gpuInfoList[0], @"\d+").Value.Length <= 0 ? -1 : int.Parse(Regex.Match(gpuInfoList[0], @"\d+").Value),
                            Temperature       = Regex.Match(gpuInfoList[1], @"\d+").Value.Length <= 0 ? -1 : int.Parse(Regex.Match(gpuInfoList[1], @"\d+").Value),
                            PowerUsage        = Regex.Match(gpuInfoList[3], @"\d+").Value.Length <= 0 ? -1 : int.Parse(Regex.Match(gpuInfoList[3], @"\d+").Value),
                            PowerLimit        = Regex.Match(gpuInfoList[4], @"\d+").Value.Length <= 0 ? -1 : int.Parse(Regex.Match(gpuInfoList[4], @"\d+").Value),
                            MemoryUsage       = Regex.Match(gpuInfoList[5], @"\d+").Value.Length <= 0 || Regex.Match(gpuInfoList[6], @"\d+").Value.Length <= 0 ? -1 : 100 * float.Parse(Regex.Match(gpuInfoList[5], @"\d+").Value) / float.Parse(Regex.Match(gpuInfoList[6], @"\d+").Value),
                            MemoryTotal       = Regex.Match(gpuInfoList[6], @"\d+").Value.Length <= 0 ? -1 : int.Parse(Regex.Match(gpuInfoList[6], @"\d+").Value),
                            MemoryUtilization = Regex.Match(gpuInfoList[7], @"\d+").Value.Length <= 0 ? -1 : int.Parse(Regex.Match(gpuInfoList[7], @"\d+").Value)
                        };

                        resultList.Add(thisGPU);
                        //Next row
                        currentRow += 3;
                    }
                }

                catch (Exception ex)
                {
                    EventLogger.WriteLog("READ NVIDIA GPU ERROR", ex.ToString());
                    return(resultList);
                }
            }
            return(resultList);
        }
예제 #4
0
        private void UpdateGPUInformation(UserGPU gpu)
        {
            GPUImage.Source     = gpu.Name.ToLower().Contains("nvidia") ? new BitmapImage(new Uri(@"Resources\nvidia.jpg", UriKind.Relative)) : new BitmapImage(new Uri(@"Resources\amd.png", UriKind.Relative));
            GPUImage.Visibility = Visibility.Visible;

            GPUNameTextBlock.Text   = gpu.Name;
            GPUNameLabel.Foreground = new SolidColorBrush(Colors.Black);

            GPUTemperatureTextBlock.Text = gpu.Temperature == -1? "Error" : gpu.Temperature.ToString() + "°C";
            TemperatureLabel.Foreground  = gpu.Temperature == -1? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);

            FanSpeedTextBlock.Text   = gpu.FanSpeed == -1? "Error" : gpu.FanSpeed.ToString() + "%";
            FanSpeedLabel.Foreground = gpu.FanSpeed == -1? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);

            MemoryUsageLabel.Foreground = gpu.MemoryUsage == -1? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);
            if (gpu.Name.ToLower().Contains("nvidia"))
            {
                MemoryUsageTextBlock.Text  = gpu.MemoryUsage == -1? "Error" : (gpu.MemoryUsage.ToString().Length >= 4) ? gpu.MemoryUsage.ToString().Substring(0, 4) + "%" : gpu.MemoryUsage.ToString() + "%";
                PowerUsageTextBlock.Text   = gpu.PowerUsage == -1? "Error" : gpu.PowerUsage.ToString() + "W";
                PowerUsageLabel.Foreground = gpu.PowerUsage == -1? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);

                PowerLimitTextBlock.Text   = gpu.PowerLimit == -1? "Error" : gpu.PowerLimit.ToString() + "W";
                PowerLimitLabel.Foreground = gpu.PowerLimit == -1? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);

                MemoryTotalTextBlock.Text   = gpu.MemoryTotal == -1? "Error" : gpu.MemoryTotal.ToString() + "MB";
                MemoryTotalLabel.Foreground = gpu.MemoryTotal == -1 ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);

                UtilizationTextBlock.Text   = gpu.MemoryUtilization == -1? "Error" : gpu.MemoryUtilization.ToString() + "%";
                UtilizationLabel.Foreground = gpu.MemoryUtilization == -1 ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);
            }
            else
            {
                MemoryUsageTextBlock.Text = (gpu.MemoryUsage.ToString().Length >= 4)? gpu.MemoryUsage.ToString().Substring(0, 4) + "%" : gpu.MemoryUsage.ToString() + "%";

                PowerUsageTextBlock.Text   = "N/A";
                PowerUsageLabel.Foreground = new SolidColorBrush(Colors.Gray);

                PowerLimitTextBlock.Text   = "N/A";
                PowerLimitLabel.Foreground = new SolidColorBrush(Colors.Gray);

                MemoryTotalTextBlock.Text   = "N/A";
                MemoryTotalLabel.Foreground = new SolidColorBrush(Colors.Gray);

                UtilizationTextBlock.Text   = "N/A";
                UtilizationLabel.Foreground = new SolidColorBrush(Colors.Gray);
            }
        }