main.rs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #![allow(clippy::arithmetic_side_effects)]
  2. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  3. use solana_entry::entry::{self, create_ticks, init_poh, EntrySlice};
  4. #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
  5. use solana_entry::entry::{create_ticks, init_poh, EntrySlice};
  6. use {
  7. clap::{crate_description, crate_name, Arg, Command},
  8. solana_measure::measure::Measure,
  9. solana_sha256_hasher::hash,
  10. };
  11. fn main() {
  12. agave_logger::setup();
  13. let matches = Command::new(crate_name!())
  14. .about(crate_description!())
  15. .version(solana_version::version!())
  16. .arg(
  17. Arg::new("max_num_entries")
  18. .long("max-num-entries")
  19. .takes_value(true)
  20. .value_name("SIZE")
  21. .help("Number of entries."),
  22. )
  23. .arg(
  24. Arg::new("start_num_entries")
  25. .long("start-num-entries")
  26. .takes_value(true)
  27. .value_name("SIZE")
  28. .help("Packets per chunk"),
  29. )
  30. .arg(
  31. Arg::new("hashes_per_tick")
  32. .long("hashes-per-tick")
  33. .takes_value(true)
  34. .value_name("SIZE")
  35. .help("hashes per tick"),
  36. )
  37. .arg(
  38. Arg::new("num_transactions_per_entry")
  39. .long("num-transactions-per-entry")
  40. .takes_value(true)
  41. .value_name("NUM")
  42. .help("Skip transaction sanity execution"),
  43. )
  44. .arg(
  45. Arg::new("iterations")
  46. .long("iterations")
  47. .takes_value(true)
  48. .help("Number of iterations"),
  49. )
  50. .arg(
  51. Arg::new("num_threads")
  52. .long("num-threads")
  53. .takes_value(true)
  54. .help("Number of threads"),
  55. )
  56. .get_matches();
  57. let max_num_entries: u64 = matches.value_of_t("max_num_entries").unwrap_or(64);
  58. let start_num_entries: u64 = matches
  59. .value_of_t("start_num_entries")
  60. .unwrap_or(max_num_entries);
  61. let iterations: usize = matches.value_of_t("iterations").unwrap_or(10);
  62. let hashes_per_tick: u64 = matches.value_of_t("hashes_per_tick").unwrap_or(10_000);
  63. let start_hash = hash(&[1, 2, 3, 4]);
  64. let ticks = create_ticks(max_num_entries, hashes_per_tick, start_hash);
  65. let mut num_entries = start_num_entries as usize;
  66. let num_threads = matches.value_of_t("num_threads").unwrap_or(num_cpus::get());
  67. let thread_pool = rayon::ThreadPoolBuilder::new()
  68. .num_threads(num_threads)
  69. .thread_name(|i| format!("solPohBench{i:02}"))
  70. .build()
  71. .expect("new rayon threadpool");
  72. init_poh();
  73. while num_entries <= max_num_entries as usize {
  74. let mut time = Measure::start("time");
  75. for _ in 0..iterations {
  76. assert!(ticks[..num_entries]
  77. .verify_cpu_generic(&start_hash, &thread_pool)
  78. .status());
  79. }
  80. time.stop();
  81. println!(
  82. "{},cpu_generic,{}",
  83. num_entries,
  84. time.as_us() / iterations as u64
  85. );
  86. // A target_arch check is required here since calling
  87. // is_x86_feature_detected from a non-x86_64 arch results in a build
  88. // error.
  89. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  90. {
  91. if is_x86_feature_detected!("avx2") && entry::api().is_some() {
  92. let mut time = Measure::start("time");
  93. for _ in 0..iterations {
  94. assert!(ticks[..num_entries]
  95. .verify_cpu_x86_simd(&start_hash, 8, &thread_pool)
  96. .status());
  97. }
  98. time.stop();
  99. println!(
  100. "{},cpu_simd_avx2,{}",
  101. num_entries,
  102. time.as_us() / iterations as u64
  103. );
  104. }
  105. if is_x86_feature_detected!("avx512f") && entry::api().is_some() {
  106. let mut time = Measure::start("time");
  107. for _ in 0..iterations {
  108. assert!(ticks[..num_entries]
  109. .verify_cpu_x86_simd(&start_hash, 16, &thread_pool)
  110. .status())
  111. }
  112. time.stop();
  113. println!(
  114. "{},cpu_simd_avx512,{}",
  115. num_entries,
  116. time.as_us() / iterations as u64
  117. );
  118. }
  119. }
  120. println!();
  121. num_entries *= 2;
  122. }
  123. }