Skip to content

Commit

Permalink
🐛 NVAPI: Add more checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexawyz committed Sep 16, 2024
1 parent 6e523c8 commit 8ad64ec
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Exo/Devices/Exo.Devices.NVidia/NvApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ internal sealed class NvApi

public static bool HasI2c => DriverVersion >= 85_00;
public static bool HasThermals => DriverVersion >= 85_00;
public static bool HasIllumination => DriverVersion >= 400_00;
public static bool HasClockFrequencies => DriverVersion >= 285_00;
public static bool HasIllumination => DriverVersion >= 400_00;
public static bool HasUtilizationSamples => DriverVersion >= 455_00;

static NvApi()
Expand Down Expand Up @@ -1281,6 +1281,7 @@ public unsafe int GetThermalSettings(Span<Gpu.ThermalSensor> thermalSensors)

public unsafe Gpu.CoolerInformation GetCoolerSettings(Gpu.CoolerTarget coolerTarget)
{
if (Functions.Gpu.GetCoolerSettings == null) throw new NotSupportedException();
var coolerSettings = new Gpu.CoolerSettings { Version = StructVersion<Gpu.CoolerSettings>(Gpu.CoolerSettingsVersion) };
ValidateResult(Functions.Gpu.GetCoolerSettings(_handle, (uint)coolerTarget, &coolerSettings));
if (coolerSettings.Count != 1) throw new InvalidOperationException("Invalid cooler count.");
Expand All @@ -1289,6 +1290,7 @@ public unsafe Gpu.CoolerInformation GetCoolerSettings(Gpu.CoolerTarget coolerTar

public unsafe int GetCoolerSettings(Span<Gpu.CoolerInformation> coolers)
{
if (Functions.Gpu.GetCoolerSettings == null) throw new NotSupportedException();
var coolerSettings = new Gpu.CoolerSettings { Version = StructVersion<Gpu.CoolerSettings>(Gpu.CoolerSettingsVersion) };
ValidateResult(Functions.Gpu.GetCoolerSettings(_handle, (uint)Gpu.CoolerTarget.All, &coolerSettings));
if (coolerSettings.Count > 3) throw new InvalidOperationException("Invalid cooler count.");
Expand All @@ -1315,13 +1317,15 @@ public unsafe int GetClockFrequencies(Gpu.ClockType clockType, Span<GpuClockFreq

public unsafe uint GetTachReading()
{
if (Functions.Gpu.GetTachReading == null) throw new NotSupportedException();
uint reading;
ValidateResult(Functions.Gpu.GetTachReading(_handle, &reading));
return reading;
}

public unsafe int GetFanCoolersStatus(Span<GpuFanStatus> fanCoolers)
{
if (Functions.Gpu.ClientFanCoolersGetStatus == null) return 0;
var status = new Gpu.Client.FanCoolersStatus { Version = StructVersion<Gpu.Client.FanCoolersStatus>(1) };
ValidateResult(Functions.Gpu.ClientFanCoolersGetStatus(_handle, &status));
if (status.Count > 32) throw new InvalidOperationException("Invalid fan cooler count.");
Expand Down

0 comments on commit 8ad64ec

Please sign in to comment.