public async Task <bool> BuildOpenCLKernels(CancellationToken stop) { // use demo user and disable colorts so we can read from stdout var stopAt = DateTime.Now.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.FromMinutes(10); var benchmarkWait = TimeSpan.FromMilliseconds(500); var t = await MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop); // TODO check kernels return(true); }
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); }
//// TODO this PATH IS temporary FIXED //protected override (string, string) GetBinAndCwdPaths() //{ // var binPath = @"D:\Programming\NiceHashMinerLegacy\Release\bin\ccminer_tpruvot\ccminer.exe"; // var binCwd = @"D:\Programming\NiceHashMinerLegacy\Release\bin\ccminer_tpruvot\"; // return (binPath, binCwd); //} protected override void Init() { bool ok; (_algorithmType, ok) = MinerToolkit.GetAlgorithmSingleType(_miningPairs); if (!ok) { throw new InvalidOperationException("Invalid mining initialization"); } // all good continue on // init command line params parts var deviceIds = MinerToolkit.GetDevicesIDsInOrder(_miningPairs); _devices = $"--devices {string.Join(",", deviceIds)}"; // TODO implement this later //_extraLaunchParameters; }
protected override void Init() { var dualType = MinerToolkit.GetAlgorithmDualType(_miningPairs); _algorithmSecondType = dualType.Item1; var ok = dualType.Item2; if (!ok) { _algorithmSecondType = AlgorithmType.NONE; } // all good continue on // mining pairs are ordered in InitMiningPairs var mappedDeviceIDs = _miningPairs.Select(p => ClaymoreHelpers.GetClaymoreDeviceID(_mappedIDs[p.Device.UUID])); _devices = string.Join("", mappedDeviceIDs); }
protected override void Init() { var singleType = MinerToolkit.GetAlgorithmSingleType(_miningPairs); _algorithmType = singleType.Item1; bool ok = singleType.Item2; if (!ok) { Logger.Info(_logGroup, "Initialization of miner failed. Algorithm not found!"); throw new InvalidOperationException("Invalid mining initialization"); } // all good continue on // Order pairs and parse ELP var orderedMiningPairs = _miningPairs.ToList(); orderedMiningPairs.Sort((a, b) => a.Device.ID.CompareTo(b.Device.ID)); _devices = string.Join(",", orderedMiningPairs.Select(p => p.Device.ID)); var openClAmdPlatformResult = MinerToolkit.GetOpenCLPlatformID(_miningPairs); _openClAmdPlatformNum = openClAmdPlatformResult.Item1; bool openClAmdPlatformNumUnique = openClAmdPlatformResult.Item2; if (!openClAmdPlatformNumUnique) { Logger.Error(_logGroup, "Initialization of miner failed. Multiple OpenCLPlatform IDs found!"); throw new InvalidOperationException("Invalid mining initialization"); } for (int i = 0; i < orderedMiningPairs.Count; i++) { _initOrderMirrorApiOrderUUIDs[i] = orderedMiningPairs[i].Device.UUID; } if (MinerOptionsPackage != null) { // TODO add ignore temperature checks var generalParams = Parser.Parse(orderedMiningPairs, MinerOptionsPackage.GeneralOptions); var temperatureParams = Parser.Parse(orderedMiningPairs, MinerOptionsPackage.TemperatureOptions); _extraLaunchParameters = $"{generalParams} {temperatureParams}".Trim(); } }
public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { //only 60s mark is available var benchmarkTime = 60; // in seconds var commandLine = $"-a {AlgoName} --benchmark -d {_devices} --multiple-instance {_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 benchHashResult = 0d; bp.CheckData = (string data) => { var hashrateFoundPair = BenchmarkHelpers.TryGetHashrateAfter(data, "60s:"); var hashrate = hashrateFoundPair.Item1; var found = hashrateFoundPair.Item2; if (found) { benchHashResult = hashrate * (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); var benchmarkWait = TimeSpan.FromMilliseconds(500); var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop); return(await t); }
public override async Task <(double speed, bool ok, string msg)> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { // determine benchmark time // settup times 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} --benchmark --time-limit {benchmarkTime} {_devices} {_extraLaunchParameters}"; var(binPath, binCwd) = GetBinAndCwdPaths(); var bp = new BenchmarkProcess(binPath, binCwd, commandLine); // TODO implement fallback average, final benchmark bp.CheckData = (string data) => { return(MinerToolkit.TryGetHashrateAfter(data, "Benchmark:")); // TODO add option to read totals }; var benchmarkTimeout = TimeSpan.FromSeconds(benchmarkTime + 5); var benchmarkWait = TimeSpan.FromMilliseconds(500); var t = MinerToolkit.WaitBenchmarkResult(bp, benchmarkTimeout, benchmarkWait, stop); return(await t); }
protected override void Init() { var singleType = MinerToolkit.GetAlgorithmSingleType(_miningPairs); _algorithmType = singleType.Item1; bool ok = singleType.Item2; if (!ok) { Logger.Info(_logGroup, "Initialization of miner failed. Algorithm not found!"); throw new InvalidOperationException("Invalid mining initialization"); } // all good continue on // Order pairs and parse ELP var orderedMiningPairs = _miningPairs.ToList(); orderedMiningPairs.Sort((a, b) => a.Device.ID.CompareTo(b.Device.ID)); var deviceIds = orderedMiningPairs.Select(pair => pair.Device.ID); _devicesOnPlatform = $"--gpu-platform {_openClAmdPlatformNum} -d {string.Join(",", deviceIds)}"; if (MinerOptionsPackage != null) { // TODO add ignore temperature checks var generalParams = Parser.Parse(orderedMiningPairs, MinerOptionsPackage.GeneralOptions); var temperatureParams = Parser.Parse(orderedMiningPairs, MinerOptionsPackage.TemperatureOptions); _extraLaunchParameters = $"{generalParams} {temperatureParams}".Trim(); } else // TODO this one is temp??? { // TODO add ignore temperature checks var generalParams = Parser.Parse(orderedMiningPairs, DefaultMinerOptionsPackage.GeneralOptions); var temperatureParams = Parser.Parse(orderedMiningPairs, DefaultMinerOptionsPackage.TemperatureOptions); _extraLaunchParameters = $"{generalParams} {temperatureParams}".Trim(); } }
protected override void Init() { bool ok; (_algorithmType, ok) = MinerToolkit.GetAlgorithmSingleType(_miningPairs); if (!ok) { throw new InvalidOperationException("Invalid mining initialization"); } // all good continue on var orderedMiningPairs = _miningPairs.ToList(); orderedMiningPairs.Sort((a, b) => a.device.ID.CompareTo(b.device.ID)); _devices = string.Join(",", orderedMiningPairs.Select(p => p.device.ID)); if (MinerOptionsPackage != null) { // TODO add ignore temperature checks var generalParams = Parser.Parse(orderedMiningPairs, MinerOptionsPackage.GeneralOptions); var temperatureParams = Parser.Parse(orderedMiningPairs, MinerOptionsPackage.TemperatureOptions); _extraLaunchParameters = $"{generalParams} {temperatureParams}".Trim(); } }
protected override void Init() { // Order pairs and parse ELP var miningPairsList = _miningPairs.ToList(); _devices = string.Join(",", miningPairsList.Select(p => p.Device.ID)); var openClAmdPlatformResult = MinerToolkit.GetOpenCLPlatformID(_miningPairs); _openClAmdPlatformNum = openClAmdPlatformResult.Item1; bool openClAmdPlatformNumUnique = openClAmdPlatformResult.Item2; if (!openClAmdPlatformNumUnique) { Logger.Error(_logGroup, "Initialization of miner failed. Multiple OpenCLPlatform IDs found!"); throw new InvalidOperationException("Invalid mining initialization"); } for (int i = 0; i < miningPairsList.Count; i++) { _initOrderMirrorApiOrderUUIDs[i] = miningPairsList[i].Device.UUID; } }
protected override void Init() { var singleType = MinerToolkit.GetAlgorithmSingleType(_miningPairs); _algorithmFirstType = singleType.Item1; bool ok = singleType.Item2; if (!ok) { Logger.Info(_logGroup, "Initialization of miner failed. Algorithm not found!"); throw new InvalidOperationException("Invalid mining initialization"); } var dualType = MinerToolkit.GetAlgorithmDualType(_miningPairs); _algorithmSecondType = dualType.Item1; ok = dualType.Item2; if (!ok) { _algorithmSecondType = AlgorithmType.NONE; } // all good continue on _orderedMiningPairs = _miningPairs.ToList(); _orderedMiningPairs.Sort((a, b) => _mappedIDs[a.Device.UUID].CompareTo(_mappedIDs[b.Device.UUID])); _devices = string.Join("", _orderedMiningPairs.Select(p => ClaymoreHelpers.GetClaymoreDeviceID(_mappedIDs[p.Device.UUID]))); _platform = $"{GetPlatformIDForType(_orderedMiningPairs.First().Device.DeviceType)}"; if (MinerOptionsPackage != null) { // TODO add ignore temperature checks var generalParams = Parser.Parse(_orderedMiningPairs, MinerOptionsPackage.GeneralOptions); var temperatureParams = Parser.Parse(_orderedMiningPairs, MinerOptionsPackage.TemperatureOptions); _extraLaunchParameters = $"{generalParams} {temperatureParams}".Trim(); } }
protected override void Init() { var singleType = MinerToolkit.GetAlgorithmSingleType(_miningPairs); _algorithmType = singleType.Item1; bool ok = singleType.Item2; if (!ok) { throw new InvalidOperationException("Invalid mining initialization"); } var orderedMiningPairs = _miningPairs.ToList(); orderedMiningPairs.Sort((a, b) => a.Device.ID.CompareTo(b.Device.ID)); //TODO this must be implemented if (MinerOptionsPackage != null) { var ignoreDefaults = MinerOptionsPackage.IgnoreDefaultValueOptions; var generalParams = ExtraLaunchParametersParser.Parse(orderedMiningPairs, MinerOptionsPackage.GeneralOptions, ignoreDefaults); var temperatureParams = ExtraLaunchParametersParser.Parse(orderedMiningPairs, MinerOptionsPackage.TemperatureOptions, ignoreDefaults); _extraLaunchParameters = $"{generalParams} {temperatureParams}".Trim(); } }
protected override void Init() { var singleType = MinerToolkit.GetAlgorithmSingleType(_miningPairs); _algorithmType = singleType.Item1; bool ok = singleType.Item2; if (!ok) { Logger.Info(_logGroup, "Initialization of miner failed. Algorithm not found!"); throw new InvalidOperationException("Invalid mining initialization"); } var orderedMiningPairs = _miningPairs.ToList(); orderedMiningPairs.Sort((a, b) => a.Device.ID.CompareTo(b.Device.ID)); if (MinerOptionsPackage != null) { // TODO add ignore temperature checks var generalParams = Parser.Parse(orderedMiningPairs, MinerOptionsPackage.GeneralOptions); var temperatureParams = Parser.Parse(orderedMiningPairs, MinerOptionsPackage.TemperatureOptions); _extraLaunchParameters = $"{generalParams} {temperatureParams}".Trim(); } }
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 var commandLine = MiningCreateCommandLine(); 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; bp.CheckData = (string data) => { if (!data.Contains("Accepted")) { return new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = false } } ; var hashrateFoundPair = BenchmarkHelpers.TryGetHashrate(data); 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 = false //TODO not sure what to set here }); }; 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) { // 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 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 bool CanGroup(MiningPair a, MiningPair b) { return(MinerToolkit.IsSameAlgorithmType(a.Algorithm, b.Algorithm)); }
public override async Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { int benchTime; switch (benchmarkType) { case BenchmarkPerformanceType.Quick: benchTime = 20; break; case BenchmarkPerformanceType.Precise: benchTime = 120; break; default: benchTime = 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 id = _mappedIDs[_miningPairs.First().Device.UUID]; var benchHashes = 0d; var benchIters = 0; var benchHashResult = 0d; // Not too sure what this is.. var targetBenchIters = Math.Max(1, (int)Math.Floor(benchTime / 20d)); bp.CheckData = (data) => { var hashrateFoundPair = data.TryGetHashrateAfter($" - {id}: "); 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; 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(benchTime + 5); var benchWait = TimeSpan.FromMilliseconds(500); var t = MinerToolkit.WaitBenchmarkResult(bp, timeout, benchWait, 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 = 20; // in seconds switch (benchmarkType) { case BenchmarkPerformanceType.Quick: benchmarkTime = 20; break; case BenchmarkPerformanceType.Standard: benchmarkTime = 60; break; case BenchmarkPerformanceType.Precise: benchmarkTime = 120; break; } // 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); }
public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { var benchmarkTime = 90; // in seconds switch (benchmarkType) { case BenchmarkPerformanceType.Quick: benchmarkTime = 60; break; case BenchmarkPerformanceType.Standard: benchmarkTime = 90; break; case BenchmarkPerformanceType.Precise: benchmarkTime = 180; break; } // local benchmark // TODO hardcoded epoch var commandLine = $"-di {_devices} {_extraLaunchParameters} -benchmark 200 -wd 0"; 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(_algorithmFirstType, benchHashResult) } }); }; 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) { using (var tickCancelSource = new CancellationTokenSource()) { // determine benchmark time // settup times int benchmarkTime; var isDaggerNvidia = _miningPairs.Any(mp => mp.Algorithm.FirstAlgorithmType == AlgorithmType.DaggerHashimoto) && _miningPairs.Any(mp => mp.Device.DeviceType == DeviceType.NVIDIA); if (isDaggerNvidia || _miningPairs.Any(mp => mp.Algorithm.FirstAlgorithmType == AlgorithmType.KAWPOW)) { benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> { 180, 240, 300 }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType); } else { benchmarkTime = MinerBenchmarkTimeSettings.ParseBenchmarkTime(new List <int> { 60, 120, 180 }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType); } var maxTicks = MinerBenchmarkTimeSettings.ParseBenchmarkTicks(new List <int> { 1, 3, 9 }, MinerBenchmarkTimeSettings, _miningPairs, benchmarkType); var maxTicksEnabled = MinerBenchmarkTimeSettings.MaxTicksEnabled && !isDaggerNvidia; //// 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}"); Logger.Info(_logGroup, $"Benchmarking is Dagger NVIDIA LHR {isDaggerNvidia}"); 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>(); int delay = maxTicksEnabled ? (benchmarkTime / maxTicks) * 1000 : 10 * 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 (maxTicksEnabled && validTicks >= maxTicks) { stoppedAfterTicks = true; break; } } // await benchmark task if (stoppedAfterTicks) { try { tickCancelSource.Cancel(); } catch { Logger.Error(_logGroup, "tickCancelSource error"); } } 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); } }
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 = 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 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); }
protected async Task <string> PrepareDeviceConfigs(CancellationToken stop) { var binPathBinCwdPair = GetBinAndCwdPaths(); var binCwd = binPathBinCwdPair.Item2; var algo = AlgorithmName(_algorithmType); // prepare configs var folder = _algorithmType.ToString().ToLower(); // check if we have configs var createConfigs = _miningDeviceTypes.All(deviceType => !_configHandler.HasConfig(deviceType, _algorithmType)); if (createConfigs) { using (_stopSource = new CancellationTokenSource()) using (var linked = CancellationTokenSource.CreateLinkedTokenSource(stop, _stopSource.Token)) { try { var t = CreateConfigFiles(_miningDeviceTypes, linked.Token); var tupleResult = await t; var result = tupleResult.Item1; var configFilePaths = tupleResult.Item2; if (result) { foreach (var path in configFilePaths) { var deviceTypes = _miningDeviceTypes.Where(deviceType => path.Contains(deviceType.ToString())); if (deviceTypes.Count() > 0) { var deviceType = deviceTypes.First(); _configHandler.SaveMoveConfig(deviceType, _algorithmType, path); } } } } catch (Exception e) { Logger.Info(_logGroup, $"Failed to create config file: {e.Message}"); } } } // wait until we have the algorithms ready, 5 seconds should be enough foreach (var deviceType in _miningDeviceTypes) { var hasConfig = false; var start = DateTime.UtcNow; while (DateTime.UtcNow.Subtract(start).Seconds < 5) { await Task.Delay(100); hasConfig = _configHandler.HasConfig(deviceType, _algorithmType); if (hasConfig) { break; } } if (!hasConfig) { Logger.Info(_logGroup, $"Config for {deviceType.ToString()}_{_algorithmType.ToString()} not found!"); throw new Exception($"Cannot start device type {deviceType.ToString()} for algorithm {_algorithmType.ToString()} there is no config"); } } var deviceConfigParams = ""; // prepare foreach (var deviceType in _miningDeviceTypes) { var flag = deviceType.ToString().ToLower(); // for filtering devices by CUDA and OpenCL indexes var deviceIDs = _miningPairs.Where(pair => pair.Device.DeviceType == deviceType).Select(pair => pair.Device.ID); var config = $"{flag}_{string.Join(",", deviceIDs)}.txt".ToLower(); deviceConfigParams += $@" --{flag} {folder}\{config}"; var deviceConfigFilePath = Path.Combine(binCwd, folder, config); if (_cpuConfig == null && DeviceType.CPU == deviceType) { // we just use the template _cpuConfig = _configHandler.GetCpuConfig(_algorithmType); ConfigHelpers.WriteConfigFile(deviceConfigFilePath, _cpuConfig); } if (_nvidiaConfig == null && DeviceType.NVIDIA == deviceType) { var nvidiaTemplate = _configHandler.GetNvidiaConfig(_algorithmType); _nvidiaConfig = new NvidiaConfig(); _nvidiaConfig.gpu_threads_conf = nvidiaTemplate.gpu_threads_conf.Where(t => deviceIDs.Contains(t.index)).ToList(); ConfigHelpers.WriteConfigFile(deviceConfigFilePath, _nvidiaConfig); } if (_amdConfig == null && DeviceType.AMD == deviceType) { var openClAmdPlatformResult = MinerToolkit.GetOpenCLPlatformID(_miningPairs); var openClAmdPlatformNum = openClAmdPlatformResult.Item1; bool openClAmdPlatformNumUnique = openClAmdPlatformResult.Item2; if (!openClAmdPlatformNumUnique) { Logger.Error(_logGroup, "Initialization of miner failed. Multiple OpenCLPlatform IDs found!"); throw new InvalidOperationException("Invalid mining initialization"); } var amdTemplate = _configHandler.GetAmdConfig(_algorithmType); _amdConfig = new AmdConfig() { platform_index = openClAmdPlatformNum }; _amdConfig.gpu_threads_conf = amdTemplate.gpu_threads_conf.Where(t => deviceIDs.Contains(t.index)).ToList(); ConfigHelpers.WriteConfigFile(deviceConfigFilePath, _amdConfig); } } return(deviceConfigParams); }
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 = 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) { 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); } }
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); }
// 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.. 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 + (2 * 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 = 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; 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 { var gpuSpeed = ad.AlgorithmSpeedsPerDevice.Values.FirstOrDefault().FirstOrDefault().Speed; 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 }; } 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); }
public async override Task <BenchmarkResult> StartBenchmark(CancellationToken stop, BenchmarkPerformanceType benchmarkType = BenchmarkPerformanceType.Standard) { var benchmarkTime = 60; // in seconds switch (benchmarkType) { case BenchmarkPerformanceType.Precise: benchmarkTime = 120; break; default: benchmarkTime = 60; break; } var commandLine = $"-a {AlgoName} --benchmark -d {_devices} --multiple-instance {_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 benchHashResult = 0d; bp.CheckData = (string data) => { if (!data.Contains("hashrate:")) { return(new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, 0d) }, Success = false }); } var hashrateFoundPair = BenchmarkHelpers.TryGetHashrateAfter(data, "60s:"); var hashrate = hashrateFoundPair.Item1; // TODO temporary fix for N/A speeds at 60s mark... will be fixed when developer fixes benchmarking if (hashrate == 0) { hashrateFoundPair = BenchmarkHelpers.TryGetHashrateAfter(data, "10s:"); } hashrate = hashrateFoundPair.Item1; var found = hashrateFoundPair.Item2; if (!found) { return new BenchmarkResult { AlgorithmTypeSpeeds = new List <AlgorithmTypeSpeedPair> { new AlgorithmTypeSpeedPair(_algorithmType, benchHashResult) }, Success = false } } ; benchHashResult = hashrate * (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); 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 = 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); }