コード例 #1
0
        private void InitializeOpenCLDevices()
        {
            OpenCLDevices = Utils.GetAllOpenCLDevices(out _cpus);

            if (_cpus.Count > 0)
            {
                Devices.Add(new OpenCLDevice(_cpus[0])
                {
                    ADLAdapterIndex = -2
                });
            }

            if (OpenCLDevices == null)
            {
                return;
            }

            try
            {
                Utils.InitializeADL(OpenCLDevices);
                Utils.InitializeNVML(OpenCLDevices);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <MinerOutputMessage>(new MinerOutputMessage()
                {
                    OutputText = $"Failed to initalize ADL, {ex.Message}{Environment.NewLine}{ex.InnerException}{Environment.NewLine}{ex.StackTrace}", IsError = true
                });
            }

            foreach (var item in OpenCLDevices.Where(x => x.IsUseable))
            {
                Devices.Add(item);
            }

            if (!GpuParameterHandler.ReadParameters(OpenCLDevices))
            {
                GpuParameterHandler.WriteParameters(OpenCLDevices);
            }
        }
コード例 #2
0
        /// <summary>
        /// A miner program elindítása a megadott paraméterekkel.
        /// </summary>
        private void startMining(int window)
        {
            if (OpenCLDevices != null && !SelectedMinerSettings.ApplicationMode.Equals(ApplicationMode.Silent) &&
                !StartMiningButtonContent.Equals("Stop", StringComparison.InvariantCultureIgnoreCase))
            {
                GpuParameterHandler.WriteParameters(OpenCLDevices);
            }

            if (Devices.Count > 0)
            {
                Messenger.Default.Send <MinerOutputMessage>(new MinerOutputMessage()
                {
                    OutputText = "The following devices are initialized:"
                });

                foreach (var item in Devices)
                {
                    Messenger.Default.Send <MinerOutputMessage>(new MinerOutputMessage()
                    {
                        OutputText = $"{item.Name} [w: {item.WorkSize}, i: {item.Intensity}, t: {item.Threads}]", IsError = true
                    });
                }
            }

            if (SelectedMinerSettings.IsCPUMiningEnabled && Utils.CheckInstallation() != CheckDetails.Installed)
            {
                if (Utils.InstallMiners() != InstallDetail.Installed)
                {
                    MessageBoxResult mResult = MessageBox.Show(String.Format("Simple Miner is corrupted, may the antivirus application blocked it. \nIf you already add it as an exception in your antivirus application, please try to download the miner again.\nWould you like to navigate to Simple Miner download page?"), "Miner error", MessageBoxButton.YesNo, MessageBoxImage.Stop);
                    if (mResult == MessageBoxResult.No)
                    {
                        return;
                    }
                    else
                    {
                        Process.Start(Consts.MinerDownload);
                        return;
                    }
                }
            }

            //talán csökkenti a memória fragmentációt
            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            GC.Collect();
            if (IsIdle)
            {
                _minerProcesses.Clear();
                MinerOutputString.Clear();
                saveMinerSettings();

                if (OpenCLDevices != null && OpenCLDevices.Any(x => x.IsEnabled)) //videokártya indítása
                {
                    //if (IsAdministrator)
                    //{
                    //    var exeMinerManager = new ExeManager(Consts.ApplicationPath, Consts.ToolExeFileName);
                    //    exeMinerManager.ExecuteResource("disable \"*VEN_1002&DEV_6*\"");
                    //    Thread.Sleep(1000);
                    //    exeMinerManager.ExecuteResource("enable \"*VEN_1002&DEV_6*\"");
                    //}
                    ThreadPool.QueueUserWorkItem(delegate
                    {
                        var mp = new MinerProcess()
                        {
                            Algorithm = (int)SupportedAlgos.CryptoNight, Devices = OpenCLDevices, MinerType = MinerType.GPU, Settings = SelectedMinerSettings
                        };
                        if (mp.InitalizeMiner(Pools.Where(x => x.IsGPUPool && (x.IsMain || x.IsFailOver)).ToList()))
                        {
                            mp.StartMiner();
                            _minerProcesses.Add(mp);
                        }
                        else
                        {
                            return;
                        }
                    });
                }

                if (SelectedMinerSettings.IsCPUMiningEnabled) //proci indítása
                {
                    var mp = new MinerProcess()
                    {
                        Algorithm = (int)SupportedAlgos.CryptoNight, Devices = OpenCLDevices, MinerType = MinerType.CPU, Settings = SelectedMinerSettings
                    };

                    if (mp.InitalizeMiner(Pools.Where(x => x.IsCPUPool && (x.IsMain || x.IsFailOver)).ToList()))
                    {
                        mp.StartMiner();
                        _minerProcesses.Add(mp);
                    }
                    else
                    {
                        return;
                    }
                }

                IsIdle = false;
            }
            else
            {
                _minerProcesses.ForEach(x => x.StopMiner());
                IsIdle = true;

                if (!isCountDown)
                {
                    Messenger.Default.Send(new MinerOutputMessage()
                    {
                        OutputText = "Mining finished!"
                    });
                }
            }
            RaisePropertyChanged(nameof(IsIdle));
            RaisePropertyChanged(nameof(StartMiningButtonContent));
            RaisePropertyChanged(nameof(IsEnabledCPUThreadAuto));
        }