Skip to content

Commit

Permalink
✨ Add nvapi thermal settings. (Not ultra useful?)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexawyz committed Apr 16, 2024
1 parent 82ffd66 commit 6dec35d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Exo.Devices.NVidia/NVidiaGpuDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ ILogger<NVidiaGpuDriver> logger
}
}

var thermalSensors = new NvApi.Gpu.ThermalSensor[3];
int sensorCount = foundGpu.GetThermalSettings(thermalSensors);

return new
(
new DriverCreationResult<SystemDevicePath>
Expand Down
63 changes: 63 additions & 0 deletions Exo.Devices.NVidia/NvApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static class Gpu
public static readonly delegate* unmanaged[Cdecl]<nint, NvApi.Gpu.Client.IlluminationZoneControlQuery*, uint> ClientIllumZonesGetControl = (delegate* unmanaged[Cdecl]<nint, NvApi.Gpu.Client.IlluminationZoneControlQuery*, uint>)QueryInterface(0x3dbf5764);
public static readonly delegate* unmanaged[Cdecl]<nint, NvApi.Gpu.Client.IlluminationZoneControlQuery*, uint> ClientIllumZonesSetControl = (delegate* unmanaged[Cdecl]<nint, NvApi.Gpu.Client.IlluminationZoneControlQuery*, uint>)QueryInterface(0x197d065e);
public static readonly delegate* unmanaged[Cdecl]<nint, NvApi.Gpu.Client.UtilizationPeriodicCallbackSettings*, uint> ClientRegisterForUtilizationSampleUpdates = (delegate* unmanaged[Cdecl]<nint, NvApi.Gpu.Client.UtilizationPeriodicCallbackSettings*, uint>)QueryInterface(0xadeeaf67);
public static readonly delegate* unmanaged[Cdecl]<nint, uint, NvApi.Gpu.ThermalSettings*, uint> GetThermalSettings = (delegate* unmanaged[Cdecl]<nint, uint, NvApi.Gpu.ThermalSettings*, uint>)QueryInterface(0xe3640a56);
}

public static class System
Expand Down Expand Up @@ -285,6 +286,59 @@ internal struct IlluminationQuery
public uint Value;
}

public enum ThermalController
{
None = 0,
GpuInternal,
Adm1032,
Max6649,
Max1617,
Lm99,
Lm89,
Lm64,
Adt7473,
SBMAX6649,
VideoBiosEvent,
Os,
Unknown = -1,
}

public enum ThermalTarget
{
None = 0,
Gpu = 1,
Memory = 2,
PowerSupply = 4,
Board = 8,
VisualComputingDeviceBoard = 9,
VisualComputingDeviceInlet = 10,
VisualComputingDeviceOutlet = 11,
All = 15,
Unknown = -1,
}

internal struct ThermalSensor
{
public ThermalController Controller;
public int DefaultMinTemp;
public int DefaultMaxTemp;
public int CurrentTemp;
public ThermalTarget Target;
}

[InlineArray(3)]
internal struct ThermalSensorArray
{
private ThermalSensor _element0;
}

internal struct ThermalSettings
{
public uint Version;
public uint Count;
public ThermalSensorArray Sensors;
}

public static class Client
{
public enum IlluminationDeviceType : int
Expand Down Expand Up @@ -989,6 +1043,15 @@ public unsafe void SetIlluminationZoneControls(Gpu.Client.IlluminationZoneContro
ValidateResult(Functions.Gpu.ClientIllumZonesSetControl(_handle, &query));
}

public unsafe int GetThermalSettings(Span<Gpu.ThermalSensor> thermalSensors)
{
var thermalSettings = new Gpu.ThermalSettings { Version = StructVersion<Gpu.ThermalSettings>(2) };
ValidateResult(Functions.Gpu.GetThermalSettings(_handle, 15, &thermalSettings));
if (thermalSettings.Count > 3) throw new InvalidOperationException("Invalid thermal reading count.");
((ReadOnlySpan<Gpu.ThermalSensor>)thermalSettings.Sensors).CopyTo(thermalSensors);
return (int)thermalSettings.Count;
}

[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
private static unsafe void OnUtilizationUpdate(nint physicalGpuHandle, Gpu.Client.CallbackUtilizationData* data)
{
Expand Down

0 comments on commit 6dec35d

Please sign in to comment.