Пример #1
0
 public bool GetMemoryClock(int gpuIndex, out int memoryClock, out int iVddc)
 {
     memoryClock = 0;
     iVddc       = 0;
     try {
         if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex))
         {
             return(false);
         }
         ADLODNPerformanceLevelsX2 info = ADLODNPerformanceLevelsX2.Create();
         var r = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get)} {r.ToString()}");
             return(false);
         }
         int index = 0;
         for (int i = 0; i < info.aLevels.Length; i++)
         {
             if (info.aLevels[i].iEnabled != 0)
             {
                 index = i;
             }
             Write.DevWarn("GetMemoryClock " + info.aLevels[i].ToString());
         }
         memoryClock = info.aLevels[index].iClock * 10;
         iVddc       = info.aLevels[index].iVddc;
         return(true);
     }
     catch {
         return(false);
     }
 }
Пример #2
0
 public void GetClockAndVolt(int gpuIndex, out int memoryClock, out int memoryiVddc, out int coreClock, out int coreiVddc)
 {
     memoryClock = 0;
     memoryiVddc = 0;
     coreClock   = 0;
     coreiVddc   = 0;
     try {
         if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpu))
         {
             return;
         }
         if (gpu.OverdriveVersion < 8)
         {
             try {
                 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()}");
                 }
                 var index = gpu.GpuLevels - 1;
                 coreClock = info.aLevels[index].iClock * 10;
                 coreiVddc = info.aLevels[index].iVddc;
             }
             catch {
             }
             try {
                 ADLODNPerformanceLevelsX2 info = ADLODNPerformanceLevelsX2.Create();
                 var r = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get(_context, gpu.AdapterIndex, ref info);
                 if (r < AdlStatus.ADL_OK)
                 {
                     NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get)} {r.ToString()}");
                 }
                 int index = gpu.MemoryLevels - 1;
                 memoryClock = info.aLevels[index].iClock * 10;
                 memoryiVddc = info.aLevels[index].iVddc;
             }
             catch {
             }
         }
         else if (GetOD8CurrentSetting(gpu.AdapterIndex, out ADLOD8CurrentSetting odCurrentSetting))
         {
             coreClock   = odCurrentSetting.Od8SettingTable[(int)ADLOD8SettingId.OD8_GFXCLK_FMAX] * 1000;
             coreiVddc   = odCurrentSetting.Od8SettingTable[(int)ADLOD8SettingId.OD8_GFXCLK_VOLTAGE3];
             memoryClock = odCurrentSetting.Od8SettingTable[(int)ADLOD8SettingId.OD8_UCLK_FMAX] * 1000;
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
 }
Пример #3
0
 public bool SetMemoryClock(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_MemoryClocksX2_Get(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get)} {r.ToString()}");
             return(false);
         }
         info.iMode = AdlConst.ODNControlType_Default;
         r          = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Set(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Set)} {r.ToString()}");
             return(false);
         }
         bool isReset = value == 0 && voltage == 0;
         if (isReset)
         {
             return(true);
         }
         r = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_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($"SetMemoryClock 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_MemoryClocksX2_Set(context, adapterIndex, ref info);
         if (r < AdlStatus.ADL_OK)
         {
             Write.DevError($"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Set)} {r.ToString()}");
             return(false);
         }
         return(true);
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(false);
     }
 }
Пример #4
0
 public bool SetMemoryClock(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_MemoryClocksX2_Get(_context, gpu.AdapterIndex, ref info);
             if (r < AdlStatus.ADL_OK)
             {
                 NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get)} {r.ToString()}");
                 return(false);
             }
             info.iMode = AdlConst.ODNControlType_Default;
             r          = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Set(_context, gpu.AdapterIndex, ref info);
             if (r < AdlStatus.ADL_OK)
             {
                 NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Set)} {r.ToString()}");
                 return(false);
             }
             if (isReset)
             {
                 return(true);
             }
             r = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get(_context, gpu.AdapterIndex, ref info);
             if (r < AdlStatus.ADL_OK)
             {
                 NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_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(SetMemoryClock)} 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_MemoryClocksX2_Set(_context, gpu.AdapterIndex, ref info);
             if (r < AdlStatus.ADL_OK)
             {
                 NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Set)} {r.ToString()}");
                 return(false);
             }
         }
         else
         {
             if (GetOD8CurrentSetting(gpu.AdapterIndex, out ADLOD8CurrentSetting odCurrentSetting))
             {
                 SetOD8Range(gpu.ADLOD8InitSetting, odCurrentSetting, gpu.AdapterIndex, ADLOD8SettingId.OD8_UCLK_FMAX, isReset, value * 100);
             }
         }
         return(true);
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(false);
     }
 }
Пример #5
0
        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);
        }