Example #1
0
 public bool SetCoreClock(int gpuIndex, int value, int voltage)
 {
     if (value < 0)
     {
         value = 0;
     }
     if (voltage < 0)
     {
         voltage = 0;
     }
     try {
         if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex))
         {
             return(false);
         }
         ADLODNPerformanceLevelsX2 info = ADLODNPerformanceLevelsX2.Create();
         var r = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get)} {r.ToString()}");
             return(false);
         }
         info.iMode = AdlConst.ODNControlType_Default;
         r          = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Set(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Set)} {r.ToString()}");
             return(false);
         }
         bool isReset = value == 0 && voltage == 0;
         if (isReset)
         {
             return(true);
         }
         r = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get)} {r.ToString()}");
             return(false);
         }
         info.iMode = AdlConst.ODNControlType_Manual;
         int index = 0;
         for (int i = 0; i < info.aLevels.Length; i++)
         {
             if (info.aLevels[i].iEnabled != 0)
             {
                 index = i;
             }
         }
         Write.DevDebug($"SetCoreClock PState {index.ToString()} value={value.ToString()} voltage={voltage.ToString()}");
         if (value != 0)
         {
             info.aLevels[index].iClock = value * 100;
         }
         if (voltage != 0)
         {
             info.aLevels[index].iVddc = voltage;
         }
         r = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Set(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Set)} {r.ToString()}");
             return(false);
         }
         return(true);
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(false);
     }
 }
Example #2
0
 public bool SetCoreClock(int gpuIndex, int value, int voltage)
 {
     if (value < 0)
     {
         value = 0;
     }
     if (voltage < 0)
     {
         voltage = 0;
     }
     try {
         if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpu))
         {
             return(false);
         }
         bool isReset = value == 0 && voltage == 0;
         if (gpu.OverdriveVersion < 8)
         {
             ADLODNPerformanceLevelsX2 info = ADLODNPerformanceLevelsX2.Create();
             var r = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get(_context, gpu.AdapterIndex, ref info);
             if (r < AdlStatus.ADL_OK)
             {
                 NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get)} {r.ToString()}");
                 return(false);
             }
             info.iMode = AdlConst.ODNControlType_Default;
             r          = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Set(_context, gpu.AdapterIndex, ref info);
             if (r < AdlStatus.ADL_OK)
             {
                 NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Set)} {r.ToString()}");
                 return(false);
             }
             if (isReset)
             {
                 return(true);
             }
             r = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get(_context, gpu.AdapterIndex, ref info);
             if (r < AdlStatus.ADL_OK)
             {
                 NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get)} {r.ToString()}");
                 return(false);
             }
             info.iMode = AdlConst.ODNControlType_Manual;
             int index = 0;
             for (int i = 0; i < info.aLevels.Length; i++)
             {
                 if (info.aLevels[i].iEnabled != 0)
                 {
                     index = i;
                 }
             }
             NTMinerConsole.DevDebug(() => $"{nameof(SetCoreClock)} PState {index.ToString()} value={value.ToString()} voltage={voltage.ToString()}");
             if (value != 0)
             {
                 info.aLevels[index].iClock = value * 100;
             }
             if (voltage != 0)
             {
                 info.aLevels[index].iVddc = voltage;
             }
             r = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Set(_context, gpu.AdapterIndex, ref info);
             if (r < AdlStatus.ADL_OK)
             {
                 NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Set)} {r.ToString()}");
                 return(false);
             }
         }
         else
         {
             if (GetOD8CurrentSetting(gpu.AdapterIndex, out ADLOD8CurrentSetting odCurrentSetting))
             {
                 SetOD8Range(gpu.ADLOD8InitSetting, odCurrentSetting, gpu.AdapterIndex, ADLOD8SettingId.OD8_GFXCLK_FMAX, isReset, value * 100);
                 SetOD8Range(gpu.ADLOD8InitSetting, odCurrentSetting, gpu.AdapterIndex, ADLOD8SettingId.OD8_GFXCLK_VOLTAGE3, isReset, voltage);
             }
         }
         return(true);
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(false);
     }
 }