private void OverClock(INTMinerContext root, IGpuProfile data) { #if DEBUG NTStopwatch.Start(); #endif if (root.GpuSet.TryGetGpu(data.Index, out IGpu gpu)) { // fanSpeed == -1表示开源自动温控 int fanSpeed = data.IsAutoFanSpeed ? -1 : data.Cool; root.GpuSet.OverClock.OverClock(data.Index, data.CoreClockDelta, data.CoreVoltage, data.MemoryClockDelta, data.MemoryVoltage, data.PowerCapacity, data.TempLimit, fanSpeed); if (data.Index == NTMinerContext.GpuAllId) { NTMinerConsole.UserOk($"统一超频:{data.ToOverClockString()}"); } else { NTMinerConsole.UserOk($"GPU{gpu.Index}超频:{data.ToOverClockString()}"); } 2.SecondsDelay().ContinueWith(t => { root.GpuSet.OverClock.RefreshGpuState(data.Index); }); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(OverClock)}"); } #endif }
private void OverClock(INTMinerContext ntminerContext, IGpuProfile data) { #if DEBUG NTStopwatch.Start(); #endif if (ntminerContext.GpuSet.TryGetGpu(data.Index, out IGpu gpu)) { ntminerContext.GpuSet.OverClock.OverClock(gpuIndex: data.Index, OverClockValue.Create(data)); if (data.Index == NTMinerContext.GpuAllId) { NTMinerConsole.UserOk($"统一超频:{data.ToOverClockString()}"); } else { NTMinerConsole.UserOk($"GPU{gpu.Index}超频:{data.ToOverClockString()}"); } 2.SecondsDelay().ContinueWith(t => { ntminerContext.GpuSet.OverClock.RefreshGpuState(data.Index); }); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(OverClock)}"); } #endif }
public AMDGpuSet() { #if DEBUG NTStopwatch.Start(); #endif this.Properties = new List<GpuSetProperty>(); this.OverClock = new GpuOverClock(adlHelper); VirtualRoot.AddEventPath<AppExitEvent>("程序退出时调用adlHelper.Close", LogEnum.None, message => { adlHelper.Close(); }, this.GetType()); int deviceCount = 0; deviceCount = adlHelper.GpuCount; for (int i = 0; i < deviceCount; i++) { var atiGpu = adlHelper.GetAtiGPU(i); string name = atiGpu.AdapterName; // short gpu name if (!string.IsNullOrEmpty(name)) { name = name.Replace("Radeon (TM) RX ", string.Empty); name = name.Replace("Radeon RX ", string.Empty); } var gpu = Gpu.Create(GpuType.AMD, i, atiGpu.BusNumber.ToString(), name); gpu.TotalMemory = adlHelper.GetTotalMemory(i); _gpus.Add(i, gpu); } if (deviceCount > 0) { this._driverVersion = adlHelper.GetDriverVersion(); this.Properties.Add(new GpuSetProperty(GpuSetProperty.DRIVER_VERSION, "驱动版本", DriverVersion)); const ulong minG = 5 * NTKeyword.ULongG; bool has470 = _gpus.Any(a => a.Key != NTMinerContext.GpuAllId && a.Value.TotalMemory < minG); if (has470) { Dictionary<string, string> kvs = new Dictionary<string, string> { ["GPU_MAX_ALLOC_PERCENT"] = "100", ["GPU_MAX_HEAP_SIZE"] = "100", ["GPU_SINGLE_ALLOC_PERCENT"] = "100" }; foreach (var kv in kvs) { var property = new GpuSetProperty(kv.Key, kv.Key, kv.Value); this.Properties.Add(property); } Task.Factory.StartNew(() => { OverClock.RefreshGpuState(NTMinerContext.GpuAllId); foreach (var kv in kvs) { Environment.SetEnvironmentVariable(kv.Key, kv.Value); } }); } else { Task.Factory.StartNew(() => { OverClock.RefreshGpuState(NTMinerContext.GpuAllId); }); } } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
private static bool NvmlInit() { if (_isNvmlInited) { return(_isNvmlInited); } lock (_locker) { if (_isNvmlInited) { return(_isNvmlInited); } try { #if DEBUG NTStopwatch.Start(); #endif if (!Directory.Exists(_nvsmiDir)) { Directory.CreateDirectory(_nvsmiDir); } if (!File.Exists(_nvmlDllFileFullName) && File.Exists(_nvmlDllFileFullName2)) { File.Copy(_nvmlDllFileFullName2, _nvmlDllFileFullName); } NvmlNativeMethods.SetDllDirectory(_nvsmiDir); var nvmlReturn = NvmlNativeMethods.nvmlInit(); NvmlNativeMethods.SetDllDirectory(null); _isNvmlInited = nvmlReturn == nvmlReturn.Success; // 没什么用,做个防御 if (!_isNvmlInited) { _nvmlInitFailCount++; if (_nvmlInitFailCount >= 10) { _isNvmlInited = true; } } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {nameof(NvmlHelper)}.{nameof(NvmlInit)}()"); } #endif return(_isNvmlInited); } catch (Exception e) { Logger.ErrorDebugLine(e); } return(false); } }
public MinerProfileIndex() { if (WpfUtil.IsInDesignMode) { return; } #if DEBUG NTStopwatch.Start(); #endif this.Vm = new MinerProfileIndexViewModel(); this.DataContext = this.Vm; InitializeComponent(); this.OnLoaded(window => { window.BuildEventPath <LocalContextReInitedEventHandledEvent>("上下文视图模型集刷新后刷新界面上的popup", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: message => { UIThread.Execute(() => { if (Vm.MinerProfile.MineWork != null) { return; } if (this.PopupKernel.Child != null && this.PopupKernel.IsOpen) { OpenKernelPopup(); } if (this.PopupMainCoinPool.Child != null && this.PopupMainCoinPool.IsOpen) { OpenMainCoinPoolPopup(); } if (this.PopupMainCoinPool1.Child != null && this.PopupMainCoinPool1.IsOpen) { OpenMainCoinPool1Popup(); } if (this.PopupMainCoin != null && this.PopupMainCoin.IsOpen) { OpenMainCoinPopup(); } if (this.PopupMainCoinWallet != null && this.PopupMainCoinWallet.IsOpen) { OpenMainCoinWalletPopup(); } }); }); }); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public void LoadGpuState() { #if DEBUG NTStopwatch.Start(); #endif for (int i = 0; i < Count; i++) { LoadGpuState(i); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.{nameof(LoadGpuState)}"); } #endif }
private static bool NvmlInit() { if (_isNvmlInited) { return(_isNvmlInited); } lock (_locker) { if (_isNvmlInited) { return(_isNvmlInited); } try { #if DEBUG NTStopwatch.Start(); #endif if (!File.Exists(_system32nvmlDllFileFullName) && File.Exists(_nvmlDllFileFullName)) { File.Copy(_nvmlDllFileFullName, _system32nvmlDllFileFullName); } var nvmlReturn = NvmlNativeMethods.NvmlInit(); _isNvmlInited = nvmlReturn == nvmlReturn.Success; #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {nameof(NvmlHelper)}.{nameof(NvmlInit)}()"); } #endif return(_isNvmlInited); } catch (Exception e) { Logger.ErrorDebugLine(e); _isNvmlInited = true; } return(false); } }
private void OverClock(INTMinerContext root, IGpuProfile data) { #if DEBUG NTStopwatch.Start(); #endif if (root.GpuSet.TryGetGpu(data.Index, out IGpu gpu)) { IOverClock overClock = root.GpuSet.OverClock; if (!data.IsAutoFanSpeed) { overClock.SetFanSpeed(data.Index, data.Cool); } overClock.SetCoreClock(data.Index, data.CoreClockDelta, data.CoreVoltage); overClock.SetMemoryClock(data.Index, data.MemoryClockDelta, data.MemoryVoltage); overClock.SetPowerLimit(data.Index, data.PowerCapacity); overClock.SetTempLimit(data.Index, data.TempLimit); if (data.Index == NTMinerContext.GpuAllId) { NTMinerConsole.UserOk($"统一超频:{data.ToOverClockString()}"); } else { NTMinerConsole.UserOk($"GPU{gpu.Index}超频:{data.ToOverClockString()}"); } 1.SecondsDelay().ContinueWith(t => { overClock.RefreshGpuState(data.Index); }); } #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.OverClock"); } #endif }
public MainWindow() { if (WpfUtil.IsInDesignMode) { return; } if (!NTMinerConsole.IsEnabled) { NTMinerConsole.Enable(); } this.Vm = new MainWindowViewModel(); this.DataContext = Vm; this.MinHeight = 430; this.MinWidth = 640; this.Width = AppRoot.MainWindowWidth; this.Height = AppRoot.MainWindowHeight; #if DEBUG NTStopwatch.Start(); #endif ConsoleWindow.Instance.MouseDown += (sender, e) => { MoveConsoleWindow(); }; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; this.Loaded += (sender, e) => { ConsoleTabItemTopBorder.Margin = new Thickness(0, ConsoleTabItem.ActualHeight - 1, 0, 0); MoveConsoleWindow(); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); }; InitializeComponent(); _leftDrawerGripWidth = LeftDrawerGrip.Width; _btnOverClockBackground = BtnOverClock.Background; // 下面几行是为了看见设计视图 this.ResizeCursors.Visibility = Visibility.Visible; this.HideLeftDrawerGrid(); // 上面几行是为了看见设计视图 DateTime lastGetServerMessageOn = DateTime.MinValue; // 切换了主界面上的Tab时 this.MainTabControl.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 #region var selectedItem = MainTabControl.SelectedItem; if (selectedItem == TabItemSpeedTable) { if (SpeedTableContainer.Child == null) { SpeedTableContainer.Child = GetSpeedTable(); } } else if (selectedItem == TabItemMessage) { if (MessagesContainer.Child == null) { MessagesContainer.Child = new Messages(); } } else if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } RpcRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage); if (selectedItem == TabItemMessage) { if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now) { lastGetServerMessageOn = DateTime.Now; VirtualRoot.Execute(new LoadNewServerMessageCommand()); } } if (selectedItem == ConsoleTabItem) { ConsoleTabItemTopBorder.Visibility = Visibility.Visible; } else { ConsoleTabItemTopBorder.Visibility = Visibility.Collapsed; } #endregion }; this.IsVisibleChanged += (sender, e) => { #region if (this.IsVisible) { NTMinerContext.IsUiVisible = true; } else { NTMinerContext.IsUiVisible = false; } MoveConsoleWindow(); #endregion }; this.StateChanged += (s, e) => { #region if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; } else { ResizeCursors.Visibility = Visibility.Visible; } MoveConsoleWindow(); #endregion }; bool isLeftClosed = false; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { if (this.ConsoleRectangle.IsVisible) { if (isLeftClosed != (LeftDrawerGrip.Width == _leftDrawerGripWidth)) { ConsoleWindowFit(); } } else { isLeftClosed = LeftDrawerGrip.Width == _leftDrawerGripWidth; } }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; if (this.Width < 860) { NTMinerConsole.UserWarn("左侧面板已折叠,可点击侧边的'开始挖矿'按钮展开。"); } this.SizeChanged += (s, e) => { #region if (this.Width < 860) { this.CloseLeftDrawer(); this.BtnAboutNTMiner.Visibility = Visibility.Collapsed; } else { this.OpenLeftDrawer(isSizeChanged: true); this.BtnAboutNTMiner.Visibility = Visibility.Visible; } if (!this.ConsoleRectangle.IsVisible) { if (e.WidthChanged) { ConsoleWindow.Instance.Width = e.NewSize.Width; } if (e.HeightChanged) { ConsoleWindow.Instance.Height = e.NewSize.Height; } } #endregion }; NotiCenterWindow.Bind(this, ownerIsTopmost: true); this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; VirtualRoot.BuildCmdPath <TopmostCommand>(path: message => { UIThread.Execute(() => { if (!this.Topmost) { this.Topmost = true; } }); }, this.GetType()); VirtualRoot.BuildCmdPath <UnTopmostCommand>(path: message => { UIThread.Execute(() => { if (this.Topmost) { this.Topmost = false; } }); }, this.GetType()); VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(path: message => { UIThread.Execute(() => { if (message.IsAutoNoUi) { SwitchToNoUi(); } else { this.Close(); } }); }, location: this.GetType()); this.BuildEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式", LogEnum.DevConsole, path: message => { if (NTMinerContext.IsUiVisible && NTMinerContext.Instance.MinerProfile.IsAutoNoUi && NTMinerContext.Instance.IsMining) { if (NTMinerContext.MainWindowRendedOn.AddMinutes(NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes) < message.BornOn) { VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"挖矿中界面展示{NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置"); VirtualRoot.Execute(new CloseMainWindowCommand(isAutoNoUi: true)); } } }, location: this.GetType()); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }