Skip to content

Commit

Permalink
Fixup benches
Browse files Browse the repository at this point in the history
  • Loading branch information
steviez committed Mar 26, 2024
1 parent 37f2db0 commit 697f7ee
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion entry/benches/entry_sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use {

#[bench]
fn bench_gpusigverify(bencher: &mut Bencher) {
let thread_pool = entry::thread_pool_for_benches();
let entries = (0..131072)
.map(|_| {
let transaction = test_tx();
Expand Down Expand Up @@ -53,6 +54,7 @@ fn bench_gpusigverify(bencher: &mut Bencher) {
let res = entry::start_verify_transactions(
entries.clone(),
false,
&thread_pool,
recycler.clone(),
Arc::new(verify_transaction),
);
Expand All @@ -65,6 +67,7 @@ fn bench_gpusigverify(bencher: &mut Bencher) {

#[bench]
fn bench_cpusigverify(bencher: &mut Bencher) {
let thread_pool = entry::thread_pool_for_benches();
let entries = (0..131072)
.map(|_| {
let transaction = test_tx();
Expand All @@ -89,6 +92,7 @@ fn bench_cpusigverify(bencher: &mut Bencher) {
};

bencher.iter(|| {
let _ans = entry::verify_transactions(entries.clone(), Arc::new(verify_transaction));
let _ans =
entry::verify_transactions(entries.clone(), &thread_pool, Arc::new(verify_transaction));
})
}
9 changes: 9 additions & 0 deletions entry/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use {
recycler::Recycler,
sigverify,
},
solana_rayon_threadlimit::get_max_thread_count,
solana_sdk::{
hash::Hash,
packet::Meta,
Expand Down Expand Up @@ -961,6 +962,14 @@ pub fn entry_thread_pool_for_tests() -> ThreadPool {
.expect("new rayon threadpool")
}

pub fn thread_pool_for_benches() -> ThreadPool {
rayon::ThreadPoolBuilder::new()
.num_threads(get_max_thread_count())
.thread_name(|i| format!("solEntryBnch{i:02}"))
.build()
.expect("new rayon threadpool")
}

#[cfg(test)]
mod tests {
use {
Expand Down
1 change: 1 addition & 0 deletions poh-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ solana-entry = { workspace = true }
solana-logger = { workspace = true }
solana-measure = { workspace = true }
solana-perf = { workspace = true }
solana-rayon-threadlimit = { workspace = true }
solana-sdk = { workspace = true }
solana-version = { workspace = true }

Expand Down
25 changes: 17 additions & 8 deletions poh-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use {
clap::{crate_description, crate_name, Arg, Command},
solana_measure::measure::Measure,
solana_perf::perf_libs,
solana_rayon_threadlimit::get_max_thread_count,
solana_sdk::hash::hash,
};

Expand Down Expand Up @@ -73,6 +74,14 @@ fn main() {
let start_hash = hash(&[1, 2, 3, 4]);
let ticks = create_ticks(max_num_entries, hashes_per_tick, start_hash);
let mut num_entries = start_num_entries as usize;
let num_threads = matches
.value_of_t("num_threads")
.unwrap_or(get_max_thread_count());
let thread_pool = rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
.thread_name(|i| format!("solPohBench{i:02}"))
.build()
.expect("new rayon threadpool");
if matches.is_present("cuda") {
perf_libs::init_cuda();
}
Expand All @@ -81,8 +90,8 @@ fn main() {
let mut time = Measure::start("time");
for _ in 0..iterations {
assert!(ticks[..num_entries]
.verify_cpu_generic(&start_hash)
.finish_verify());
.verify_cpu_generic(&start_hash, &thread_pool)
.finish_verify(&thread_pool));
}
time.stop();
println!(
Expand All @@ -100,8 +109,8 @@ fn main() {
let mut time = Measure::start("time");
for _ in 0..iterations {
assert!(ticks[..num_entries]
.verify_cpu_x86_simd(&start_hash, 8)
.finish_verify());
.verify_cpu_x86_simd(&start_hash, 8, &thread_pool)
.finish_verify(&thread_pool));
}
time.stop();
println!(
Expand All @@ -115,8 +124,8 @@ fn main() {
let mut time = Measure::start("time");
for _ in 0..iterations {
assert!(ticks[..num_entries]
.verify_cpu_x86_simd(&start_hash, 16)
.finish_verify());
.verify_cpu_x86_simd(&start_hash, 16, &thread_pool)
.finish_verify(&thread_pool));
}
time.stop();
println!(
Expand All @@ -132,8 +141,8 @@ fn main() {
let recyclers = VerifyRecyclers::default();
for _ in 0..iterations {
assert!(ticks[..num_entries]
.start_verify(&start_hash, recyclers.clone())
.finish_verify());
.start_verify(&start_hash, &thread_pool, recyclers.clone())
.finish_verify(&thread_pool));
}
time.stop();
println!(
Expand Down
10 changes: 7 additions & 3 deletions poh/benches/poh_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extern crate test;

use {
solana_entry::entry::{next_entry_mut, Entry, EntrySlice},
solana_entry::entry::{self, next_entry_mut, Entry, EntrySlice},
solana_sdk::{
hash::{hash, Hash},
signature::{Keypair, Signer},
Expand All @@ -17,6 +17,8 @@ const NUM_ENTRIES: usize = 800;
#[bench]
fn bench_poh_verify_ticks(bencher: &mut Bencher) {
solana_logger::setup();
let thread_pool = entry::thread_pool_for_benches();

let zero = Hash::default();
let start_hash = hash(zero.as_ref());
let mut cur_hash = start_hash;
Expand All @@ -27,12 +29,14 @@ fn bench_poh_verify_ticks(bencher: &mut Bencher) {
}

bencher.iter(|| {
assert!(ticks.verify(&start_hash));
assert!(ticks.verify(&start_hash, &thread_pool));
})
}

#[bench]
fn bench_poh_verify_transaction_entries(bencher: &mut Bencher) {
let thread_pool = entry::thread_pool_for_benches();

let zero = Hash::default();
let start_hash = hash(zero.as_ref());
let mut cur_hash = start_hash;
Expand All @@ -47,6 +51,6 @@ fn bench_poh_verify_transaction_entries(bencher: &mut Bencher) {
}

bencher.iter(|| {
assert!(ticks.verify(&start_hash));
assert!(ticks.verify(&start_hash, &thread_pool));
})
}

0 comments on commit 697f7ee

Please sign in to comment.