GpuOverClock.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using NTMiner.Gpus;
  2. namespace NTMiner.Core.Gpus.Impl {
  3. public class GpuOverClock : IOverClock {
  4. private readonly IGpuHelper _gpuHelper;
  5. public GpuOverClock(IGpuHelper gpuHelper) {
  6. _gpuHelper = gpuHelper;
  7. }
  8. public void RefreshGpuState(IGpu gpu) {
  9. if (gpu.Index == NTMinerRoot.GpuAllId) {
  10. return;
  11. }
  12. try {
  13. OverClockRange range = _gpuHelper.GetClockRange(gpu.GetOverClockId());
  14. gpu.UpdateState(range);
  15. }
  16. catch (System.Exception e) {
  17. Logger.ErrorDebugLine(e);
  18. }
  19. VirtualRoot.RaiseEvent(new GpuStateChangedEvent(gpu));
  20. }
  21. public void SetCoreClock(int gpuIndex, int value, int voltage) {
  22. if (gpuIndex == NTMinerRoot.GpuAllId) {
  23. foreach (var gpu in NTMinerRoot.Instance.GpuSet) {
  24. if (gpu.Index == NTMinerRoot.GpuAllId) {
  25. continue;
  26. }
  27. if (value != 0) {
  28. if (value == gpu.CoreClockDelta && voltage == gpu.CoreVoltage) {
  29. continue;
  30. }
  31. }
  32. _gpuHelper.SetCoreClock(gpu.GetOverClockId(), value, voltage);
  33. }
  34. }
  35. else {
  36. if (!NTMinerRoot.Instance.GpuSet.TryGetGpu(gpuIndex, out IGpu gpu) || (value != 0 && value == gpu.CoreClockDelta && voltage == gpu.CoreVoltage)) {
  37. return;
  38. }
  39. _gpuHelper.SetCoreClock(gpu.GetOverClockId(), value, voltage);
  40. }
  41. }
  42. public void SetMemoryClock(int gpuIndex, int value, int voltage) {
  43. if (gpuIndex == NTMinerRoot.GpuAllId) {
  44. foreach (var gpu in NTMinerRoot.Instance.GpuSet) {
  45. if (gpu.Index == NTMinerRoot.GpuAllId) {
  46. continue;
  47. }
  48. if (value != 0) {
  49. if (value == gpu.MemoryClockDelta && voltage == gpu.MemoryVoltage) {
  50. continue;
  51. }
  52. }
  53. _gpuHelper.SetMemoryClock(gpu.GetOverClockId(), value, voltage);
  54. }
  55. }
  56. else {
  57. if (!NTMinerRoot.Instance.GpuSet.TryGetGpu(gpuIndex, out IGpu gpu) || (value != 0 && value == gpu.MemoryClockDelta && voltage == gpu.MemoryVoltage)) {
  58. return;
  59. }
  60. _gpuHelper.SetMemoryClock(gpu.GetOverClockId(), value, voltage);
  61. }
  62. }
  63. public void SetPowerLimit(int gpuIndex, int value) {
  64. if (value == 0) {
  65. value = 100;
  66. }
  67. if (gpuIndex == NTMinerRoot.GpuAllId) {
  68. foreach (var gpu in NTMinerRoot.Instance.GpuSet) {
  69. if (gpu.Index == NTMinerRoot.GpuAllId) {
  70. continue;
  71. }
  72. if (value != 0) {
  73. if (value == gpu.PowerCapacity) {
  74. continue;
  75. }
  76. }
  77. _gpuHelper.SetPowerLimit(gpu.GetOverClockId(), value);
  78. }
  79. }
  80. else {
  81. if (!NTMinerRoot.Instance.GpuSet.TryGetGpu(gpuIndex, out IGpu gpu) || (value != 0 && value == gpu.PowerCapacity)) {
  82. return;
  83. }
  84. _gpuHelper.SetPowerLimit(gpu.GetOverClockId(), value);
  85. }
  86. }
  87. public void SetTempLimit(int gpuIndex, int value) {
  88. if (gpuIndex == NTMinerRoot.GpuAllId) {
  89. foreach (var gpu in NTMinerRoot.Instance.GpuSet) {
  90. if (gpu.Index == NTMinerRoot.GpuAllId) {
  91. continue;
  92. }
  93. if (value != 0) {
  94. if (value == gpu.TempLimit) {
  95. continue;
  96. }
  97. }
  98. _gpuHelper.SetTempLimit(gpu.GetOverClockId(), value);
  99. }
  100. }
  101. else {
  102. if (!NTMinerRoot.Instance.GpuSet.TryGetGpu(gpuIndex, out IGpu gpu) || (value != 0 && value == gpu.TempLimit)) {
  103. return;
  104. }
  105. _gpuHelper.SetTempLimit(gpu.GetOverClockId(), value);
  106. }
  107. }
  108. public void SetFanSpeed(int gpuIndex, int value) {
  109. bool isAutoModel = value == 0;
  110. if (gpuIndex == NTMinerRoot.GpuAllId) {
  111. foreach (var gpu in NTMinerRoot.Instance.GpuSet) {
  112. if (gpu.Index == NTMinerRoot.GpuAllId) {
  113. continue;
  114. }
  115. _gpuHelper.SetFanSpeed(gpu.GetOverClockId(), value, isAutoModel);
  116. }
  117. }
  118. else {
  119. if (!NTMinerRoot.Instance.GpuSet.TryGetGpu(gpuIndex, out IGpu gpu)) {
  120. return;
  121. }
  122. _gpuHelper.SetFanSpeed(gpu.GetOverClockId(), value, isAutoModel);
  123. }
  124. }
  125. public void Restore() {
  126. SetCoreClock(NTMinerRoot.GpuAllId, 0, 0);
  127. SetMemoryClock(NTMinerRoot.GpuAllId, 0, 0);
  128. SetPowerLimit(NTMinerRoot.GpuAllId, 0);
  129. SetTempLimit(NTMinerRoot.GpuAllId, 0);
  130. SetFanSpeed(NTMinerRoot.GpuAllId, 0);
  131. RefreshGpuState(NTMinerRoot.GpuAllId);
  132. }
  133. public void RefreshGpuState(int gpuIndex) {
  134. if (gpuIndex == NTMinerRoot.GpuAllId) {
  135. foreach (var gpu in NTMinerRoot.Instance.GpuSet) {
  136. if (gpu.Index == NTMinerRoot.GpuAllId) {
  137. continue;
  138. }
  139. RefreshGpuState(gpu);
  140. }
  141. }
  142. else {
  143. if (NTMinerRoot.Instance.GpuSet.TryGetGpu(gpuIndex, out IGpu gpu)) {
  144. RefreshGpuState(gpu);
  145. }
  146. }
  147. }
  148. }
  149. }