Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/NHM.DeviceMonitoring/DeviceMonitorNVIDIA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace NHM.DeviceMonitoring
{
internal class DeviceMonitorNVIDIA : DeviceMonitor, IFanSpeedRPM, IGetFanSpeedPercentage, ILoad, IPowerUsage, ITemp, ITDP, IMemoryTimings, IMemControllerLoad, ISpecialTemps, ICoreClock, IMemoryClock, ICoreClockSet, IMemoryClockSet, IMemoryClockRange, ICoreClockRange, ISetFanSpeedPercentage, IResetFanSpeed, ITDPLimits
internal class DeviceMonitorNVIDIA : DeviceMonitor, IFanSpeedRPM, IGetFanSpeedPercentage, ILoad, IPowerUsage, ITemp, ITDP, IMemoryTimings, IMemControllerLoad, ISpecialTemps, ICoreClock, IMemoryClock, ICoreClockSet, IMemoryClockSet, IMemoryClockRange, ICoreClockRange, ISetFanSpeedPercentage, IResetFanSpeed, ITDPLimits, IMemoryClockDelta
{
private const int RET_OK = 0;
public static object _lock = new object();
Expand Down Expand Up @@ -285,18 +285,31 @@ public int MemoryClock
return -1;
}
}

public int MemoryClockDelta
{
get
{
int memoryClockDelta = 0;
int ok = NVIDIA_MON.nhm_nvidia_device_get_memory_clocks_delta(BusID, ref memoryClockDelta);
if (ok == RET_OK) return memoryClockDelta;
Logger.InfoDelayed(LogTag, $"nhm_nvidia_device_get_memory_clocks_delta failed with error code {ok}", _delayedLogging);
return -(1);
}
}

public void PrintMemoryTimings()
{
NVIDIA_MON.nhm_nvidia_device_print_memory_timings(BusID);
}

public bool SetCoreClock(int coreClock)
{
return NVIDIA_MON.nhm_nvidia_device_set_core_clocks(BusID, coreClock) == 0 ? true : false;
return NVIDIA_MON.nhm_nvidia_device_set_core_clocks(BusID, coreClock, false) == 0 ? true : false;
}
public bool SetMemoryClock(int memoryClock)
{
return NVIDIA_MON.nhm_nvidia_device_set_memory_clocks(BusID, memoryClock) == 0 ? true : false;
return NVIDIA_MON.nhm_nvidia_device_set_memory_clocks(BusID, memoryClock, false) == 0 ? true : false;
}
public (bool ok, uint min, uint max, uint def) GetTDPLimits()
{
Expand All @@ -316,7 +329,7 @@ public bool SetMemoryClock(int memoryClock)
int min = 0;
int max = 0;
int def = 0;
var ok = NVIDIA_MON.nhm_nvidia_device_get_core_clocks_min_max_default(BusID, ref min, ref max, ref def);
var ok = NVIDIA_MON.nhm_nvidia_device_get_core_clocks_min_max_default(BusID, ref min, ref max, ref def, false);
if (ok == RET_OK) return (true, min, max, def);
Logger.InfoDelayed(LogTag, $"nhm_nvidia_device_get_core_clocks_min_max_default failed with error code {ok}", _delayedLogging);
return (false, 0, 0, 0);
Expand All @@ -330,7 +343,7 @@ public bool SetMemoryClock(int memoryClock)
int min = 0;
int max = 0;
int def = 0;
var ok = NVIDIA_MON.nhm_nvidia_device_get_memory_clocks_min_max_default(BusID, ref min, ref max, ref def);
var ok = NVIDIA_MON.nhm_nvidia_device_get_memory_clocks_min_max_default(BusID, ref min, ref max, ref def, false);
if (ok == RET_OK) return (true, min, max, def);
Logger.InfoDelayed(LogTag, $"nhm_nvidia_device_get_memory_clocks_min_max_default failed with error code {ok}", _delayedLogging);
return (false, 0, 0, 0);
Expand Down
13 changes: 13 additions & 0 deletions src/NHM.DeviceMonitoring/Memory_clock/IMemoryClockDelta.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NHM.DeviceMonitoring.Memory_clock
{
public interface IMemoryClockDelta
{
int MemoryClockDelta { get; }
}
}
15 changes: 11 additions & 4 deletions src/NHM.DeviceMonitoring/NVIDIA/NVIDIA_MON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ internal static class NVIDIA_MON
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_get_core_clocks(int bus_number, ref int core_clocks);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_set_core_clocks(int bus_number, int core_clocks);
public static extern int nhm_nvidia_device_set_core_clocks(int bus_number, int core_clocks, bool is_absolute);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_reset_core_clocks(int bus_number, bool is_absolute);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_get_memory_clocks(int bus_number, ref int memory_clocks);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_set_memory_clocks(int bus_number, int memory_clocks);

public static extern int nhm_nvidia_device_get_memory_clocks_delta(int bus_number, ref int memory_clocks);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_set_memory_clocks(int bus_number, int memory_clocks, bool is_absolute);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_reset_memory_clocks(int bus_number, bool is_absolute);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_get_memory_info(int bus_number, ref ulong free, ref ulong total, ref ulong used);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
Expand All @@ -64,9 +71,9 @@ internal static class NVIDIA_MON
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_print_memory_timings(int bus_number);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_get_core_clocks_min_max_default(int bus_number, ref int min, ref int max, ref int def);
public static extern int nhm_nvidia_device_get_core_clocks_min_max_default(int bus_number, ref int min, ref int max, ref int def, bool is_absolute);
[DllImport(dll, CallingConvention = CallingConvention.StdCall)]
public static extern int nhm_nvidia_device_get_memory_clocks_min_max_default(int bus_number, ref int min, ref int max, ref int def);
public static extern int nhm_nvidia_device_get_memory_clocks_min_max_default(int bus_number, ref int min, ref int max, ref int def, bool is_absolute);


}
Expand Down
11 changes: 10 additions & 1 deletion src/NHMCore/Mining/ComputeDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ public int MemoryClock
return -1;
}
}

public int MemoryClockDelta
{
get
{
if (!GlobalDeviceSettings.Instance.DisableDeviceStatusMonitoring && DeviceMonitor != null && DeviceMonitor is IMemoryClockDelta get) return get.MemoryClockDelta;
return -1;
}
}
public (uint min, uint max, uint def) TDPLimits
{
get
Expand Down Expand Up @@ -886,7 +895,7 @@ private void SetFanSpeedWithLoweringMemoryClocks(FanProfile profile)
if (_memoryControlCounter >= 5)
{
_pidController.SetPid(100, 0.8, 1);
_pidController.SetOutputLimits(MemoryClockRange.min, MemoryClockRange.max);
_pidController.SetOutputLimits(MemoryClockRange.min, MemoryClockDelta);
var memory_clock = _pidController.GetOutput(Temp, Math.Min(profile.GpuTemp, profile.VramTemp));
SetMemoryClock((int)memory_clock);
_memoryControlCounter = 0;
Expand Down