Ejemplo n.º 1
0
        public NvidiaGroup()
        {
            if (!NVAPI.IsAvailable)
            {
                return;
            }

            report.AppendLine("NVAPI");
            report.AppendLine();

            NvPhysicalGpuHandle[] handles =
                new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];

            int count;

            if (NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count) != NvStatus.OK)
            {
                return;
            }

            report.Append("Number of GPUs: ");
            report.AppendLine(count.ToString());
            report.AppendLine();

            for (int i = 0; i < count; i++)
            {
                hardware.Add(new NvidiaGPU(i, handles[i]));
            }
        }
Ejemplo n.º 2
0
        public NvidiaGroup()
        {
            if (!NVAPI.IsAvailable)
            {
                return;
            }

            NvPhysicalGpuHandle[] handles =
                new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];

            int count;

            if (NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count) != NvStatus.OK)
            {
                return;
            }

            for (int i = 0; i < count; i++)
            {
                string gpuName;
                NVAPI.NvAPI_GPU_GetFullName(handles[i], out gpuName);
                if (gpuName != null && gpuName.Trim() != "")
                {
                    hardware.Add(new NvidiaGPU(i, handles[i]));
                }
            }
        }
Ejemplo n.º 3
0
        public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle,
                                                     out string name)
        {
            StringBuilder builder = new StringBuilder(SHORT_STRING_MAX);
            NvStatus      status  = _NvAPI_GPU_GetFullName(gpuHandle, builder);

            name = builder.ToString();
            return(status);
        }
Ejemplo n.º 4
0
        public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle)
        {
            try {
                string gpuName;
                if (NVAPI.NvAPI_GPU_GetFullName(handle, out gpuName) == NvStatus.OK)
                {
                    this.name = "NVIDIA " + gpuName.Trim();
                }
                else
                {
                    this.name = "NVIDIA";
                }
                this.icon         = Utilities.EmbeddedResources.GetImage("nvidia.png");
                this.adapterIndex = adapterIndex;
                this.handle       = handle;

                NvGPUThermalSettings settings = GetThermalSettings();
                temperatures = new Sensor[settings.Count];
                for (int i = 0; i < temperatures.Length; i++)
                {
                    NvSensor sensor = settings.Sensor[i];
                    string   name;
                    switch (sensor.Target)
                    {
                    case NvThermalTarget.BOARD: name = "GPU Board"; break;

                    case NvThermalTarget.GPU: name = "GPU Core"; break;

                    case NvThermalTarget.MEMORY: name = "GPU Memory"; break;

                    case NvThermalTarget.POWER_SUPPLY: name = "GPU Power Supply"; break;

                    case NvThermalTarget.UNKNOWN: name = "GPU Unknown"; break;

                    default: name = "GPU"; break;
                    }
                    temperatures[i] = new Sensor(name, i, sensor.DefaultMaxTemp,
                                                 SensorType.Temperature, this);
                    ActivateSensor(temperatures[i]);
                }

                int value;
                if (NVAPI.NvAPI_GPU_GetTachReading != null &&
                    NVAPI.NvAPI_GPU_GetTachReading(handle, out value) == NvStatus.OK)
                {
                    if (value > 0)
                    {
                        fan = new Sensor("GPU", 0, SensorType.Fan, this);
                        ActivateSensor(fan);
                    }
                }

                available = temperatures.Length > 0 || fan != null;
            } catch (Exception e) {
                System.Windows.Forms.MessageBox.Show(e.Message + "\n" + e.StackTrace);
            }
        }
Ejemplo n.º 5
0
        private static string GetName(NvPhysicalGpuHandle handle)
        {
            string gpuName;

            if (NVAPI.NvAPI_GPU_GetFullName(handle, out gpuName) == NvStatus.OK)
            {
                return("NVIDIA " + gpuName.Trim());
            }
            return("NVIDIA");
        }
Ejemplo n.º 6
0
        public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle, out string name)
        {
            StringBuilder builder = new StringBuilder(SHORT_STRING_MAX);
            NvStatus      status;

            if (_NvAPI_GPU_GetFullName != null)
            {
                status = _NvAPI_GPU_GetFullName(gpuHandle, builder);
            }
            else
            {
                status = NvStatus.FUNCTION_NOT_FOUND;
            }
            name = builder.ToString();
            return(status);
        }
Ejemplo n.º 7
0
        public NvidiaNVMLGPU(int adapterIndex, NvPhysicalGpuHandle handle,
                             NvDisplayHandle?displayHandle, ISettings settings, NVML nvml)
            : base(adapterIndex, handle, displayHandle, settings)
        {
            if (nvml == null)
            {
                throw new ArgumentNullException(nameof(nvml));
            }

            this.nvml = nvml;

            if (nvml.Initialised)
            {
                device = nvml.NvmlDeviceGetHandleByIndex(adapterIndex);
                if (device.HasValue)
                {
                    powerUsage = new Sensor("GPU Package", 0, SensorType.Power, this, settings);
                }
            }
        }
Ejemplo n.º 8
0
        public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle,
                         NvDisplayHandle?displayHandle, ISettings settings)
            : base(GetName(handle), new Identifier("nvidiagpu",
                                                   adapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.adapterIndex  = adapterIndex;
            this.handle        = handle;
            this.displayHandle = displayHandle;

            NvGPUThermalSettings thermalSettings = GetThermalSettings();

            temperatures = new Sensor[thermalSettings.Count];
            for (int i = 0; i < temperatures.Length; i++)
            {
                NvSensor sensor = thermalSettings.Sensor[i];
                string   name;
                switch (sensor.Target)
                {
                case NvThermalTarget.BOARD: name = "GPU Board"; break;

                case NvThermalTarget.GPU: name = "GPU Core"; break;

                case NvThermalTarget.MEMORY: name = "GPU Memory"; break;

                case NvThermalTarget.POWER_SUPPLY: name = "GPU Power Supply"; break;

                case NvThermalTarget.UNKNOWN: name = "GPU Unknown"; break;

                default: name = "GPU"; break;
                }
                temperatures[i] = new Sensor(name, i, SensorType.Temperature, this,
                                             new ParameterDescription[0], settings);
                ActivateSensor(temperatures[i]);
            }

            fan = new Sensor("GPU", 0, SensorType.Fan, this, settings);

            clocks    = new Sensor[3];
            clocks[0] = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
            clocks[1] = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
            clocks[2] = new Sensor("GPU Shader", 2, SensorType.Clock, this, settings);
            for (int i = 0; i < clocks.Length; i++)
            {
                ActivateSensor(clocks[i]);
            }

            loads       = new Sensor[4];
            loads[0]    = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
            loads[1]    = new Sensor("GPU Frame Buffer", 1, SensorType.Load, this, settings);
            loads[2]    = new Sensor("GPU Video Engine", 2, SensorType.Load, this, settings);
            loads[3]    = new Sensor("GPU Bus Interface", 3, SensorType.Load, this, settings);
            memoryLoad  = new Sensor("GPU Memory", 4, SensorType.Load, this, settings);
            memoryFree  = new Sensor("GPU Memory Free", 1, SensorType.SmallData, this, settings);
            memoryUsed  = new Sensor("GPU Memory Used", 2, SensorType.SmallData, this, settings);
            memoryAvail = new Sensor("GPU Memory Total", 3, SensorType.SmallData, this, settings);
            control     = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);

            NvGPUCoolerSettings coolerSettings = GetCoolerSettings();

            if (coolerSettings.Count > 0)
            {
                fanControl = new Control(control, settings,
                                         coolerSettings.Cooler[0].DefaultMin,
                                         coolerSettings.Cooler[0].DefaultMax);
                fanControl.ControlModeChanged          += ControlModeChanged;
                fanControl.SoftwareControlValueChanged += SoftwareControlValueChanged;
                ControlModeChanged(fanControl);
                control.Control = fanControl;
            }

            if (NVML.IsInitialized)
            {
                if (NVAPI.NvAPI_GPU_GetBusId != null &&
                    NVAPI.NvAPI_GPU_GetBusId(handle, out uint busId) == NvStatus.OK)
                {
                    if (NVML.NvmlDeviceGetHandleByPciBusId != null &&
                        NVML.NvmlDeviceGetHandleByPciBusId(
                            "0000:" + busId.ToString("X2") + ":00.0", out var result)
                        == NVML.NvmlReturn.Success)
                    {
                        device           = result;
                        power            = new Sensor("GPU Power", 0, SensorType.Power, this, settings);
                        pcieThroughputRx = new Sensor("GPU PCIE Rx", 0,
                                                      SensorType.Throughput, this, settings);
                        pcieThroughputTx = new Sensor("GPU PCIE Tx", 1,
                                                      SensorType.Throughput, this, settings);
                    }
                }
            }

            Update();
        }
Ejemplo n.º 9
0
        public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle,
                         NvDisplayHandle?displayHandle, ISettings settings)
            : base(GetName(handle), new Identifier("nvidiagpu",
                                                   adapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.adapterIndex  = adapterIndex;
            this.handle        = handle;
            this.displayHandle = displayHandle;

            NvGPUThermalSettings thermalSettings = GetThermalSettings();

            temperatures = new Sensor[thermalSettings.Count];
            for (int i = 0; i < temperatures.Length; i++)
            {
                NvSensor sensor = thermalSettings.Sensor[i];
                string   name;
                switch (sensor.Target)
                {
                case NvThermalTarget.BOARD: name = "GPU Board"; break;

                case NvThermalTarget.GPU: name = "GPU Core"; break;

                case NvThermalTarget.MEMORY: name = "GPU Memory"; break;

                case NvThermalTarget.POWER_SUPPLY: name = "GPU Power Supply"; break;

                case NvThermalTarget.UNKNOWN: name = "GPU Unknown"; break;

                default: name = "GPU"; break;
                }
                temperatures[i] = new Sensor(name, i, SensorType.Temperature, this,
                                             new ParameterDescription[0], settings);
                ActivateSensor(temperatures[i]);
            }

            int value;

            if (NVAPI.NvAPI_GPU_GetTachReading != null &&
                NVAPI.NvAPI_GPU_GetTachReading(handle, out value) == NvStatus.OK)
            {
                if (value > 0)
                {
                    fan = new Sensor("GPU", 0, SensorType.Fan, this, settings);
                    ActivateSensor(fan);
                }
            }

            clocks    = new Sensor[3];
            clocks[0] = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
            clocks[1] = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
            clocks[2] = new Sensor("GPU Shader", 2, SensorType.Clock, this, settings);
            for (int i = 0; i < clocks.Length; i++)
            {
                ActivateSensor(clocks[i]);
            }

            loads      = new Sensor[3];
            loads[0]   = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
            loads[1]   = new Sensor("GPU Memory Controller", 1, SensorType.Load, this, settings);
            loads[2]   = new Sensor("GPU Video Engine", 2, SensorType.Load, this, settings);
            memoryLoad = new Sensor("GPU Memory", 3, SensorType.Load, this, settings);

            control = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);

            NvGPUCoolerSettings coolerSettings = GetCoolerSettings();

            if (coolerSettings.Count > 0)
            {
                fanControl = new Control(control, settings,
                                         coolerSettings.Cooler[0].DefaultMin,
                                         coolerSettings.Cooler[0].DefaultMax);
                fanControl.ControlModeChanged          += ControlModeChanged;
                fanControl.SoftwareControlValueChanged += SoftwareControlValueChanged;
                ControlModeChanged(fanControl);
                control.Control = fanControl;
            }
            Update();
        }
Ejemplo n.º 10
0
        public NvidiaGroup(ISettings settings)
        {
            if (!NVAPI.IsAvailable)
            {
                return;
            }

            report.AppendLine("NVAPI");
            report.AppendLine();

            string version;

            if (NVAPI.NvAPI_GetInterfaceVersionString(out version) == NvStatus.OK)
            {
                report.Append("Version: ");
                report.AppendLine(version);
            }

            NvPhysicalGpuHandle[] handles =
                new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
            int count;

            if (NVAPI.NvAPI_EnumPhysicalGPUs == null)
            {
                report.AppendLine("Error: NvAPI_EnumPhysicalGPUs not available");
                report.AppendLine();
                return;
            }
            else
            {
                NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count);
                if (status != NvStatus.OK)
                {
                    report.AppendLine("Status: " + status);
                    report.AppendLine();
                    return;
                }
            }

            IDictionary <NvPhysicalGpuHandle, NvDisplayHandle> displayHandles =
                new Dictionary <NvPhysicalGpuHandle, NvDisplayHandle>();

            if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null &&
                NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null)
            {
                NvStatus status = NvStatus.OK;
                int      i      = 0;
                while (status == NvStatus.OK)
                {
                    NvDisplayHandle displayHandle = new NvDisplayHandle();
                    status = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle);
                    i++;

                    if (status == NvStatus.OK)
                    {
                        NvPhysicalGpuHandle[] handlesFromDisplay =
                            new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
                        uint countFromDisplay;
                        if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle,
                                                                   handlesFromDisplay, out countFromDisplay) == NvStatus.OK)
                        {
                            for (int j = 0; j < countFromDisplay; j++)
                            {
                                if (!displayHandles.ContainsKey(handlesFromDisplay[j]))
                                {
                                    displayHandles.Add(handlesFromDisplay[j], displayHandle);
                                }
                            }
                        }
                    }
                }
            }

            report.Append("Number of GPUs: ");
            report.AppendLine(count.ToString(CultureInfo.InvariantCulture));

            for (int i = 0; i < count; i++)
            {
                NvDisplayHandle displayHandle;
                displayHandles.TryGetValue(handles[i], out displayHandle);
                hardware.Add(new NvidiaGPU(i, handles[i], displayHandle, settings));
            }

            report.AppendLine();
        }
Ejemplo n.º 11
0
        public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle,
                         NvDisplayHandle?displayHandle, ISettings settings, PhysicalGPU physicalGPU = null)
            : base(GetName(handle), new Identifier("nvidiagpu",
                                                   adapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.adapterIndex  = adapterIndex;
            this.handle        = handle;
            this.displayHandle = displayHandle;
            this.physicalGPU   = physicalGPU;

            NvGPUThermalSettings thermalSettings = GetThermalSettings();

            temperatures = new Sensor[thermalSettings.Count];
            for (int i = 0; i < temperatures.Length; i++)
            {
                NvSensor sensor = thermalSettings.Sensor[i];
                string   name;
                switch (sensor.Target)
                {
                case NvThermalTarget.BOARD: name = "GPU Board"; break;

                case NvThermalTarget.GPU: name = "GPU Core"; break;

                case NvThermalTarget.MEMORY: name = "GPU Memory"; break;

                case NvThermalTarget.POWER_SUPPLY: name = "GPU Power Supply"; break;

                case NvThermalTarget.UNKNOWN: name = "GPU Unknown"; break;

                default: name = "GPU"; break;
                }
                temperatures[i] = new Sensor(name, i, SensorType.Temperature, this,
                                             new ParameterDescription[0], settings);
                ActivateSensor(temperatures[i]);
            }

            clocks    = new Sensor[3];
            clocks[0] = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
            clocks[1] = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
            clocks[2] = new Sensor("GPU Shader", 2, SensorType.Clock, this, settings);
            for (int i = 0; i < clocks.Length; i++)
            {
                ActivateSensor(clocks[i]);
            }

            loads                = new Sensor[4];
            loads[0]             = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
            loads[1]             = new Sensor("GPU Frame Buffer", 1, SensorType.Load, this, settings);
            loads[2]             = new Sensor("GPU Video Engine", 2, SensorType.Load, this, settings);
            loads[3]             = new Sensor("GPU Bus Interface", 3, SensorType.Load, this, settings);
            memoryLoad           = new Sensor("GPU Memory", 4, SensorType.Load, this, settings);
            memoryFree           = new Sensor("GPU Memory Free", 1, SensorType.SmallData, this, settings);
            memoryUsed           = new Sensor("GPU Memory Used", 2, SensorType.SmallData, this, settings);
            memoryAvail          = new Sensor("GPU Memory Total", 3, SensorType.SmallData, this, settings);
            memoryUsageDedicated = new Sensor("GPU Memory Dedicated", 4, SensorType.SmallData, this, settings);
            memoryUsageShared    = new Sensor("GPU Memory Shared", 5, SensorType.SmallData, this, settings);
            fan              = new Sensor("GPU Fan", 0, SensorType.Fan, this, settings);
            control          = new Sensor("GPU Fan", 1, SensorType.Control, this, settings);
            voltage          = new Sensor("GPU Voltage", 0, SensorType.Voltage, this, settings);
            powerLimit       = new Sensor("GPU Power Limit", 0, SensorType.Factor, this, settings);
            temperatureLimit = new Sensor("GPU Thermal Limit", 1, SensorType.Factor, this, settings);
            voltageLimit     = new Sensor("GPU Voltage Limit", 2, SensorType.Factor, this, settings);
            power            = new Sensor("GPU Power", 0, SensorType.Power, this, settings);

            NvGPUCoolerSettings coolerSettings = GetCoolerSettings();

            if (coolerSettings.Count > 0)
            {
                fanControl = new Control(control, settings,
                                         coolerSettings.Cooler[0].DefaultMin,
                                         coolerSettings.Cooler[0].DefaultMax);
                fanControl.ControlModeChanged          += ControlModeChanged;
                fanControl.SoftwareControlValueChanged += SoftwareControlValueChanged;
                ControlModeChanged(fanControl);
                control.Control = fanControl;
            }

            try
            {
                if (PerformanceCounterCategory.Exists("GPU Adapter Memory"))
                {
                    var category  = new PerformanceCounterCategory("GPU Adapter Memory");
                    var instances = category.GetInstanceNames();

                    if (instances.Any())
                    {
                        long maxRawValue = 0;
                        int  maxIndex    = 0;
                        for (int i = 0; i < instances.Length; i++)
                        {
                            try
                            {
                                var currentPerfCounter = new PerformanceCounter("GPU Adapter Memory", "Dedicated Usage", instances[i]);

                                if (currentPerfCounter.RawValue > maxRawValue)
                                {
                                    maxRawValue = currentPerfCounter.RawValue;
                                    maxIndex    = i;
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Logger.Error(ex, $"Error while creating performance counter with instance {i}.");
                            }
                        }

                        dedicatedVramUsagePerformCounter = new PerformanceCounter("GPU Adapter Memory", "Dedicated Usage", instances[maxIndex]);
                        sharedVramUsagePerformCounter    = new PerformanceCounter("GPU Adapter Memory", "Shared Usage", instances[maxIndex]);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex, "Error while creating GPU memory performance counter.");
            }


            if (NVML.IsInitialized)
            {
                if (NVAPI.NvAPI_GPU_GetBusId != null &&
                    NVAPI.NvAPI_GPU_GetBusId(handle, out uint busId) == NvStatus.OK)
                {
                    if (NVML.NvmlDeviceGetHandleByPciBusId != null &&
                        NVML.NvmlDeviceGetHandleByPciBusId(
                            "0000:" + busId.ToString("X2") + ":00.0", out var result)
                        == NVML.NvmlReturn.Success)
                    {
                        device           = result;
                        pcieThroughputRx = new Sensor("GPU PCIE Rx", 0,
                                                      SensorType.Throughput, this, settings);
                        pcieThroughputTx = new Sensor("GPU PCIE Tx", 1,
                                                      SensorType.Throughput, this, settings);
                    }
                }
            }

            Update();
        }
Ejemplo n.º 12
0
        public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle,
                         NvDisplayHandle?displayHandle, ISettings settings)
        {
            string gpuName;

            if (NVAPI.NvAPI_GPU_GetFullName(handle, out gpuName) == NvStatus.OK)
            {
                this.name = "NVIDIA " + gpuName.Trim();
            }
            else
            {
                this.name = "NVIDIA";
            }
            this.adapterIndex  = adapterIndex;
            this.handle        = handle;
            this.displayHandle = displayHandle;

            NvGPUThermalSettings thermalSettings = GetThermalSettings();

            temperatures = new Sensor[thermalSettings.Count];
            for (int i = 0; i < temperatures.Length; i++)
            {
                NvSensor sensor = thermalSettings.Sensor[i];
                string   name;
                switch (sensor.Target)
                {
                case NvThermalTarget.BOARD: name = "GPU Board"; break;

                case NvThermalTarget.GPU: name = "GPU Core"; break;

                case NvThermalTarget.MEMORY: name = "GPU Memory"; break;

                case NvThermalTarget.POWER_SUPPLY: name = "GPU Power Supply"; break;

                case NvThermalTarget.UNKNOWN: name = "GPU Unknown"; break;

                default: name = "GPU"; break;
                }
                temperatures[i] = new Sensor(name, i, SensorType.Temperature, this,
                                             new ParameterDescription[0], settings);
                ActivateSensor(temperatures[i]);
            }

            int value;

            if (NVAPI.NvAPI_GPU_GetTachReading != null &&
                NVAPI.NvAPI_GPU_GetTachReading(handle, out value) == NvStatus.OK)
            {
                if (value > 0)
                {
                    fan = new Sensor("GPU", 0, SensorType.Fan, this, settings);
                    ActivateSensor(fan);
                }
            }

            clocks    = new Sensor[3];
            clocks[0] = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
            clocks[1] = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
            clocks[2] = new Sensor("GPU Shader", 2, SensorType.Clock, this, settings);
            for (int i = 0; i < clocks.Length; i++)
            {
                ActivateSensor(clocks[i]);
            }

            loads      = new Sensor[3];
            loads[0]   = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
            loads[1]   = new Sensor("GPU Memory Controller", 1, SensorType.Load, this, settings);
            loads[2]   = new Sensor("GPU Video Engine", 2, SensorType.Load, this, settings);
            memoryLoad = new Sensor("GPU Memory", 3, SensorType.Load, this, settings);

            control = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);
        }