private static void PickGpuSpeed(string input, IKernelOutput kernelOutput, ICoin coin, bool isDual) { string gpuSpeedPattern = kernelOutput.GpuSpeedPattern; if (isDual) { gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern; } if (string.IsNullOrEmpty(gpuSpeedPattern)) { return; } var now = DateTime.Now; bool hasGpuId = gpuSpeedPattern.Contains("?<gpu>"); Regex regex = new Regex(gpuSpeedPattern); MatchCollection matches = regex.Matches(input); if (matches.Count > 0) { IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; for (int i = 0; i < matches.Count; i++) { Match match = matches[i]; string gpuSpeedText = match.Groups["gpuSpeed"].Value; string gpuSpeedUnit = match.Groups["gpuSpeedUnit"].Value; int gpu = i; if (hasGpuId) { string gpuText = match.Groups["gpu"].Value; if (!int.TryParse(gpuText, out gpu)) { gpu = i; } } double gpuSpeed; if (double.TryParse(gpuSpeedText, out gpuSpeed)) { double gpuSpeedL = gpuSpeed.FromUnitSpeed(gpuSpeedUnit); gpuSpeeds.SetCurrentSpeed(gpu, gpuSpeedL, isDual, now); } } string totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; if (isDual) { totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; } if (string.IsNullOrEmpty(totalSpeedPattern)) { // 求和分算力 double speed = isDual? gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.DualCoinSpeed.Value) : gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.MainCoinSpeed.Value); gpuSpeeds.SetCurrentSpeed(NTMinerRoot.GpuAllId, speed, isDual, now); } } }
private static void PickGpuSpeed(INTMinerRoot root, IMineContext mineContext, string input, IKernelOutput kernelOutput, bool isDual) { string gpuSpeedPattern = kernelOutput.GpuSpeedPattern; if (isDual) { gpuSpeedPattern = kernelOutput.DualGpuSpeedPattern; } if (string.IsNullOrEmpty(gpuSpeedPattern)) { return; } var now = DateTime.Now; bool hasGpuId = gpuSpeedPattern.Contains($"?<{NTKeyword.GpuIndexGroupName}>"); Regex regex = VirtualRoot.GetRegex(gpuSpeedPattern); MatchCollection matches = regex.Matches(input); if (matches.Count > 0) { IGpusSpeed gpuSpeeds = NTMinerRoot.Instance.GpusSpeed; for (int i = 0; i < matches.Count; i++) { Match match = matches[i]; string gpuSpeedText = match.Groups[NTKeyword.GpuSpeedGroupName].Value; string gpuSpeedUnit = match.Groups[NTKeyword.GpuSpeedUnitGroupName].Value; if (string.IsNullOrEmpty(gpuSpeedUnit)) { if (isDual) { gpuSpeedUnit = kernelOutput.DualSpeedUnit; } else { gpuSpeedUnit = kernelOutput.SpeedUnit; } } int gpu = i; if (hasGpuId) { string gpuText = match.Groups[NTKeyword.GpuIndexGroupName].Value; if (!int.TryParse(gpuText, out gpu)) { gpu = i; } else { gpu = gpu - kernelOutput.GpuBaseIndex; if (gpu < 0) { continue; } } } if (kernelOutput.IsMapGpuIndex && !string.IsNullOrWhiteSpace(mineContext.KernelInput.DevicesArg)) { if (mineContext.UseDevices.Length != 0 && mineContext.UseDevices.Length != root.GpuSet.Count && gpu < mineContext.UseDevices.Length) { gpu = mineContext.UseDevices[gpu]; } } if (double.TryParse(gpuSpeedText, out double gpuSpeed)) { double gpuSpeedL = gpuSpeed.FromUnitSpeed(gpuSpeedUnit); gpuSpeeds.SetCurrentSpeed(gpu, gpuSpeedL, isDual, now); } } string totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; if (isDual) { totalSpeedPattern = kernelOutput.DualTotalSpeedPattern; } if (string.IsNullOrEmpty(totalSpeedPattern)) { // 求和分算力 double speed = isDual? gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.DualCoinSpeed.Value) : gpuSpeeds.Where(a => a.Gpu.Index != NTMinerRoot.GpuAllId).Sum(a => a.MainCoinSpeed.Value); gpuSpeeds.SetCurrentSpeed(NTMinerRoot.GpuAllId, speed, isDual, now); } } }