private void setTimeLimit(BenchmarkPerformanceType type, string numString)
 {
     if (_timeLimits == null) return;
     int value;
     if(Int32.TryParse(numString, out value)) {
         _timeLimits[(int)type] = value;
     }
 }
        public int GetBenchamrktime(BenchmarkPerformanceType benchmarkPerformanceType, DeviceGroupType deviceGroupType)
        {
            if (deviceGroupType == DeviceGroupType.CPU) {
                return CPU[(int)benchmarkPerformanceType];
            }
            if (deviceGroupType == DeviceGroupType.AMD_OpenCL) {
                return AMD[(int)benchmarkPerformanceType];
            }

            return NVIDIA[(int)benchmarkPerformanceType];
        }
Ejemplo n.º 3
0
 private void radioButton_PreciseBenchmark_CheckedChanged(object sender, EventArgs e)
 {
     PerformanceType = BenchmarkPerformanceType.Precise;
 }
Ejemplo n.º 4
0
        public Form_Benchmark(BenchmarkPerformanceType benchmarkPerformanceType = BenchmarkPerformanceType.Standard,
            bool autostart = false,
            //List<ComputeDevice> enabledDevices = null,
            AlgorithmType singleBenchmarkType = AlgorithmType.NONE)
        {
            InitializeComponent();
            this.Icon = NiceHashMiner.Properties.Resources.logo;

            StartMining = false;
            _singleBenchmarkType = singleBenchmarkType;

            benchmarkOptions1.SetPerformanceType(benchmarkPerformanceType);

            // benchmark only unique devices
            devicesListViewEnableControl1.SetIListItemCheckColorSetter(this);
            devicesListViewEnableControl1.SetComputeDevices(ComputeDeviceManager.Avaliable.AllAvaliableDevices);

            // use this to track miner benchmark statuses
            _benchmarkMiners = new List<Miner>();

            InitLocale();

            _benchmarkingTimer = new Timer();
            _benchmarkingTimer.Tick += BenchmarkingTimer_Tick;
            _benchmarkingTimer.Interval = 1000; // 1s

            // name, UUID
            Dictionary<string, string> benchNamesUUIDs = new Dictionary<string, string>();
            // initialize benchmark settings for same cards to only copy settings
            foreach (var cDev in ComputeDeviceManager.Avaliable.AllAvaliableDevices) {
                var plainDevName = cDev.Name;
                if (benchNamesUUIDs.ContainsKey(plainDevName)) {
                    cDev.Enabled = false;
                    cDev.BenchmarkCopyUUID = benchNamesUUIDs[plainDevName];
                } else {
                    benchNamesUUIDs.Add(plainDevName, cDev.UUID);
                    cDev.Enabled = true; // enable benchmark
                    cDev.BenchmarkCopyUUID = null;
                }
            }

            //groupBoxAlgorithmBenchmarkSettings.Enabled = _singleBenchmarkType == AlgorithmType.NONE;
            devicesListViewEnableControl1.Enabled = _singleBenchmarkType == AlgorithmType.NONE;
            devicesListViewEnableControl1.SetDeviceSelectionChangedCallback(devicesListView1_ItemSelectionChanged);

            devicesListViewEnableControl1.SetAlgorithmsListView(algorithmsListView1);
            devicesListViewEnableControl1.IsBenchmarkForm = true;
            devicesListViewEnableControl1.IsSettingsCopyEnabled = true;

            ResetBenchmarkProgressStatus();
            CalcBenchmarkDevicesAlgorithmQueue();
            devicesListViewEnableControl1.ResetListItemColors();

            // to update laclulation status
            devicesListViewEnableControl1.BenchmarkCalculation = this;
            algorithmsListView1.BenchmarkCalculation = this;

            // set first device selected {
            if (ComputeDeviceManager.Avaliable.AllAvaliableDevices.Count > 0) {
                var firstComputedevice = ComputeDeviceManager.Avaliable.AllAvaliableDevices[0];
                algorithmsListView1.SetAlgorithms(firstComputedevice, firstComputedevice.Enabled);
            }

            if (autostart) {
                ExitWhenFinished = true;
                StartStopBtn_Click(null, null);
            }
        }
Ejemplo n.º 5
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // TODO dagger takes a long time
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // AVEMORE needs time to build kernels for each platform and this takes quite a while
            // TODO avemore takes REALLY LONG TIME TO BUILD KERNELS!!!! ADD kernel build checks
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                60, 90, 180
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            // use demo user and disable colorts so we can read from stdout
            var stopAt            = DateTime.Now.AddSeconds(benchmarkTime).ToString("HH:mm");
            var commandLine       = $"--sched-stop {stopAt} -T " + CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var          device        = _miningPairs.Select(kvp => kvp.Device).FirstOrDefault();
            string       currentGPU    = $"GPU{device.ID}";
            const string hashrateAfter = "(avg):";

            bp.CheckData = (string data) =>
            {
                var containsHashRate = data.Contains(currentGPU) && data.Contains(hashrateAfter);
                if (containsHashRate == false)
                {
                    return new BenchmarkResult {
                               Success = false
                    }
                }
                ;

                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, hashrateAfter);
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;
                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, hashrate)
                    },
                    Success = found
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 6
0
 private void radioButton_QuickBenchmark_CheckedChanged(object sender, EventArgs e)
 {
     PerformanceType = BenchmarkPerformanceType.Quick;
 }
        public static int ParseBenchmarkTime(List <int> defaults, MinerBenchmarkTimeSettings timeSetting, IEnumerable <MiningPair> miningPairs, BenchmarkPerformanceType benchmarkType)
        {
            var dict = new Dictionary <BenchmarkPerformanceType, int> {
                { BenchmarkPerformanceType.Quick, defaults[0] },
                { BenchmarkPerformanceType.Standard, defaults[1] },
                { BenchmarkPerformanceType.Precise, defaults[2] },
            };

            return(ParseBenchmarkTime(dict, timeSetting, miningPairs, benchmarkType));
        }
        public Form_Benchmark(BenchmarkPerformanceType benchmarkPerformanceType = BenchmarkPerformanceType.Standard,
                              bool autostart = false)
        {
            InitializeComponent();
            this.Icon = NiceHashMiner.Properties.Resources.logo;

            StartMining = false;

            // clear prev pending statuses
            foreach (var dev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
            {
                foreach (var algo in dev.GetAlgorithmSettings())
                {
                    algo.ClearBenchmarkPendingFirst();
                }
            }

            benchmarkOptions1.SetPerformanceType(benchmarkPerformanceType);

            // benchmark only unique devices
            devicesListViewEnableControl1.SetIListItemCheckColorSetter(this);
            devicesListViewEnableControl1.SetComputeDevices(ComputeDeviceManager.Avaliable.AllAvaliableDevices);

            // use this to track miner benchmark statuses
            _benchmarkMiners = new List <Miner>();

            InitLocale();

            _benchmarkingTimer          = new Timer();
            _benchmarkingTimer.Tick    += BenchmarkingTimer_Tick;
            _benchmarkingTimer.Interval = 1000; // 1s

            //// name, UUID
            //Dictionary<string, string> benchNamesUUIDs = new Dictionary<string, string>();
            //// initialize benchmark settings for same cards to only copy settings
            //foreach (var cDev in ComputeDeviceManager.Avaliable.AllAvaliableDevices) {
            //    var plainDevName = cDev.Name;
            //    if (benchNamesUUIDs.ContainsKey(plainDevName)) {
            //        cDev.Enabled = false;
            //        cDev.BenchmarkCopyUUID = benchNamesUUIDs[plainDevName];
            //    } else if (cDev.Enabled == true) {
            //        benchNamesUUIDs.Add(plainDevName, cDev.UUID);
            //        //cDev.Enabled = true; // enable benchmark
            //        cDev.BenchmarkCopyUUID = null;
            //    }
            //}

            //groupBoxAlgorithmBenchmarkSettings.Enabled = _singleBenchmarkType == AlgorithmType.NONE;
            devicesListViewEnableControl1.Enabled = true;
            devicesListViewEnableControl1.SetDeviceSelectionChangedCallback(devicesListView1_ItemSelectionChanged);

            devicesListViewEnableControl1.SetAlgorithmsListView(algorithmsListView1);
            devicesListViewEnableControl1.IsBenchmarkForm       = true;
            devicesListViewEnableControl1.IsSettingsCopyEnabled = true;

            ResetBenchmarkProgressStatus();
            CalcBenchmarkDevicesAlgorithmQueue();
            devicesListViewEnableControl1.ResetListItemColors();

            // to update laclulation status
            devicesListViewEnableControl1.BenchmarkCalculation = this;
            algorithmsListView1.BenchmarkCalculation           = this;

            // set first device selected {
            if (ComputeDeviceManager.Avaliable.AllAvaliableDevices.Count > 0)
            {
                var firstComputedevice = ComputeDeviceManager.Avaliable.AllAvaliableDevices[0];
                algorithmsListView1.SetAlgorithms(firstComputedevice, firstComputedevice.Enabled);
            }

            if (autostart)
            {
                ExitWhenFinished = true;
                StartStopBtn_Click(null, null);
            }
        }
Ejemplo n.º 9
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var commandLine       = $"--benchmark {AlgorithmName(_algorithmType)} --longstats {benchmarkTime} --devices {_devices} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d; // Not too sure what this is..
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                // data => Average speed (60s): 0.40 g/s
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "s):");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2 && data.Contains("Average speed");

                if (!found)
                {
                    return new BenchmarkResult {
                               Success = false
                    }
                }
                ;

                benchHashes += hashrate;
                benchIters++;

                benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 10
0
        public async override Task <(double speed, bool ok, string msg)> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = 20; // in seconds

            switch (benchmarkType)
            {
            case BenchmarkPerformanceType.Quick:
                benchmarkTime = 20;
                break;

            case BenchmarkPerformanceType.Standard:
                benchmarkTime = 60;
                break;

            case BenchmarkPerformanceType.Precise:
                benchmarkTime = 120;
                break;
            }

            var commandLine = $"--benchmark {AlgorithmName(_algorithmType)} --longstats {benchmarkTime} --devices {_devices} {_extraLaunchParameters}";

            var(binPath, binCwd) = GetBinAndCwdPaths();
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine);

            bp.CheckData = (string data) =>
            {
                return(MinerToolkit.TryGetHashrateAfter(data, "Total:"));
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 11
0
        // TODO account AMD kernel building
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // END prepare config block

            // determine benchmark time
            // settup times
            var openCLCodeGenerationWait = _miningDeviceTypes.Contains(DeviceType.AMD) ? 20 : 0;
            var benchWait     = 5;
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                30, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds


            var url  = StratumServiceHelpers.GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP);
            var algo = AlgorithmName(_algorithmType);

            // this one here might block
            string deviceConfigParams = "";

            try
            {
                deviceConfigParams = await PrepareDeviceConfigs(stop);
            }
            catch (Exception e)
            {
                return(new BenchmarkResult
                {
                    ErrorMessage = e.Message
                });
            }

            var disableDeviceTypes = CommandLineHelpers.DisableDevCmd(_miningDeviceTypes);
            var binPathBinCwdPair  = GetBinAndCwdPaths();
            var binPath            = binPathBinCwdPair.Item1;
            var binCwd             = binPathBinCwdPair.Item2;
            // API port function might be blocking
            var apiPort     = GetAvaliablePort();
            var commandLine = $"-o {url} -u {MinerToolkit.DemoUserBTC} --currency {algo} -i {apiPort} --use-nicehash -p x -r x --benchmark 10 --benchwork {benchmarkTime} --benchwait {benchWait} {deviceConfigParams} {disableDeviceTypes}";

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d; // Not too sure what this is..
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Benchmark Total:");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (found)
                {
                    benchHashes += hashrate;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = found
                });
            };

            // always add 10second extra
            var benchmarkTimeout = TimeSpan.FromSeconds(10 + benchmarkTime + benchWait + openCLCodeGenerationWait);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 12
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var algo              = AlgorithmName(_algorithmType);
            var commandLine       = $"--algo {algo} --devices {_devices} --benchmark --time-limit {benchmarkTime} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes     = 0d;
            var counter         = 0;
            var benchHashResult = 0d;

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (!found)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                benchHashes += hashrate;
                counter++;

                benchHashResult = (benchHashes / counter) * (1 - DevFee * 0.01);

                if (_algorithmType == AlgorithmType.X16R)
                {
                    // Quick adjustment, x16r speeds are overestimated by around 3.5
                    benchHashResult /= 3.5;
                }

                return(new BenchmarkResult {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    }, Success = false
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 13
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            // use demo user and disable the watchdog
            var commandLine       = CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            // disable line readings and read speeds from API
            bp.CheckData = null;

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            double benchHashesSum  = 0;
            double benchHashesSum2 = 0;
            int    benchIters      = 0;
            var    ticks           = benchmarkTime / 10; // on each 10 seconds tick
            var    result          = new BenchmarkResult();

            for (var tick = 0; tick < ticks; tick++)
            {
                if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                {
                    break;
                }
                await Task.Delay(10 * 1000, stop); // 10 seconds delay

                if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                {
                    break;
                }

                var ad = await GetMinerStatsDataAsync();

                if (ad.AlgorithmSpeedsPerDevice.Count == 1)
                {
                    // all single GPUs and single speeds
                    try
                    {
                        if (_algorithmSecondType == AlgorithmType.NONE)
                        {
                            var gpuSpeed = ad.AlgorithmSpeedsPerDevice.Values.FirstOrDefault().FirstOrDefault().Speed;
                            if (gpuSpeed == 0 && IsDaggerOrKawpow(_algorithmType))
                            {
                                continue;
                            }
                            benchHashesSum += gpuSpeed;
                            benchIters++;
                            double benchHashResult = (benchHashesSum / benchIters); // fee is subtracted from API readings
                                                                                    // save each result step
                            result = new BenchmarkResult
                            {
                                AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                    new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                                },
                                Success = benchIters >= (ticks - 1) // allow 1 tick to fail and still consider this benchmark as success
                            };
                        }
                        else
                        {
                            var gpuSpeed  = ad.AlgorithmSpeedsPerDevice.Values.FirstOrDefault().FirstOrDefault().Speed;
                            var gpuSpeed2 = ad.AlgorithmSpeedsPerDevice.Values.FirstOrDefault().LastOrDefault().Speed;
                            if (gpuSpeed == 0 && IsDaggerOrKawpow(_algorithmType))
                            {
                                continue;
                            }
                            if (gpuSpeed2 == 0 && IsDaggerOrKawpow(_algorithmSecondType))
                            {
                                continue;
                            }
                            benchHashesSum  += gpuSpeed;
                            benchHashesSum2 += gpuSpeed2;
                            benchIters++;
                            double benchHashResult = (benchHashesSum / benchIters);   // fee is subtracted from API readings
                                                                                      // save each result step
                            double benchHashResult2 = (benchHashesSum2 / benchIters); // fee is subtracted from API readings
                                                                                      // save each result step
                            result = new BenchmarkResult
                            {
                                AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                    new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult), new AlgorithmTypeSpeedPair(_algorithmSecondType, benchHashResult2)
                                },
                                Success = benchIters >= (ticks - 1) // allow 1 tick to fail and still consider this benchmark as success
                            };
                        }
                    }
                    catch (Exception e)
                    {
                        if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                        {
                            break;
                        }
                        Logger.Error(_logGroup, $"benchmarking error: {e.Message}");
                    }
                }
            }
            // await benchmark task
            await t;

            if (stop.IsCancellationRequested)
            {
                return(t.Result);
            }

            // return API result
            return(result);
        }
Ejemplo n.º 14
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            await Task.Delay(15000, stop);

            var    success = !stop.IsCancellationRequested;
            double speed   = success ? 1000 : 0; // everything is same speed

            // and return our result
            return(new BenchmarkResult
            {
                AlgorithmTypeSpeeds = new List <(AlgorithmType type, double speed)> {
                    (_algorithmType, speed)
                },
                Success = success,
                ErrorMessage = ""
            });
Ejemplo n.º 15
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                60, 90, 180
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var deviceType = _miningPairs.FirstOrDefault().Device.DeviceType == DeviceType.AMD ? "-amd" : "-nvidia";

            // local benchmark
            // TODO hardcoded epoch
            var commandLine       = $"-di {_devices} {_extraLaunchParameters} -benchmark 200 -wd 0 {deviceType}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d;
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPairFirst = data.TryGetHashrateAfter("Eth speed:");
                var hashrateFirst          = hashrateFoundPairFirst.Item1;
                var foundFirst             = hashrateFoundPairFirst.Item2;

                if (foundFirst)
                {
                    benchHashes += hashrateFirst;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                }


                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    }
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 16
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            if (_uuid == "SGminerAvemore")
            {
                await _semaphore.WaitAsync();

                try
                {
                    await BuildOpenCLKernels(stop);
                }
                finally
                {
                    _semaphore.Release();
                }
            }

            return(await base.StartBenchmark(stop, benchmarkType));
        }
Ejemplo n.º 17
0
        //abstract public Task<BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard);
        public virtual async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            using (var tickCancelSource = new CancellationTokenSource())
            {
                // determine benchmark time
                // settup times
                var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                    40, 60, 140
                }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds
                var maxTicks = MinerBenchmarkTimeSettings.ParseBenchmarkTicks(new List <int> {
                    1, 3, 9
                }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);
                var maxTicksEnabled = MinerBenchmarkTimeSettings.MaxTicksEnabled;

                //// use demo user and disable the watchdog
                var commandLine = MiningCreateCommandLine();
                var(binPath, binCwd) = GetBinAndCwdPaths();
                Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
                Logger.Info(_logGroup, $"Benchmarking settings: time={benchmarkTime} ticks={maxTicks} ticksEnabled={maxTicksEnabled}");
                var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());
                // disable line readings and read speeds from API
                bp.CheckData = null;

                var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
                var benchmarkWait    = TimeSpan.FromMilliseconds(500);
                var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop, tickCancelSource.Token);

                var stoppedAfterTicks = false;
                var validTicks        = 0;
                var ticks             = benchmarkTime / 10; // on each 10 seconds tick
                var result            = new BenchmarkResult();
                var benchmarkApiData  = new List <ApiData>();
                for (var tick = 0; tick < ticks; tick++)
                {
                    if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                    {
                        break;
                    }
                    await Task.Delay(10 * 1000, stop); // 10 seconds delay

                    if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                    {
                        break;
                    }

                    var ad = await GetMinerStatsDataAsync();

                    var adTotal     = ad.AlgorithmSpeedsTotal();
                    var isTickValid = adTotal.Count > 0 && adTotal.All(pair => pair.speed > 0);
                    benchmarkApiData.Add(ad);
                    if (isTickValid)
                    {
                        ++validTicks;
                    }
                    if (maxTicksEnabled && validTicks >= maxTicks)
                    {
                        stoppedAfterTicks = true;
                        break;
                    }
                }
                // await benchmark task
                if (stoppedAfterTicks)
                {
                    try
                    {
                        tickCancelSource.Cancel();
                    }
                    catch
                    {}
                }
                await t;
                if (stop.IsCancellationRequested)
                {
                    return(t.Result);
                }

                // calc speeds
                // TODO calc std deviaton to reduce invalid benches
                try
                {
                    var nonZeroSpeeds = benchmarkApiData.Where(ad => ad.AlgorithmSpeedsTotal().Count > 0 && ad.AlgorithmSpeedsTotal().All(pair => pair.speed > 0))
                                        .Select(ad => (ad, ad.AlgorithmSpeedsTotal().Count)).ToList();
                    var speedsFromTotals = new List <(AlgorithmType type, double speed)>();
                    if (nonZeroSpeeds.Count > 0)
                    {
                        var maxAlgoPiarsCount = nonZeroSpeeds.Select(adCount => adCount.Count).Max();
                        var sameCountApiDatas = nonZeroSpeeds.Where(adCount => adCount.Count == maxAlgoPiarsCount).Select(adCount => adCount.ad).ToList();
                        var firstPair         = sameCountApiDatas.FirstOrDefault();
                        var speedSums         = firstPair.AlgorithmSpeedsTotal().Select(pair => new KeyValuePair <AlgorithmType, double>(pair.type, 0.0)).ToDictionary(x => x.Key, x => x.Value);
                        // sum
                        foreach (var ad in sameCountApiDatas)
                        {
                            foreach (var pair in ad.AlgorithmSpeedsTotal())
                            {
                                speedSums[pair.type] += pair.speed;
                            }
                        }
                        // average
                        foreach (var algoId in speedSums.Keys.ToArray())
                        {
                            speedSums[algoId] /= sameCountApiDatas.Count;
                        }
                        result = new BenchmarkResult
                        {
                            AlgorithmTypeSpeeds = firstPair.AlgorithmSpeedsTotal().Select(pair => (pair.type, speedSums[pair.type])).ToList(),
                            Success             = true
                        };
                    }
                }
                catch (Exception e)
                {
                    Logger.Warn(_logGroup, $"benchmarking AlgorithmSpeedsTotal error {e.Message}");
                }

                // return API result
                return(result);
            }
        }
Ejemplo n.º 18
0
        public async override Task <(double speed, bool ok, string msg)> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = 90; // in seconds

            switch (benchmarkType)
            {
            case BenchmarkPerformanceType.Quick:
                benchmarkTime = 60;
                break;

            case BenchmarkPerformanceType.Standard:
                benchmarkTime = 90;
                break;

            case BenchmarkPerformanceType.Precise:
                benchmarkTime = 120;
                break;
            }

            // use demo user and disable colorts so we can read from stdout
            var commandLine = CreateCommandLine(MinerToolkit.DemoUser) + " --disable_colors";

            var(binPath, binCwd) = GetBinAndCwdPaths();
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine);

            double benchHashesSum   = 0;
            double benchHashResult  = 0;
            int    benchIters       = 0;
            int    targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 30d));

            string afterAlgoSpeed = $"{AlgoName}:";

            bp.CheckData = (string data) =>
            {
                var containsHashRate = data.Contains(afterAlgoSpeed) && data.Contains("GPU");
                if (containsHashRate == false)
                {
                    return(benchHashResult, false);
                }
                var(hashrate, found) = MinerToolkit.TryGetHashrateAfter(data, afterAlgoSpeed);
                if (!found)
                {
                    return(benchHashResult, false);
                }

                // sum and return
                benchHashesSum += hashrate;
                benchIters++;

                benchHashResult = (benchHashesSum / benchIters) * (1 - DevFee);

                var isFinished = benchIters >= targetBenchIters;
                return(benchHashResult, isFinished);
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 19
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                30, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var commandLine       = $"--benchmark 200 {_cudaDevices} {_openCLDevices} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes     = 0d;
            var benchIters      = 0;
            var benchHashResult = 0d;  // Not too sure what this is..

            var lookFor = _miningPairs.Any(mp => mp.Device.DeviceType == DeviceType.AMD) ? "cl0" : "cu0";

            bp.CheckData = (string data) =>
            {
                double hashrate = 0d;
                bool   found    = false;
                for (int i = 0; i < 10; i++)
                {
                    var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, $"A{i}");
                    hashrate = hashrateFoundPair.Item1;
                    found    = hashrateFoundPair.Item2;
                    if (found)
                    {
                        break;
                    }
                }

                if (hashrate > 0 && found && data.Contains(lookFor))
                {
                    benchHashes += hashrate;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = false
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 20
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var commandLine       = CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d;
            var targetBenchIters = 2; //Math.Max(1, (int)Math.Floor(benchTime / 20d));

            bp.CheckData = (data) =>
            {
                var hashrateFoundPair = data.ToLower().TryGetHashrateAfter("]:");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (data.Contains("l-shr") && data.Contains("GPU[") && found && hashrate > 0)
                {
                    benchHashes += hashrate;
                    benchIters++;
                    benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                }
                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var timeout   = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchWait = TimeSpan.FromMilliseconds(500);
            var t         = MinerToolkit.WaitBenchmarkResult(bp, timeout, benchWait, stop);

            return(await t);
        }
 internal static void BenchmarkDeviceAlgorithms(ComputeDevice computeDevice, IEnumerable <AlgorithmContainer> algorithmContainers, BenchmarkPerformanceType performance, bool startMiningAfterBenchmark = false)
 {
     if (algorithmContainers.Count() == 0)
     {
         return;                                   // no algorithms skip
     }
     if (BenchmarkingHandlers.TryGetValue(computeDevice, out var benchmarkHandler))
     {
         // update algorithms
         Logger.Debug("BenchmarkingComputeDeviceHandler", $"Already benchmarking");
         // TODO UPDATE algorithms and skip creating new task
         return;
     }
     // create new
     Task.Run(async() => await CreateBenchmarkingTask(computeDevice, algorithmContainers, performance, startMiningAfterBenchmark));
 }
        public static int ParseBenchmarkTime(Dictionary <BenchmarkPerformanceType, int> defaults, MinerBenchmarkTimeSettings timeSetting, IEnumerable <MiningPair> miningPairs, BenchmarkPerformanceType benchmarkType)
        {
            try
            {
                if (timeSetting?.UseUserSettings ?? false)
                {
                    // TimePerAlgorithm has #1 priority
                    if (timeSetting.PerAlgorithm != null && timeSetting.PerAlgorithm.ContainsKey(benchmarkType))
                    {
                        var pairTypeTimeout = timeSetting.PerAlgorithm[benchmarkType];
                        var algorithmName   = miningPairs.FirstOrDefault()?.Algorithm?.AlgorithmName ?? "";
                        if (pairTypeTimeout != null && !string.IsNullOrEmpty(algorithmName) && pairTypeTimeout.ContainsKey(algorithmName))
                        {
                            return(pairTypeTimeout[algorithmName]);
                        }
                    }
                    // TimePerType has #2 priority
                    return(timeSetting.General[benchmarkType]);
                }
            } catch (Exception e)
            {
                Logger.Error("ParseBenchmarkTime", $"ParseBenchmarkTime failed: {e.Message}");
            }

            return(defaults[benchmarkType]);
        }
        private static async Task CreateBenchmarkingTask(ComputeDevice computeDevice, IEnumerable <AlgorithmContainer> algorithmContainers, BenchmarkPerformanceType performance, bool startMiningAfterBenchmark = false)
        {
            // create new
            var newBenchmarkHandler = new BenchmarkingComputeDeviceHandler(computeDevice)
            {
                PerformanceType           = performance,
                StartMiningAfterBenchmark = startMiningAfterBenchmark
            };

            newBenchmarkHandler.AppendForBenchmarking(algorithmContainers);
            await newBenchmarkHandler.Benchmark();
        }
Ejemplo n.º 24
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                40, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var urlWithPort = StratumServiceHelpers.GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP);
            var algo        = AlgorithmName(_algorithmType);

            var commandLine       = $"--algo {algo} --url={urlWithPort} --user {MinerToolkit.DemoUserBTC} --devices {_devices} {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d;      // Not too sure what this is..
            var after            = $"GPU#"; //if multiple benchmark add gpu cuda id
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                var hasHashRate = data.Contains(after) && data.Contains("-");

                if (!hasHashRate)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                var hashrateFoundPair = data.TryGetHashrateAfter("-");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                benchHashes += hashrate;
                benchIters++;

                benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 25
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var algo        = AlgorithmName(_algorithmType);
            var timeLimit   = _noTimeLimitOption ? "" : $"--time-limit {benchmarkTime}";
            var commandLine = $"--algo={algo} --benchmark {timeLimit} --devices {_devices} {_extraLaunchParameters}";

            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine);


            var errorList = new List <string> {
                "Unknown algo parameter", "Cuda error", "Non-existant CUDA device"
            };
            var errorMsg = "";

            var benchHashes     = 0d;
            var benchIters      = 0;
            var benchHashResult = 0d;  // Not too sure what this is..
            // TODO fix this tick based system
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            // TODO implement fallback average, final benchmark
            bp.CheckData = (string data) => {
                // check if error
                foreach (var err in errorList)
                {
                    if (data.Contains(err))
                    {
                        bp.TryExit();
                        errorMsg = data;
                        return(new BenchmarkResult {
                            Success = false, ErrorMessage = errorMsg
                        });
                    }
                }

                //return MinerToolkit.TryGetHashrateAfter(data, "Benchmark:"); // TODO add option to read totals
                var hashrateFinalFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Benchmark:"); // TODO add option to read totals
                var hashrateFinal          = hashrateFinalFoundPair.Item1;
                var finalFound             = hashrateFinalFoundPair.Item2;

                if (finalFound)
                {
                    return(new BenchmarkResult
                    {
                        AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                            new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                        },
                        Success = true
                    });
                }
                // no final calculate avg speed
                var hashrateTotalFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total:"); // TODO add option to read totals
                var hashrateTotal          = hashrateTotalFoundPair.Item1;
                var totalFound             = hashrateTotalFoundPair.Item2;
                if (totalFound)
                {
                    benchHashes += hashrateTotal;
                    benchIters++;
                    benchHashResult = (benchHashes / benchIters); // * (1 - DevFee * 0.01);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 26
0
 abstract public Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard);
Ejemplo n.º 27
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            int benchmarkTime;

            switch (benchmarkType)
            {
            case BenchmarkPerformanceType.Quick:
                benchmarkTime = 20;
                break;

            case BenchmarkPerformanceType.Precise:
                benchmarkTime = 120;
                break;

            default:
                benchmarkTime = 60;
                break;
            }

            var commandLine       = CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d; // Not too sure what this is..
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total speed:");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (found)
                {
                    benchHashes += hashrate;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 28
0
 private void radioButton_StandardBenchmark_CheckedChanged(object sender, EventArgs e)
 {
     PerformanceType = BenchmarkPerformanceType.Standard;
 }
Ejemplo n.º 29
0
        public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var isDaggerNvidia = _miningPairs.Any(mp => mp.Algorithm.FirstAlgorithmType == AlgorithmType.DaggerHashimoto) && _miningPairs.Any(mp => mp.Device.DeviceType == DeviceType.NVIDIA);
            var defaultTimes   = isDaggerNvidia ? new List <int> {
                180, 240, 300
            } : new List <int> {
                90, 120, 180
            };
            int benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(defaultTimes, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);
            var isLhr         = isDaggerNvidia && IsLhrGPU(_miningPairs.Select(mp => mp.Device).FirstOrDefault());

            using var tickCancelSource = new CancellationTokenSource();
            // determine benchmark time
            // settup times


            var maxTicks = MinerBenchmarkTimeSettings.ParseBenchmarkTicks(new List <int> {
                1, 3, 9
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);

            //// use demo user and disable the watchdog
            var commandLine = MiningCreateCommandLine();

            var(binPath, binCwd) = GetBinAndCwdPaths();
            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            Logger.Info(_logGroup, $"Benchmarking settings: time={benchmarkTime} ticks={maxTicks}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            // disable line readings and read speeds from API
            bp.CheckData = null;

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop, tickCancelSource.Token);

            var stoppedAfterTicks = false;
            var validTicks        = 0;
            var ticks             = benchmarkTime / 10; // on each 10 seconds tick
            var result            = new BenchmarkResult();
            var benchmarkApiData  = new List <ApiData>();
            var delay             = (benchmarkTime / maxTicks) * 1000;

            for (var tick = 0; tick < ticks; tick++)
            {
                if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                {
                    break;
                }
                await Task.Delay(delay, stop); // 10 seconds delay

                if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested)
                {
                    break;
                }

                var ad = await GetMinerStatsDataAsync();

                var adTotal     = ad.AlgorithmSpeedsTotal();
                var isTickValid = adTotal.Count > 0 && adTotal.All(pair => pair.speed > 0);
                benchmarkApiData.Add(ad);
                if (isTickValid)
                {
                    ++validTicks;
                }
                if (validTicks >= maxTicks)
                {
                    stoppedAfterTicks = true;
                    break;
                }
            }
            // await benchmark task
            if (stoppedAfterTicks)
            {
                try
                {
                    tickCancelSource.Cancel();
                }
                catch
                { }
            }
            await t;

            if (stop.IsCancellationRequested)
            {
                return(t.Result);
            }

            // calc speeds
            // TODO calc std deviaton to reduce invalid benches
            try
            {
                var nonZeroSpeeds = benchmarkApiData.Where(ad => ad.AlgorithmSpeedsTotal().Count > 0 && ad.AlgorithmSpeedsTotal().All(pair => pair.speed > 0))
                                    .Select(ad => (ad, ad.AlgorithmSpeedsTotal().Count)).ToList();
                var speedsFromTotals = new List <(AlgorithmType type, double speed)>();
                if (nonZeroSpeeds.Count > 0)
                {
                    var maxAlgoPiarsCount = nonZeroSpeeds.Select(adCount => adCount.Count).Max();
                    var sameCountApiDatas = nonZeroSpeeds.Where(adCount => adCount.Count == maxAlgoPiarsCount).Select(adCount => adCount.ad).ToList();
                    var firstPair         = sameCountApiDatas.FirstOrDefault();
                    // sum
                    var values = sameCountApiDatas.SelectMany(x => x.AlgorithmSpeedsTotal()).Select(pair => pair.speed).ToArray();
                    var value  = isLhr ? values.Max() : values.Sum() / values.Length;
                    result = new BenchmarkResult
                    {
                        AlgorithmTypeSpeeds = firstPair.AlgorithmSpeedsTotal().Select(pair => (pair.type, value)).ToList(),
                        Success             = true
                    };
                }
            }
            catch (Exception e)
            {
                Logger.Warn(_logGroup, $"benchmarking AlgorithmSpeedsTotal error {e.Message}");
            }

            // return API result
            return(result);
        }
Ejemplo n.º 30
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                30, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var algoName    = AlgorithmName(_algorithmType);
            var logfileName = $"{_devices}_{algoName}_bench.txt";

            var commandLine       = CreateCommandLine(DemoUser.BTC) + $" --nocolor --logfile {logfileName}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            //first delete benchmark file if it exists
            File.Delete(Path.Combine(binCwd, logfileName));

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            bp.CheckData = (string data) =>
            {
                // we can't read from stdout or stderr, read from logs later
                return(new BenchmarkResult());
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(1000);
            var t = await MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            // look for log file and parse that
            try
            {
                var benchHashes      = 0d;
                var benchIters       = 0;
                var benchHashResult  = 0d;
                var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 10d));

                var logFullPath = Path.Combine(binCwd, logfileName);
                var lines       = File.ReadLines(logFullPath);
                foreach (var line in lines)
                {
                    var hashrateFoundPair = BenchmarkHelpers.TryGetHashrateAfter(line, "I/s");
                    var hashrate          = hashrateFoundPair.Item1;
                    var found             = hashrateFoundPair.Item2;

                    if (found)
                    {
                        benchHashes += hashrate;
                        benchIters++;

                        benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                    }
                }

                var success = benchHashResult > 0d;
                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = success
                });
            }
            catch (Exception e)
            {
                Logger.Error(_logGroup, $"Benchmarking failed: {e.Message}");
            }
            return(t);
        }
Ejemplo n.º 31
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                30, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            var urlWithPort = GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP);
            var split       = urlWithPort.Split(':');
            var url         = split[1].Substring(2, split[1].Length - 2);
            var port        = split[2];
            var algo        = AlgorithmName(_algorithmType);

            var commandLine       = $"-uri {algo}://{_username}@{url}:{port} {_devices} -watchdog=false {_extraLaunchParameters}";
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            var benchHashes      = 0d;
            var benchIters       = 0;
            var benchHashResult  = 0d; // Not too sure what this is..
            var targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 20d));

            bp.CheckData = (string data) =>
            {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;

                if (found)
                {
                    benchHashes += hashrate;
                    benchIters++;

                    benchHashResult = (benchHashes / benchIters) * (1 - DevFee * 0.01);
                }

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 32
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            // determine benchmark time
            // settup times
            var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                               // in seconds

            // use demo user and disable the watchdog
            var commandLine       = CreateCommandLine(MinerToolkit.DemoUserBTC);
            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());

            double benchHashesSum   = 0;
            double benchHashResult  = 0;
            int    benchIters       = 0;
            int    targetBenchIters = Math.Max(1, (int)Math.Floor(benchmarkTime / 30d));

            // TODO implement fallback average, final benchmark
            bp.CheckData = (string data) => {
                var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total Speed:");
                var hashrate          = hashrateFoundPair.Item1;
                var found             = hashrateFoundPair.Item2;
                if (!found)
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                               }, Success = false
                    }
                }
                ;

                // sum and return
                benchHashesSum += hashrate;
                benchIters++;

                benchHashResult = (benchHashesSum / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = benchIters >= targetBenchIters
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }
Ejemplo n.º 33
0
        public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard)
        {
            var benchmarkTime = MinerPluginToolkitV1.Configs.MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> {
                20, 60, 120
            }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType);                                                                                                                            // in seconds

            var algo        = AlgorithmName(_algorithmType);
            var commandLine = $"--algo={algo} --benchmark --time-limit {benchmarkTime} {_extraLaunchParameters}";

            var binPathBinCwdPair = GetBinAndCwdPaths();
            var binPath           = binPathBinCwdPair.Item1;
            var binCwd            = binPathBinCwdPair.Item2;

            Logger.Info(_logGroup, $"Benchmarking started with command: {commandLine}");
            var bp = new BenchmarkProcess(binPath, binCwd, commandLine, GetEnvironmentVariables());
            // TODO benchmark process add after benchmark

            double benchHashesSum  = 0;
            double benchHashResult = 0;
            int    benchIters      = 0;
            var    foundBench      = false;

            bp.CheckData = (string data) => {
                if (!data.Contains("Total:"))
                {
                    return new BenchmarkResult {
                               AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                   new AlgorithmTypeSpeedPair(_algorithmType, 0)
                               }, Success = false
                    }
                }
                ;
                var hashrateFoundPairAvg = MinerToolkit.TryGetHashrateAfter(data, "H, ");
                var hashrateAvg          = hashrateFoundPairAvg.Item1;
                var foundAvg             = hashrateFoundPairAvg.Item2;
                if (!foundAvg)
                {
                    var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Benchmark: ");

                    var hashrate = hashrateFoundPair.Item1;
                    foundBench = hashrateFoundPair.Item2;
                    if (foundBench && hashrate != 0)
                    {
                        benchHashResult = hashrate * (1 - DevFee * 0.01);

                        return(new BenchmarkResult
                        {
                            AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                                new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                            },
                            Success = benchHashResult != 0
                        });
                    }
                }

                // sum and return
                benchHashesSum += hashrateAvg;
                benchIters++;

                benchHashResult = (benchHashesSum / benchIters) * (1 - DevFee * 0.01);

                return(new BenchmarkResult
                {
                    AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> {
                        new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult)
                    },
                    Success = foundBench
                });
            };

            var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5);
            var benchmarkWait    = TimeSpan.FromMilliseconds(500);
            var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop);

            return(await t);
        }