예제 #1
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();
        }
예제 #2
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();
        }