public static void Manual(string gpuType, int powerlimit, int coreclock, int fan, int memoryclock) { for (int i = 0; i < mahm.Header.GpuEntryCount; i++) { try { macm.GpuEntries[i].FanSpeedCur = Convert.ToUInt32(fan); } catch (Exception ex) { macm.GpuEntries[i].FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.None; macm.GpuEntries[i].FanSpeedCur = Convert.ToUInt32(fan); } macm.GpuEntries[i].PowerLimitCur = powerlimit; if (gpuType.Equals("nvidia")) { macm.GpuEntries[i].CoreClockBoostCur = coreclock * 1000; macm.GpuEntries[i].MemoryClockBoostCur = memoryclock * 1000; } if (gpuType.Equals("amd")) { macm.GpuEntries[i].CoreClockCur = Convert.ToUInt32(coreclock * 1000); macm.GpuEntries[i].MemoryClockCur = Convert.ToUInt32(memoryclock * 1000); } // APPLY AFTERBURNER CHANGES macm.CommitChanges(); System.Threading.Thread.Sleep(2000); macm.ReloadAll(); } }
private void CardsMonitoring() { var messageBus = _messageBusFactory.Create(); Task.Factory.StartNew(async() => { do { _lockEvent.WaitOne(); try { var ctrlGpu = new ControlMemory(); var voltageMonitor = new HardwareMonitor(); var voltage = new List <VoltageInfo>(); var temp = new List <TempInfo>(); foreach (var vol in voltageMonitor.Entries.Where(x => x.SrcId == 96)) { voltage.Add(new VoltageInfo { Current = vol.Data, Max = vol.MaxLimit, CardId = vol.GPU }); } messageBus.Handle(new AutobernerVoltageCardsInfoMessage { VoltageInfoModel = voltage.ToArray() }); foreach (var vol in voltageMonitor.Entries.Where(x => x.SrcId == 0)) { temp.Add(new TempInfo { Current = vol.Data, CardId = vol.GPU }); } messageBus.Handle(new AutobernerTempCardsInfoMessage { TempInfoModel = temp.ToArray() }); ctrlGpu.Connect(); ctrlGpu.ReloadAll(); ctrlGpu.Reinitialize(); var actualList = FindCards(ctrlGpu); messageBus.Handle(new AutobernerInformationMessage { CurrentInfoCards = actualList.ToList() }); ctrlGpu.Disconnect(); } catch (Exception ex) { _logger.Error($"CardsMonitoring error: {ex.Message}"); } await Task.Delay(_config.MonitoringInterval, _token.Token); } while (!_token.IsCancellationRequested); }, _token.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith((x) => { messageBus.Handle <AutobernerStopWatchingMessage>(); }, TaskContinuationOptions.OnlyOnFaulted); }
private static Task MSIconnecting(MainModel mm) { return(Task.Run(() => { while (Process.GetProcessesByName("MSIAfterburner").Length == 0) { Thread.Sleep(100); } try { MSIpath = Process.GetProcessesByName("MSIAfterburner").First().MainModule.FileName; } catch { mm.Logging("Добавьте права администратора", true); } IEnumerable <ControlMemoryGpuEntry> GEs = new List <ControlMemoryGpuEntry>(); while (GEs.Count() == 0) { try { CM = new ControlMemory(); CM.ReloadAll(); GEs = CM.GpuEntries.Where(e => e.PowerLimitMax - e.PowerLimitMin != 0); ValidGPUS = CM.GpuEntries.Select(e => e.PowerLimitMax - e.PowerLimitMin != 0); Thread.Sleep(1000); } catch { Thread.Sleep(1000); } } MSIconnected = true; Task.Run(() => ConnectedToMSI?.Invoke(new DefClock { PowerLimits = GEs.Select(e => e.PowerLimitDef).ToArray(), CoreClocks = GEs.Select(e => (e.CoreClockBoostMin != 0 ? e.CoreClockBoostDef : (e.CoreClockMin != 0 ? Convert.ToInt32(e.CoreClockDef) : 0)) / 1000).ToArray(), MemoryClocks = GEs.Select(e => (e.MemoryClockBoostMin != 0 ? e.MemoryClockBoostDef : (e.MemoryClockMin != 0 ? Convert.ToInt32(e.MemoryClockDef) : 0)) / 1000).ToArray(), FanSpeeds = GEs.Select(e => Convert.ToInt32(e.FanSpeedDef)).ToArray() })); })); }
private void CardsMonitoring(CardParam[] configCards) { var messageBus = _messageBusFactory.Create(); Task.Factory.StartNew(async() => { do { _lockEvent.WaitOne(); try { var ctrlGpu = new ControlMemory(); ctrlGpu.Connect(); ctrlGpu.ReloadAll(); ctrlGpu.Reinitialize(); var actualList = FindCards(ctrlGpu); ctrlGpu.Disconnect(); if (_config.WatchDog) { WatchDog(configCards, actualList); } } catch (Exception ex) { _logger.Error($"CardsMonitoring error: {ex.Message}"); } await Task.Delay(_config.MonitoringInterval, _token.Token); } while (!_token.IsCancellationRequested); }, _token.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default) .ContinueWith((x) => { messageBus.Publish <AutobernerStopWatchingMessage>(); }, TaskContinuationOptions.OnlyOnFaulted); }
public static void Manual(string gpuType, int powerlimit, int coreclock, int fan, int memoryclock) { for (int i = 0; i < mahm.Header.GpuEntryCount; i++) { if (!fan.Equals(9999)) { try { macm.GpuEntries[i].FanSpeedCur = Convert.ToUInt32(fan); } catch (Exception ex) { macm.GpuEntries[i].FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.None; macm.GpuEntries[i].FanSpeedCur = Convert.ToUInt32(fan); } } if (!powerlimit.Equals(9999)) { try { macm.GpuEntries[i].PowerLimitCur = powerlimit; } catch (Exception powerIssue) { Console.WriteLine(powerIssue.ToString()); } } if (gpuType.Equals("nvidia")) { if (!coreclock.Equals(9999)) { try { macm.GpuEntries[i].CoreClockBoostCur = coreclock * 1000; } catch (Exception coreIssue) { Program.NewMessage(coreIssue.ToString(), ""); } } if (!memoryclock.Equals(9999)) { try { macm.GpuEntries[i].MemoryClockBoostCur = memoryclock * 1000; } catch (Exception memoryIssue) { Console.WriteLine(memoryIssue.ToString()); } } } if (gpuType.Equals("amd")) { if (!coreclock.Equals(9999)) { try { macm.GpuEntries[i].CoreClockCur = Convert.ToUInt32(coreclock * 1000); } catch (Exception coreIssue) { Program.NewMessage(coreIssue.ToString(), ""); } } if (!memoryclock.Equals(9999)) { try { macm.GpuEntries[i].MemoryClockCur = Convert.ToUInt32(memoryclock * 1000); } catch (Exception memoryIssue) { Console.WriteLine(memoryIssue.ToString()); } } } try { // APPLY AFTERBURNER CHANGES macm.CommitChanges(); System.Threading.Thread.Sleep(2000); macm.ReloadAll(); } catch (Exception applySettings) { Program.NewMessage("AfterBurner => Install v4.5 version for ClockTune support", "ERROR"); } } }
public static void ApplyOverclock(IOverclock OC) { Task.Run(() => { while (!MSIconnected) { Thread.Sleep(100); } Process.Start(MSIpath); tryApplyClock: CM = new ControlMemory(); ControlMemory nConf; List <ControlMemoryGpuEntry> gpuEnries = new List <ControlMemoryGpuEntry>(); do { Thread.Sleep(50); CM.ReloadAll(); nConf = CM; if (nConf.GpuEntries.Length > 0) { var vals = ValidGPUS.ToArray(); for (int i = 0; i < vals.Length; i++) { if (vals[i]) { gpuEnries.Add(nConf.GpuEntries[i]); } } } }while (gpuEnries[0].PowerLimitMax == 0); for (int i = 0; i < gpuEnries.Count; i++) { try { gpuEnries[i].PowerLimitCur = SetParam(i, 1, OC.PowLim, gpuEnries[i].PowerLimitMax, gpuEnries[i].PowerLimitMin, gpuEnries[i].PowerLimitDef); } catch { } if (gpuEnries[i].CoreClockBoostMax - gpuEnries[i].CoreClockBoostMin != 0) { try { gpuEnries[i].CoreClockBoostCur = SetParam(i, 1000, OC.CoreClock, gpuEnries[i].CoreClockBoostMax, gpuEnries[i].CoreClockBoostMin, gpuEnries[i].CoreClockBoostDef); } catch { } } else if (gpuEnries[i].CoreClockMax - gpuEnries[i].CoreClockMin != 0) { try { gpuEnries[i].CoreClockCur = SetParam(i, 1000, OC.CoreClock, gpuEnries[i].CoreClockMax, gpuEnries[i].CoreClockMin, gpuEnries[i].CoreClockDef); } catch { } } if (gpuEnries[i].MemoryClockBoostMax - gpuEnries[i].MemoryClockBoostMin != 0) { try { gpuEnries[i].MemoryClockBoostCur = SetParam(i, 1000, OC.MemoryClock, gpuEnries[i].MemoryClockBoostMax, gpuEnries[i].MemoryClockBoostMin, gpuEnries[i].MemoryClockBoostDef); } catch { } } else if (gpuEnries[i].MemoryClockMax - gpuEnries[i].MemoryClockMin != 0) { try { gpuEnries[i].MemoryClockCur = SetParam(i, 1000, OC.MemoryClock, gpuEnries[i].MemoryClockMax, gpuEnries[i].MemoryClockMin, gpuEnries[i].MemoryClockDef); } catch { } } try { if (OC.FanSpeed != null) { if (OC.FanSpeed.Length > i) { gpuEnries[i].FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.None; if (OC.FanSpeed[i] > gpuEnries[i].FanSpeedMax) { gpuEnries[i].FanSpeedCur = gpuEnries[i].FanSpeedMax; } else if (OC.FanSpeed[i] < gpuEnries[i].FanSpeedMin) { gpuEnries[i].FanSpeedCur = gpuEnries[i].FanSpeedMin; } else { gpuEnries[i].FanSpeedCur = Convert.ToUInt32(OC.FanSpeed[i]); } } else { gpuEnries[i].FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.AUTO; } } else { gpuEnries[i].FanFlagsCur = MACM_SHARED_MEMORY_GPU_ENTRY_FAN_FLAG.AUTO; } } catch { } } while (true) { try { CM = nConf; CM.CommitChanges(); Thread.Sleep(3000); if (MSICurrent != null) { var msi = MSICurrent.Value; for (int i = 0; i < OC.PowLim.Length; i++) { if (OC.PowLim != null) { if (msi.PowerLimits[i] != OC.PowLim[i]) { goto tryApplyClock; } } if (OC.CoreClock != null) { if (msi.CoreClocks[i] != OC.CoreClock[i]) { goto tryApplyClock; } } if (OC.MemoryClock != null) { if (msi.MemoryClocks[i] != OC.MemoryClock[i]) { goto tryApplyClock; } } } } else { goto tryApplyClock; } Task.Run(() => OverclockApplied?.Invoke()); return; } catch { } Thread.Sleep(50); } }); }