public OverClockRange GetClockRange(int gpuIndex) { OverClockRange result = new OverClockRange(gpuIndex); try { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(result); } ADLODNCapabilitiesX2 info = new ADLODNCapabilitiesX2(); var r = AdlNativeMethods.ADL2_OverdriveN_CapabilitiesX2_Get(context, adapterIndex, ref info); if (r < AdlStatus.ADL_OK) { Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_CapabilitiesX2_Get)} {r}"); return(result); } result.PowerCurr = GetPowerLimit(gpuIndex); result.TempCurr = GetTempLimit(gpuIndex); if (GetMemoryClock(gpuIndex, out int memoryClock, out int iVddc)) { result.MemoryClockDelta = memoryClock; result.MemoryVoltage = iVddc; } if (GetCoreClock(gpuIndex, out int coreClock, out iVddc)) { result.CoreClockDelta = coreClock; result.CoreVoltage = iVddc; } result.CoreClockMin = info.sEngineClockRange.iMin * 10; result.CoreClockMax = info.sEngineClockRange.iMax * 10; result.MemoryClockMin = info.sMemoryClockRange.iMin * 10; result.MemoryClockMax = info.sMemoryClockRange.iMax * 10; result.PowerMin = info.power.iMin + 100; result.PowerMax = info.power.iMax + 100; result.PowerDefault = info.power.iDefault + 100; result.TempLimitMin = info.powerTuneTemperature.iMin; result.TempLimitMax = info.powerTuneTemperature.iMax; result.TempLimitDefault = info.powerTuneTemperature.iDefault; result.VoltMin = info.svddcRange.iMin; result.VoltMax = info.svddcRange.iMax; result.VoltDefault = info.svddcRange.iDefault; if (info.fanSpeed.iMax == 0) { result.FanSpeedMin = 0; } else { result.FanSpeedMin = info.fanSpeed.iMin * 100 / info.fanSpeed.iMax; } result.FanSpeedMax = 100; result.FanSpeedDefault = info.fanSpeed.iDefault; #if DEBUG Write.DevWarn($"GetClockRange {result.ToString()}"); #endif } catch (Exception e) { Logger.ErrorDebugLine(e); } return(result); }
// AMD tdpLimit private bool SetTdpADL(double percValue) { try { if (ADL.ADL2_OverdriveN_PowerLimit_Set.Delegate == null) { Logger.ErrorDelayed(LogTag, $"SetTdpADL ADL2_OverdriveN_PowerLimit_Set not supported", TimeSpan.FromSeconds(30)); return(false); } if (ADL.ADL2_OverdriveN_CapabilitiesX2_Get.Delegate == null) { Logger.ErrorDelayed(LogTag, $"SetTdpADL ADL2_OverdriveN_CapabilitiesX2_Get not supported", TimeSpan.FromSeconds(30)); return(false); } var ADLODNCapabilitiesX2 = new ADLODNCapabilitiesX2(); var ret = ADL.ADL2_OverdriveN_CapabilitiesX2_Get.Delegate(_adlContext, _adapterIndex, ref ADLODNCapabilitiesX2); if (ret != ADL.ADL_SUCCESS) { Logger.Info(LogTag, $"SetTdpADL ADL2_OverdriveN_CapabilitiesX2_Get returned {ret}"); return(false); } var limit = 0.0d; if (percValue > 1) { limit = RangeCalculator.CalculateValueAMD(percValue - 1, ADLODNCapabilitiesX2.power.iDefault, ADLODNCapabilitiesX2.power.iMax); } else { limit = RangeCalculator.CalculateValueAMD(percValue, ADLODNCapabilitiesX2.power.iMin, ADLODNCapabilitiesX2.power.iDefault); } var setLimit = (int)limit; if (setLimit > ADLODNCapabilitiesX2.power.iMax) { setLimit = ADLODNCapabilitiesX2.power.iMax; } //set value here var lpODPowerLimit = new ADLODNPowerLimitSetting(); lpODPowerLimit.iMode = (int)ADLODNControlType.ODNControlType_Manual; lpODPowerLimit.iTDPLimit = setLimit; var adlRet = ADL.ADL2_OverdriveN_PowerLimit_Set.Delegate(_adlContext, _adapterIndex, ref lpODPowerLimit); if (adlRet != ADL.ADL_SUCCESS) { Logger.Error(LogTag, $"ADL2_OverdriveN_PowerLimit_Set failed with code {adlRet} for GPU BusID={BusID}."); return(false); } return(true); } catch (Exception e) { Logger.Info(LogTag, $"SetTdpADL {e.Message}"); } return(false); }
// AMD tdpLimit private bool SetTdpADL(bool usePercentage, double rawOrPercValue) { try { if (ADL.ADL2_OverdriveN_PowerLimit_Set.Delegate == null) { Logger.ErrorDelayed(LogTag, $"SetTdpADL ADL2_OverdriveN_PowerLimit_Set not supported", TimeSpan.FromSeconds(30)); return(false); } if (ADL.ADL2_OverdriveN_CapabilitiesX2_Get.Delegate == null) { Logger.ErrorDelayed(LogTag, $"SetTdpADL ADL2_OverdriveN_CapabilitiesX2_Get not supported", TimeSpan.FromSeconds(30)); return(false); } var ADLODNCapabilitiesX2 = new ADLODNCapabilitiesX2(); var ret = ADL.ADL2_OverdriveN_CapabilitiesX2_Get.Delegate(_adlContext, _adapterIndex, ref ADLODNCapabilitiesX2); if (ret != ADL.ADL_SUCCESS) { Logger.Info(LogTag, $"SetTdpADL ADL2_OverdriveN_CapabilitiesX2_Get returned {ret}"); return(false); } // We limit 100% to the default as max int tdpLimit = 0; if (usePercentage) { var limit = RangeCalculator.CalculateValue(rawOrPercValue, ADLODNCapabilitiesX2.power.iMin, ADLODNCapabilitiesX2.power.iDefault); tdpLimit = (int)limit; } else { var limit = Math.Max((int)rawOrPercValue, ADLODNCapabilitiesX2.power.iMin); tdpLimit = Math.Min(limit, ADLODNCapabilitiesX2.power.iDefault); } //set value here var lpODPowerLimit = new ADLODNPowerLimitSetting(); lpODPowerLimit.iMode = (int)ADLODNControlType.ODNControlType_Manual; lpODPowerLimit.iTDPLimit = tdpLimit; var adlRet = ADL.ADL2_OverdriveN_PowerLimit_Set.Delegate(_adlContext, _adapterIndex, ref lpODPowerLimit); if (adlRet != ADL.ADL_SUCCESS) { Logger.Error(LogTag, $"ADL2_OverdriveN_PowerLimit_Set failed with code {adlRet} for GPU BusID={BusID}."); return(false); } return(true); } catch (Exception e) { Logger.Info(LogTag, $"SetTdpADL {e.Message}"); } return(false); }
private bool Init() { try { if (_isHasATIGpu) { foreach (var adapterInfo in _adapterInfoes) { NTMinerConsole.DevDebug(() => adapterInfo.ToString()); bool found = false; foreach (ATIGPU gpu in _gpuNames) { if (gpu.BusNumber == adapterInfo.BusNumber && gpu.DeviceNumber == adapterInfo.DeviceNumber) { found = true; break; } } if (!found) { int adapterIndex = adapterInfo.AdapterIndex; int overdriveVersion = 0; try { if (AdlNativeMethods.ADL_Overdrive_Caps(adapterIndex, out _, out _, out overdriveVersion) != AdlStatus.ADL_OK) { overdriveVersion = -1; } } catch (Exception ex) { Logger.ErrorDebugLine(ex); } ADLODNCapabilitiesX2 info = new ADLODNCapabilitiesX2(); try { var r = AdlNativeMethods.ADL2_OverdriveN_CapabilitiesX2_Get(_context, adapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_CapabilitiesX2_Get)} {r.ToString()}"); } } catch (Exception ex) { Logger.ErrorDebugLine(ex); } int maxLevels = info.iMaximumNumberOfPerformanceLevels; int fanSpeedMin = 0; int fanSpeedMax = 0; ADLFanSpeedInfo afsi = new ADLFanSpeedInfo(); try { var r = AdlNativeMethods.ADL_Overdrive5_FanSpeedInfo_Get(adapterIndex, 0, ref afsi); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL_Overdrive5_FanSpeedInfo_Get)} {r.ToString()}"); } else { fanSpeedMax = afsi.MaxPercent; fanSpeedMin = afsi.MinPercent; } } catch (Exception ex) { Logger.ErrorDebugLine(ex); } ADLODNPerformanceLevelsX2 systemClockX2 = ADLODNPerformanceLevelsX2.Create(); systemClockX2.iNumberOfPerformanceLevels = maxLevels; try { var r = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get(_context, adapterIndex, ref systemClockX2); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get)} {r.ToString()}"); } } catch (Exception ex) { Logger.ErrorDebugLine(ex); } int gpuLevel = 0; int memoryLevel = 0; for (int j = 0; j < systemClockX2.aLevels.Length; j++) { if (systemClockX2.aLevels[j].iEnabled != 0) { gpuLevel = j + 1; } } ADLODNPerformanceLevelsX2 memoryClockX2 = ADLODNPerformanceLevelsX2.Create(); memoryClockX2.iNumberOfPerformanceLevels = maxLevels; try { var r = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get(_context, adapterIndex, ref memoryClockX2); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get)} {r.ToString()}"); } } catch (Exception ex) { Logger.ErrorDebugLine(ex); } for (int j = 0; j < memoryClockX2.aLevels.Length; j++) { if (memoryClockX2.aLevels[j].iEnabled != 0) { memoryLevel = j + 1; } } int powerMin = info.power.iMin + 100; int powerMax = info.power.iMax + 100; int powerDefault = info.power.iDefault + 100; int voltMin = info.svddcRange.iMin; // 0 int voltMax = info.svddcRange.iMax; // 0 int voltDefault = info.svddcRange.iDefault; // 0 int tempLimitMin = info.powerTuneTemperature.iMin; int tempLimitMax = info.powerTuneTemperature.iMax; int tempLimitDefault = info.powerTuneTemperature.iDefault; int coreClockMin = info.sEngineClockRange.iMin * 10; int coreClockMax = info.sEngineClockRange.iMax * 10; int memoryClockMin = info.sMemoryClockRange.iMin * 10; int memoryClockMax = info.sMemoryClockRange.iMax * 10; bool apiSupported = gpuLevel > 0 && memoryLevel > 0; ADLOD8InitSetting odInitSetting = ADLOD8InitSetting.Create(); if (!apiSupported) { try { if (overdriveVersion == 8) { if (GetOD8InitSetting(adapterIndex, out odInitSetting)) { apiSupported = true; gpuLevel = 3; memoryLevel = 0; maxLevels = 3; powerMin = 0; powerMax = 0; powerDefault = 0; voltMin = 0; voltMax = 0; voltDefault = 0; tempLimitMin = 0; tempLimitMax = 0; tempLimitDefault = 0; coreClockMin = 0; coreClockMax = 0; memoryClockMin = 0; memoryClockMax = 0; if ((odInitSetting.overdrive8Capabilities & (int)ADLOD8FeatureControl.ADL_OD8_GFXCLK_LIMITS) == (int)ADLOD8FeatureControl.ADL_OD8_GFXCLK_LIMITS || (odInitSetting.overdrive8Capabilities & (int)ADLOD8FeatureControl.ADL_OD8_GFXCLK_CURVE) == (int)ADLOD8FeatureControl.ADL_OD8_GFXCLK_CURVE) { coreClockMin = odInitSetting.od8SettingTable[(int)ADLOD8SettingId.OD8_GFXCLK_FMAX].minValue * 1000; coreClockMax = odInitSetting.od8SettingTable[(int)ADLOD8SettingId.OD8_GFXCLK_FMAX].maxValue * 1000; voltMin = odInitSetting.od8SettingTable[(int)ADLOD8SettingId.OD8_GFXCLK_VOLTAGE3].minValue; voltMax = odInitSetting.od8SettingTable[(int)ADLOD8SettingId.OD8_GFXCLK_VOLTAGE3].maxValue; powerMin = 100 + odInitSetting.od8SettingTable[(int)ADLOD8SettingId.OD8_POWER_PERCENTAGE].minValue; powerMax = 100 + odInitSetting.od8SettingTable[(int)ADLOD8SettingId.OD8_POWER_PERCENTAGE].maxValue; memoryClockMin = odInitSetting.od8SettingTable[(int)ADLOD8SettingId.OD8_UCLK_FMAX].minValue * 1000; memoryClockMax = odInitSetting.od8SettingTable[(int)ADLOD8SettingId.OD8_UCLK_FMAX].maxValue * 1000; } #if DEBUG Logger.Debug(odInitSetting.ToString()); #endif } } } catch (Exception ex) { Logger.ErrorDebugLine(ex); } } if (fanSpeedMax <= 0) { fanSpeedMax = 100; } if (powerMax <= 0) { powerMax = 100; } _gpuNames.Add(new ATIGPU { AdapterName = adapterInfo.AdapterName.Trim(), AdapterIndex = adapterIndex, BusNumber = adapterInfo.BusNumber, DeviceNumber = adapterInfo.DeviceNumber, OverdriveVersion = overdriveVersion, MaxLevels = maxLevels, ApiSupported = apiSupported, GpuLevels = gpuLevel, MemoryLevels = memoryLevel, CoreClockMin = coreClockMin, CoreClockMax = coreClockMax, MemoryClockMin = memoryClockMin, MemoryClockMax = memoryClockMax, PowerMin = powerMin, PowerMax = powerMax, PowerDefault = powerDefault, TempLimitMin = tempLimitMin, TempLimitMax = tempLimitMax, TempLimitDefault = tempLimitDefault, VoltMin = voltMin, VoltMax = voltMax, VoltDefault = voltDefault, FanSpeedMax = fanSpeedMax, FanSpeedMin = fanSpeedMin, ADLOD8InitSetting = odInitSetting }); } } } _gpuNames = _gpuNames.OrderBy(a => a.BusNumber).ToList(); NTMinerConsole.DevDebug(() => string.Join(",", _gpuNames.Select(a => a.AdapterIndex))); } catch (Exception ex) { Logger.ErrorDebugLine(ex); return(false); } return(true); }