public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { using (var tickCancelSource = new CancellationTokenSource()) { var workers = string.Join(",", _miningPairs.Select((_, i) => $@"""{i}""")); var workersReset = @"{""id"":1,""method"":"" workers.reset"",""params"":[__WORKERS__]}".Replace("__WORKERS__", workers); // determine benchmark time // settup times var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> { 20, 40, 60 }, 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 ExecuteCommand(workersReset, stop); await ExcavatorTaskHelpers.TryDelay(TimeSpan.FromSeconds(10), stop); if (t.IsCompleted || t.IsCanceled || stop.IsCancellationRequested) { break; } // get speeds var ad = await GetMinerStatsDataAsyncPrivate(stop); 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); } }
// 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); }
public async override Task <BenchmarkResult> 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.DemoUserBTC) + " --disable_colors"; 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)); string afterAlgoSpeed = $"{AlgoName}:"; bp.CheckData = (string data) => { var containsHashRate = data.Contains(afterAlgoSpeed) && data.Contains("GPU"); if (containsHashRate == false) { return new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = false } } ; var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, afterAlgoSpeed); 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); }
public override async Task <BenchmarkResult> 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 algo = AlgorithmName(_algorithmType); ////UNTIL BENCHMARKING FIXED ON MINER SIDE var url = GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP); var commandLine = $"--algo {algo} --url {url} --user {_username} --devices {_devices} {_extraLaunchParameters} --no-watchdog --time-limit {benchmarkTime}"; /////// //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) => { ////UNTIL BENCHMARKING FIXED ON MINER SIDE if (!data.Contains("[ OK ]")) { return new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = false } } ; var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, " - "); /////// //var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, "Total"); var hashrate = hashrateFoundPair.Item1; var found = hashrateFoundPair.Item2; if (data.Contains("Time limit is reached.")) { return new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = true } } ; 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); ////UNTIL BENCHMARKING FIXED ON MINER SIDE //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); }
public async override Task <(double speed, bool ok, string msg)> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { var numOfGpus = 2; //MUST BE SET CORRECTLY OTHERWISE BENCHMARKING WON't WORK (all cards are combined currently) var avgRet = 0.0; var counter = 0; var maxCheck = 0; var after = "Avr"; // determine benchmark time // settup times var benchmarkTime = 20; // in seconds switch (benchmarkType) { case BenchmarkPerformanceType.Quick: benchmarkTime = 20; maxCheck = 1 * numOfGpus; break; case BenchmarkPerformanceType.Standard: benchmarkTime = 60; maxCheck = 2 * numOfGpus; break; case BenchmarkPerformanceType.Precise: benchmarkTime = 120; maxCheck = 3 * numOfGpus; break; } var url = GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP); var algo = AlgorithmName(_algorithmType); var commandLine = $"--algo {algo} --url {url} --user {_username} --api-bind 127.0.0.1:{_apiPort} --no-watchdog --device {_devices} {_extraLaunchParameters}"; var(binPath, binCwd) = GetBinAndCwdPaths(); var bp = new BenchmarkProcess(binPath, binCwd, commandLine); bp.CheckData = (string data) => { var s = data; Console.WriteLine(s); var ret = (hashrate : default(double), found : false); if (s.Contains(after)) { var afterString = s.GetStringAfter(after).ToLower(); var afterStringArray = afterString.Split(' '); var hashRate = afterStringArray[1]; var numString = new string(hashRate .ToCharArray() .SkipWhile(c => !char.IsDigit(c)) .TakeWhile(c => char.IsDigit(c) || c == ',') .ToArray()); numString.Replace(',', '.'); if (!double.TryParse(numString, NumberStyles.Float, CultureInfo.InvariantCulture, out var hash)) { return(ret); } counter++; if (hashRate.Contains("kh")) { avgRet += hash * 1000; } else if (hashRate.Contains("mh")) { avgRet += hash * 1000000; } else if (hashRate.Contains("gh")) { avgRet += hash * 1000000000; } else { avgRet += hash; } maxCheck--; if (maxCheck == 0) { ret.hashrate = avgRet / counter; ret.found = true; } } return(ret); }; var benchmarkTimeout = TimeSpan.FromSeconds(300); var benchmarkWait = TimeSpan.FromMilliseconds(500); var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop); return(await t); }
public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { // determine benchmark time // settup times var benchmarkTime = 60; switch (benchmarkType) { case BenchmarkPerformanceType.Quick: benchmarkTime = 40; break; case BenchmarkPerformanceType.Standard: benchmarkTime = 60; break; case BenchmarkPerformanceType.Precise: benchmarkTime = 120; break; } 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 = $"--algo {algo} --url={url}:{port} --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); }
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 errorFound = false; 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(); errorFound = true; 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); }
public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { var numOfGpus = 2; //MUST BE SET CORRECTLY OTHERWISE BENCHMARKING WON't WORK (all cards are combined currently) var avgRet = 0.0; var counter = 0; var maxCheck = 0; var after = "Avr"; // determine benchmark time // settup times var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> { 20, 60, 120 }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType); // in seconds var url = GetLocationUrl(_algorithmType, _miningLocation, NhmConectionType.STRATUM_TCP); var algo = AlgorithmName(_algorithmType); var commandLine = $"--algo {algo} --url {url} --user {MinerToolkit.DemoUserBTC} --api-bind 0 --no-watchdog --device {_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()); bp.CheckData = (string data) => { var s = data; var ret = new HashFound(); ret.hashrate = default(double); ret.found = false; if (s.Contains(after)) { var afterString = s.GetStringAfter(after).ToLower(); var afterStringArray = afterString.Split(' '); var hashRate = afterStringArray[1]; var numString = new string(hashRate .ToCharArray() .SkipWhile(c => !char.IsDigit(c)) .TakeWhile(c => char.IsDigit(c) || c == ',') .ToArray()); numString.Replace(',', '.'); if (!double.TryParse(numString, NumberStyles.Float, CultureInfo.InvariantCulture, out var hash)) { return(new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, ret.hashrate) }, Success = ret.found }); } counter++; if (hashRate.Contains("kh")) { avgRet += hash * 1000; } else if (hashRate.Contains("mh")) { avgRet += hash * 1000000; } else if (hashRate.Contains("gh")) { avgRet += hash * 1000000000; } else { avgRet += hash; } maxCheck--; if (maxCheck == 0) { ret.hashrate = avgRet / counter; ret.found = true; } } return(new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, ret.hashrate) }, Success = ret.found }); }; var benchmarkTimeout = TimeSpan.FromSeconds(300); var benchmarkWait = TimeSpan.FromMilliseconds(500); var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop); return(await t); }
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 = PluginSupportedAlgorithms.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); }
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 deviceIDs = string.Join("", _miningPairs.Select(pair => $"{pair.Device.DeviceType.ToString()}{pair.Device.ID}")); var algoID = IsDual() ? $"{SingleAlgoName}{DualAlgoName}" : SingleAlgoName; var logfileName = $"noappend_{deviceIDs}_{algoID}_bench.txt"; var commandLine = CreateCommandLine(MinerToolkit.DemoUserBTC) + " -dbg 1 -logfile " + logfileName; 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()); bp.CheckData = (string data) => { // we can't read from stdout or stderr, read from logs later return(new BenchmarkResult()); }; var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 10); var benchmarkWait = TimeSpan.FromMilliseconds(500); var t = await MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop); // look for log file and parse that try { var benchHashesFirstSum = 0d; var benchItersFirst = 0; var benchHashesSecondSum = 0d; var benchItersSecond = 0; //var afterSingle = $"{SingleAlgoName.ToUpper()} - Total Speed:"; var firstAlgoLineMustContain = SingleAlgoName.ToUpper(); var secondAlgoLineMustContain = DualAlgoName.ToUpper(); var singleLineMustContain = SingleAlgoName.ToUpper(); var gpuAfter = $"GPU0"; // for single device we always have GPU0 var afterDual = $"{DualAlgoName.ToUpper()}: {DualAlgoName.ToUpper()} - Total Speed:"; var logFullPath = Path.Combine(binCwd, logfileName); var lines = File.ReadLines(logFullPath); foreach (var line in lines) { var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(line, gpuAfter); var hashrate = hashrateFoundPair.Item1; var found = hashrateFoundPair.Item2; if (!found || hashrate == 0) { continue; } if (line.Contains(firstAlgoLineMustContain)) { benchHashesFirstSum += hashrate; benchItersFirst++; } else if (line.Contains(secondAlgoLineMustContain)) { benchHashesSecondSum += hashrate; benchItersSecond++; } } var benchHashResultFirst = benchItersFirst == 0 ? 0d : benchHashesFirstSum / benchItersFirst; var benchHashResultSecond = benchItersSecond == 0 ? 0d : benchHashesSecondSum / benchItersSecond; var success = benchHashResultFirst > 0d; var speeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResultFirst * (1 - DevFee * 0.01)) }; if (IsDual()) { speeds.Add(new AlgorithmTypeSpeedPair(_algorithmSecondType, benchHashResultSecond * (1 - DualDevFee * 0.01))); } // return return(new BenchmarkResult { AlgorithmTypeSpeeds = speeds, Success = success }); } catch (Exception e) { Logger.Error(_logGroup, $"Benchmarking failed: {e.Message}"); } return(t); }
public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { // determine benchmark time // settup times var benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> { 60, 90, 120 }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType); // in seconds // use demo user and disable the watchdog var commandLine = CreateCommandLine(MinerToolkit.DemoUserBTC) + " --color 0 --boff"; 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)); const string totalSpeed = "Total speed:"; //const string speedPerGPU = $"GPU{CUDA_D}"// per GPU if we would use multiple GPUs bp.CheckData = (string data) => { var containsSolRate = data.Contains(totalSpeed) && data.Contains("Sol"); if (containsSolRate == false) { return new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = false } } ; var hashrateFoundPair = MinerToolkit.TryGetHashrateAfter(data, totalSpeed); 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); }
public override async Task <BenchmarkResult> 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 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); }
public async override Task <BenchmarkResult> 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 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) { 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); }