Clock Limit tweaks

This commit is contained in:
Serge
2023-08-13 15:48:54 +02:00
parent 2282e56aad
commit 4c989c9d75
4 changed files with 55 additions and 49 deletions

View File

@@ -364,7 +364,7 @@ public static class AppConfig
public static bool IsGPUFixNeeded() public static bool IsGPUFixNeeded()
{ {
return ContainsModel("GA402X") || ContainsModel("GV302"); return ContainsModel("GA402X") || ContainsModel("GV302") || ContainsModel("FX506");
} }
public static bool IsGPUFix() public static bool IsGPUFix()

View File

@@ -443,7 +443,6 @@ namespace GHelper
int core = AppConfig.GetMode("gpu_core"); int core = AppConfig.GetMode("gpu_core");
int memory = AppConfig.GetMode("gpu_memory"); int memory = AppConfig.GetMode("gpu_memory");
int clock_limit = AppConfig.GetMode("gpu_clock_limit"); int clock_limit = AppConfig.GetMode("gpu_clock_limit");
if (gpu_boost < 0) gpu_boost = AsusACPI.MaxGPUBoost; if (gpu_boost < 0) gpu_boost = AsusACPI.MaxGPUBoost;
@@ -453,15 +452,17 @@ namespace GHelper
if (memory == -1) memory = 0; if (memory == -1) memory = 0;
if (clock_limit == -1) clock_limit = NvidiaGpuControl.MaxClockLimit; if (clock_limit == -1) clock_limit = NvidiaGpuControl.MaxClockLimit;
//if (readClocks) if (nvControl.GetClocks(out int current_core, out int current_memory))
//{
int status = nvControl.GetClocks(out int current_core, out int current_memory);
if (status != -1)
{ {
core = current_core; core = current_core;
memory = current_memory; memory = current_memory;
} }
int _clockLimit = nvControl.GetMaxGPUCLock();
if (_clockLimit == 0) clock_limit = NvidiaGpuControl.MaxClockLimit;
else if (_clockLimit > 0) clock_limit = _clockLimit;
try try
{ {
labelGPU.Text = nvControl.FullName; labelGPU.Text = nvControl.FullName;

View File

@@ -23,7 +23,6 @@ public class NvidiaGpuControl : IGpuControl
private static PhysicalGPU? _internalGpu; private static PhysicalGPU? _internalGpu;
private static int _maxClock = -1;
public NvidiaGpuControl() public NvidiaGpuControl()
{ {
_internalGpu = GetInternalDiscreteGpu(); _internalGpu = GetInternalDiscreteGpu();
@@ -80,7 +79,7 @@ public class NvidiaGpuControl : IGpuControl
} }
public int GetClocks(out int core, out int memory) public bool GetClocks(out int core, out int memory)
{ {
PhysicalGPU internalGpu = _internalGpu!; PhysicalGPU internalGpu = _internalGpu!;
@@ -99,14 +98,14 @@ public class NvidiaGpuControl : IGpuControl
Logger.WriteLine("GPU VOLT:" + delta.IsEditable + " - " + delta.ValueDeltaInMicroVolt.DeltaValue); Logger.WriteLine("GPU VOLT:" + delta.IsEditable + " - " + delta.ValueDeltaInMicroVolt.DeltaValue);
} }
return 0; return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.WriteLine("GET GPU CLOCKS:" + ex.Message); Logger.WriteLine("GET GPU CLOCKS:" + ex.Message);
core = memory = 0; core = memory = 0;
return -1; return false;
} }
} }
@@ -127,21 +126,43 @@ public class NvidiaGpuControl : IGpuControl
} }
public bool SetMaxGPUClock (int clock) public int GetMaxGPUCLock()
{ {
int oldClock = _maxClock; PhysicalGPU internalGpu = _internalGpu!;
try
{
PrivateClockBoostLockV2 data = GPUApi.GetClockBoostLock(internalGpu.Handle);
int limit = (int)data.ClockBoostLocks[0].VoltageInMicroV / 1000;
Logger.WriteLine("GET CLOCK LIMIT: " + limit);
return limit;
}
catch (Exception ex)
{
Logger.WriteLine("GET CLOCK LIMIT: " + ex.Message);
return -1;
if (clock >= MinClockLimit && clock < MaxClockLimit) }
RunPowershellCommand($"nvidia-smi -lgc 0,{clock}"); }
public int SetMaxGPUClock(int clock)
{
if (clock < MinClockLimit || clock >= MaxClockLimit) clock = 0;
int _clockLimit = GetMaxGPUCLock();
if (_clockLimit != clock)
{
if (clock > 0) RunPowershellCommand($"nvidia-smi -lgc 0,{clock}");
else RunPowershellCommand($"nvidia-smi -rgc");
return 1;
}
else else
{ {
clock = -1; return 0;
RunPowershellCommand($"nvidia-smi -rgc");
} }
_maxClock = clock;
return (oldClock != clock);
} }
@@ -150,25 +171,23 @@ public class NvidiaGpuControl : IGpuControl
return RunPowershellCommand(@"$device = Get-PnpDevice | Where-Object { $_.FriendlyName -imatch 'NVIDIA' -and $_.Class -eq 'Display' }; Disable-PnpDevice $device.InstanceId -Confirm:$false; Start-Sleep -Seconds 5; Enable-PnpDevice $device.InstanceId -Confirm:$false"); return RunPowershellCommand(@"$device = Get-PnpDevice | Where-Object { $_.FriendlyName -imatch 'NVIDIA' -and $_.Class -eq 'Display' }; Disable-PnpDevice $device.InstanceId -Confirm:$false; Start-Sleep -Seconds 5; Enable-PnpDevice $device.InstanceId -Confirm:$false");
} }
public int SetClocksFromConfig()
{
int core = AppConfig.Get("gpu_core", 0);
int memory = AppConfig.Get("gpu_memory", 0);
int status = SetClocks(core, memory);
return status;
}
public int SetClocks(int core, int memory, int voltage = 0) public int SetClocks(int core, int memory)
{ {
if (core < MinCoreOffset || core > MaxCoreOffset) return 0; if (core < MinCoreOffset || core > MaxCoreOffset) return 0;
if (memory < MinMemoryOffset || memory > MaxMemoryOffset) return 0; if (memory < MinMemoryOffset || memory > MaxMemoryOffset) return 0;
if (GetClocks(out int currentCore, out int currentMemory))
{
if (Math.Abs(core - currentCore) < 5 && Math.Abs(memory - currentMemory) < 5) return 0;
}
PhysicalGPU internalGpu = _internalGpu!; PhysicalGPU internalGpu = _internalGpu!;
var coreClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Graphics, new PerformanceStates20ParameterDelta(core * 1000)); var coreClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Graphics, new PerformanceStates20ParameterDelta(core * 1000));
var memoryClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Memory, new PerformanceStates20ParameterDelta(memory * 1000)); var memoryClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Memory, new PerformanceStates20ParameterDelta(memory * 1000));
var voltageEntry = new PerformanceStates20BaseVoltageEntryV1(PerformanceVoltageDomain.Core, new PerformanceStates20ParameterDelta(voltage)); //var voltageEntry = new PerformanceStates20BaseVoltageEntryV1(PerformanceVoltageDomain.Core, new PerformanceStates20ParameterDelta(voltage));
PerformanceStates20ClockEntryV1[] clocks = { coreClock, memoryClock }; PerformanceStates20ClockEntryV1[] clocks = { coreClock, memoryClock };
PerformanceStates20BaseVoltageEntryV1[] voltages = { }; PerformanceStates20BaseVoltageEntryV1[] voltages = { };
@@ -188,8 +207,6 @@ public class NvidiaGpuControl : IGpuControl
return -1; return -1;
} }
return 1; return 1;
} }

View File

@@ -291,11 +291,11 @@ namespace GHelper.Mode
Task.Run(() => Task.Run(() =>
{ {
int gpu_core = AppConfig.GetMode("gpu_core"); int core = AppConfig.GetMode("gpu_core");
int gpu_memory = AppConfig.GetMode("gpu_memory"); int memory = AppConfig.GetMode("gpu_memory");
int gpu_clock_limit = AppConfig.GetMode("gpu_clock_limit"); int clock_limit = AppConfig.GetMode("gpu_clock_limit");
if (gpu_core == -1 && gpu_memory == -1) return; if (core == -1 && memory == -1) return;
//if ((gpu_core > -5 && gpu_core < 5) && (gpu_memory > -5 && gpu_memory < 5)) launchAsAdmin = false; //if ((gpu_core > -5 && gpu_core < 5) && (gpu_memory > -5 && gpu_memory < 5)) launchAsAdmin = false;
@@ -306,21 +306,9 @@ namespace GHelper.Mode
using NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl; using NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
try try
{ {
int statusLimit = nvControl.SetMaxGPUClock(clock_limit);
bool changed = nvControl.SetMaxGPUClock(gpu_clock_limit); int statusClocks = nvControl.SetClocks(core, memory);
if (changed && launchAsAdmin) ProcessHelper.RunAsAdmin("gpu"); if ((statusLimit != 0 || statusClocks != 0) && launchAsAdmin) ProcessHelper.RunAsAdmin("gpu");
int getStatus = nvControl.GetClocks(out int current_core, out int current_memory);
if (getStatus != -1)
{
if (Math.Abs(gpu_core - current_core) < 5 && Math.Abs(gpu_memory - current_memory) < 5) return;
}
int setStatus = nvControl.SetClocks(gpu_core, gpu_memory);
if (launchAsAdmin) ProcessHelper.RunAsAdmin("gpu");
} }
catch (Exception ex) catch (Exception ex)
{ {