Example #1
0
        private NvGPUThermalSettings GetThermalSettings()
        {
            NvGPUThermalSettings settings = new NvGPUThermalSettings();

            settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER;
            settings.Count   = NVAPI.MAX_THERMAL_SENSORS_PER_GPU;
            settings.Sensor  = new NvSensor[NVAPI.MAX_THERMAL_SENSORS_PER_GPU];
            if (!(NVAPI.NvAPI_GPU_GetThermalSettings != null && NVAPI.NvAPI_GPU_GetThermalSettings(handle, (int)NvThermalTarget.ALL, ref settings) == NvStatus.OK))
            {
                settings.Count = 0;
            }
            return(settings);
        }
Example #2
0
        private string GetReportCard(int adapterIndex, NvPhysicalGpuHandle handle, NvDisplayHandle displayHandle)
        {
            StringBuilder r = new StringBuilder();

            r.AppendLine("Nvidia GPU");
            r.AppendLine();
            string tmp;

            if (NVAPI.NvAPI_GPU_GetFullName(handle, out tmp) == NvStatus.OK)
            {
                tmp = "NVIDIA " + tmp.Trim();
            }
            else
            {
                tmp = "NVIDIA GPU name not found";
            }
            r.AppendFormat("Name: {0}{1}", tmp, Environment.NewLine);
            r.AppendFormat("Index: {0}{1}", adapterIndex, Environment.NewLine);
            if (NVAPI.NvAPI_GetDisplayDriverVersion != null)
            {
                NvDisplayDriverVersion driverVersion = new NvDisplayDriverVersion();
                driverVersion.Version = NVAPI.DISPLAY_DRIVER_VERSION_VER;
                if (NVAPI.NvAPI_GetDisplayDriverVersion(displayHandle, ref driverVersion) == NvStatus.OK)
                {
                    r.Append("Driver Version: ");
                    r.Append(driverVersion.DriverVersion / 100);
                    r.Append(".");
                    r.Append((driverVersion.DriverVersion % 100).ToString("00", CultureInfo.InvariantCulture));
                    r.AppendLine();
                    r.Append("Driver Branch: ");
                    r.AppendLine(driverVersion.BuildBranch);
                }
            }
            r.AppendLine();
            if (NVAPI.NvAPI_GPU_GetPCIIdentifiers != null)
            {
                uint     deviceId, subSystemId, revisionId, extDeviceId;
                NvStatus status = NVAPI.NvAPI_GPU_GetPCIIdentifiers(handle, out deviceId, out subSystemId, out revisionId, out extDeviceId);
                if (status == NvStatus.OK)
                {
                    r.Append("DeviceID: 0x");
                    r.AppendLine(deviceId.ToString("X", CultureInfo.InvariantCulture));
                    r.Append("SubSystemID: 0x");
                    r.AppendLine(subSystemId.ToString("X", CultureInfo.InvariantCulture));
                    r.Append("RevisionID: 0x");
                    r.AppendLine(revisionId.ToString("X", CultureInfo.InvariantCulture));
                    r.Append("ExtDeviceID: 0x");
                    r.AppendLine(extDeviceId.ToString("X", CultureInfo.InvariantCulture));
                    r.AppendLine();
                }
            }
            if (NVAPI.NvAPI_GPU_GetThermalSettings != null)
            {
                NvGPUThermalSettings settings = new NvGPUThermalSettings();
                settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER;
                settings.Count   = NVAPI.MAX_THERMAL_SENSORS_PER_GPU;
                settings.Sensor  = new NvSensor[NVAPI.MAX_THERMAL_SENSORS_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetThermalSettings(handle, (int)NvThermalTarget.ALL, ref settings);
                r.AppendLine("Thermal Settings");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < settings.Count; i++)
                    {
                        r.AppendFormat(" Sensor[{0}].Controller: {1}{2}", i, settings.Sensor[i].Controller, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].DefaultMinTemp: {1}{2}", i, settings.Sensor[i].DefaultMinTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].DefaultMaxTemp: {1}{2}", i, settings.Sensor[i].DefaultMaxTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].CurrentTemp: {1}{2}", i, settings.Sensor[i].CurrentTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].Target: {1}{2}", i, settings.Sensor[i].Target, Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }
            if (NVAPI.NvAPI_GPU_GetAllClocks != null)
            {
                NvClocks allClocks = new NvClocks();
                allClocks.Version = NVAPI.GPU_CLOCKS_VER;
                allClocks.Clock   = new uint[NVAPI.MAX_CLOCKS_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetAllClocks(handle, ref allClocks);
                r.AppendLine("Clocks");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < allClocks.Clock.Length; i++)
                    {
                        if (allClocks.Clock[i] > 0)
                        {
                            r.AppendFormat(" Clock[{0}]: {1}{2}", i, allClocks.Clock[i], Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetTachReading != null)
            {
                int      tachValue;
                NvStatus status = NVAPI.NvAPI_GPU_GetTachReading(handle, out tachValue);

                r.AppendLine("Tachometer");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    r.AppendFormat(" Value: {0}{1}", tachValue, Environment.NewLine);
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }
            if (NVAPI.NvAPI_GPU_GetPStates != null)
            {
                NvPStates states = new NvPStates();
                states.Version = NVAPI.GPU_PSTATES_VER;
                states.PStates = new NvPState[NVAPI.MAX_PSTATES_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetPStates(handle, ref states);
                r.AppendLine("P-States");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < states.PStates.Length; i++)
                    {
                        if (states.PStates[i].Present)
                        {
                            r.AppendFormat(" Percentage[{0}]: {1}{2}", i, states.PStates[i].Percentage, Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }
            if (NVAPI.NvAPI_GPU_GetUsages != null)
            {
                NvUsages usages = new NvUsages();
                usages.Version = NVAPI.GPU_USAGES_VER;
                usages.Usage   = new uint[NVAPI.MAX_USAGES_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetUsages(handle, ref usages);
                r.AppendLine("Usages");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < usages.Usage.Length; i++)
                    {
                        if (usages.Usage[i] > 0)
                        {
                            r.AppendFormat(" Usage[{0}]: {1}{2}", i, usages.Usage[i], Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }
            if (NVAPI.NvAPI_GPU_GetCoolerSettings != null)
            {
                NvGPUCoolerSettings settings = new NvGPUCoolerSettings();
                settings.Version = NVAPI.GPU_COOLER_SETTINGS_VER;
                settings.Cooler  = new NvCooler[NVAPI.MAX_COOLER_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetCoolerSettings(handle, 0, ref settings);
                r.AppendLine("Cooler Settings");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < settings.Count; i++)
                    {
                        r.AppendFormat(" Cooler[{0}].Type: {1}{2}", i, settings.Cooler[i].Type, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Controller: {1}{2}", i, settings.Cooler[i].Controller, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultMin: {1}{2}", i, settings.Cooler[i].DefaultMin, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultMax: {1}{2}", i, settings.Cooler[i].DefaultMax, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentMin: {1}{2}", i, settings.Cooler[i].CurrentMin, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentMax: {1}{2}", i, settings.Cooler[i].CurrentMax, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentLevel: {1}{2}", i, settings.Cooler[i].CurrentLevel, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultPolicy: {1}{2}", i, settings.Cooler[i].DefaultPolicy, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentPolicy: {1}{2}", i, settings.Cooler[i].CurrentPolicy, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Target: {1}{2}", i, settings.Cooler[i].Target, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].ControlType: {1}{2}", i, settings.Cooler[i].ControlType, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Active: {1}{2}", i, settings.Cooler[i].Active, Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }
            if (NVAPI.NvAPI_GPU_GetMemoryInfo != null)
            {
                NvMemoryInfo memoryInfo = new NvMemoryInfo();
                memoryInfo.Version = NVAPI.GPU_MEMORY_INFO_VER;
                memoryInfo.Values  = new uint[NVAPI.MAX_MEMORY_VALUES_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetMemoryInfo(displayHandle, ref memoryInfo);
                r.AppendLine("Memory Info");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < memoryInfo.Values.Length; i++)
                    {
                        r.AppendFormat(" Value[{0}]: {1}{2}", i, memoryInfo.Values[i], Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }
            return(r.ToString());
        }
Example #3
0
        private void UpdateNvi()
        {
            //Clock GPU, MEM
            uint[] values = GetClocks();
            int    GPUClock = 0; int MemClock = 0;

            if (values != null)
            {
                if (values[30] != 0)
                {
                    GPUClock = (int)values[30] / 2000;
                    MemClock = (int)values[8] / 2000;
                }
                else
                {
                    GPUClock = (int)values[0] / 1000;
                    MemClock = (int)values[8] / 1000;
                }
            }
            GPUParams[0].ParCollect.Add(GPUClock);
            GPUParams[1].ParCollect.Add(MemClock);
            //Load GPU, MEM
            NvPStates states = new NvPStates();

            states.Version = NVAPI.GPU_PSTATES_VER;
            states.PStates = new NvPState[NVAPI.MAX_PSTATES_PER_GPU];
            int GPULoad = 0; int MemLoad = 0;

            if (NVAPI.NvAPI_GPU_GetPStates != null && NVAPI.NvAPI_GPU_GetPStates(handle, ref states) == NvStatus.OK)
            {
                if (states.PStates[0].Present)
                {
                    GPULoad = states.PStates[0].Percentage;
                    MemLoad = states.PStates[1].Percentage;
                }
            }
            GPUParams[2].ParCollect.Add(GPULoad);
            GPUParams[3].ParCollect.Add(MemLoad);
            //Temperature GPU
            NvGPUThermalSettings settings = GetThermalSettings();
            int GPUTemp = 0;

            for (int i = 0; i < settings.Count; i++)
            {
                if (settings.Sensor[i].CurrentTemp > 0)
                {
                    GPUTemp = (int)settings.Sensor[i].CurrentTemp;
                }
            }
            GPUParams[4].ParCollect.Add(GPUTemp);
            //Fan speed %, RPM
            NvGPUCoolerSettings coolerSettings = GetCoolerSettings();
            int FANprecentage = 0; int FANrpm = 0;

            if (coolerSettings.Count > 0)
            {
                FANprecentage = coolerSettings.Cooler[0].CurrentLevel;
            }
            GPUParams[5].ParCollect.Add(FANprecentage);
            GPUParams[6].ParCollect.Add(FANrpm);
        }
Example #4
0
        private void UpdateCurr()
        {
            NvGPUThermalSettings settings = GetThermalSettings();

            for (int i = 0; i < settings.Count; i++)
            {
                if (settings.Sensor[i].CurrentTemp > 0)
                {
                    gpucurr.GPUTemp = settings.Sensor[i].CurrentTemp;
                }
                else
                {
                    gpucurr.GPUTemp = 0;
                }
            }

            uint[] values = GetClocks();
            if (values != null)
            {
                gpucurr.CoreClock   = (values[0] / 1000);
                gpucurr.MemoryClock = (values[8] / 1000);
                if (values[30] != 0)
                {
                    //GPU Clock values[30]/2 GPU Memory Clock values[8]/2
                    gpucurr.CoreClock   = (values[30] / 2000);
                    gpucurr.MemoryClock = (values[8] / 2000);
                }
            }
            else
            {
                gpucurr.CoreClock   = 0;
                gpucurr.MemoryClock = 0;
            }

            NvPStates states = new NvPStates();

            states.Version = NVAPI.GPU_PSTATES_VER;
            states.PStates = new NvPState[NVAPI.MAX_PSTATES_PER_GPU];
            if (NVAPI.NvAPI_GPU_GetPStates != null && NVAPI.NvAPI_GPU_GetPStates(handle, ref states) == NvStatus.OK)
            {
                if (states.PStates[0].Present)
                {
                    //states.PStates[0] GPU Load states.PStates[1] Memory controller load
                    gpucurr.GPULoad     = (uint)states.PStates[0].Percentage;
                    gpucurr.MemCtrlLoad = (uint)states.PStates[1].Percentage;
                }
                else
                {
                    gpucurr.GPULoad     = 0;
                    gpucurr.MemCtrlLoad = 0;
                }
            }
            else
            {
                NvUsages usages = new NvUsages();
                usages.Version = NVAPI.GPU_USAGES_VER;
                usages.Usage   = new uint[NVAPI.MAX_USAGES_PER_GPU];
                if (NVAPI.NvAPI_GPU_GetUsages != null && NVAPI.NvAPI_GPU_GetUsages(handle, ref usages) == NvStatus.OK)
                {
                }
            }

            NvGPUCoolerSettings coolerSettings = GetCoolerSettings();

            if (coolerSettings.Count > 0)
            {
                gpucurr.FanLoad = (uint)coolerSettings.Cooler[0].CurrentLevel;
            }
            else
            {
                gpucurr.FanLoad = 0;
            }

            gpucurr.FanRPM = 0;

            NvMemoryInfo memoryInfo = new NvMemoryInfo();

            memoryInfo.Version = NVAPI.GPU_MEMORY_INFO_VER;
            memoryInfo.Values  = new uint[NVAPI.MAX_MEMORY_VALUES_PER_GPU];
            if (NVAPI.NvAPI_GPU_GetMemoryInfo != null && NVAPI.NvAPI_GPU_GetMemoryInfo(displayHandle, ref memoryInfo) == NvStatus.OK)
            {
                uint  totalMemory = memoryInfo.Values[0];
                uint  freeMemory  = memoryInfo.Values[4];
                float usedMemory  = Math.Max(totalMemory - freeMemory, 0);
            }
        }