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); }
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); }