Skip to content

Commit

Permalink
perf: Add benchmarks for different FRI exp factors
Browse files Browse the repository at this point in the history
For now, it looks like an expansion factor of 8 minimizes the opstack
table height and clock cycle count. But this was only measured for inner
padded heights of 2^8 and 2^9. We need to run these benchmarks, and
profilers, for inner padded heights of 2^21 and 2^22.
  • Loading branch information
Sword-Smith committed Apr 18, 2024
1 parent dc7d8a2 commit 4411e21
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"name": "tasmlib_verifier_stark_verify_256",
"name": "tasmlib_verifier_stark_verify_inner_padded_height_256_fri_exp_4",
"benchmark_result": {
"clock_cycle_count": 1193994,
"hash_table_height": 181747,
"u32_table_height": 45543,
"u32_table_height": 45892,
"op_stack_table_height": 1637760,
"ram_table_height": 513214
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[
{
"name": "tasmlib_verifier_stark_verify_512",
"name": "tasmlib_verifier_stark_verify_inner_padded_height_512_fri_exp_4",
"benchmark_result": {
"clock_cycle_count": 1221657,
"hash_table_height": 190879,
"u32_table_height": 51307,
"u32_table_height": 51192,
"op_stack_table_height": 1675318,
"ram_table_height": 516821
},
Expand Down
48 changes: 40 additions & 8 deletions tasm-lib/src/verifier/stark_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,13 +1200,37 @@ mod benches {
use super::*;

#[test]
fn benchmark_small() {
benchmark_verifier(3, 1 << 8);
benchmark_verifier(40, 1 << 9);
fn benchmark_small_default_stark() {
benchmark_verifier(3, 1 << 8, Stark::default());
benchmark_verifier(40, 1 << 9, Stark::default());
}

#[ignore = "Takes a fairly long time. Intended to find optimal FRI expansion factor."]
#[test]
fn small_benchmark_different_fri_expansion_factors() {
for log2_of_fri_expansion_factor in 2..=5 {
let stark = Stark::new(160, log2_of_fri_expansion_factor);
benchmark_verifier(10, 1 << 8, stark);
benchmark_verifier(40, 1 << 9, stark);
}
}

#[ignore = "Takes a very long time. Intended to find optimal FRI expansion factor. Make sure to run
with `RUSTFLAGS=\"-C opt-level=3 -C debug-assertions=no`"]
#[test]
fn big_benchmark_different_fri_expansion_factors() {
for log2_of_fri_expansion_factor in 2..=5 {
let stark = Stark::new(160, log2_of_fri_expansion_factor);
benchmark_verifier(10, 1 << 8, stark);
benchmark_verifier(40, 1 << 9, stark);
benchmark_verifier(80, 1 << 10, stark);
benchmark_verifier(102400, 1 << 21, stark);
benchmark_verifier(204800, 1 << 22, stark);
}
}

#[ignore = "Intended to generate data about verifier table heights as a function of inner padded
height Make sure to run with `RUSTFLAGS=\"-C opt-level=3 -C debug-assertions=no`"]
height. Make sure to run with `RUSTFLAGS=\"-C opt-level=3 -C debug-assertions=no`"]
#[test]
fn benchmark_verification_as_a_function_of_inner_padded_height() {
for (fact_arg, expected_inner_padded_height) in [
Expand All @@ -1225,13 +1249,16 @@ mod benches {
(51200, 1 << 20),
(102400, 1 << 21),
] {
benchmark_verifier(fact_arg, expected_inner_padded_height);
benchmark_verifier(fact_arg, expected_inner_padded_height, Stark::default());
}
}

fn benchmark_verifier(factorial_argument: u32, expected_inner_padded_height: usize) {
fn benchmark_verifier(
factorial_argument: u32,
expected_inner_padded_height: usize,
stark: Stark,
) {
let factorial_program = factorial_program_with_io();
let stark = Stark::default();
let (mut non_determinism, claim_for_proof, inner_padded_height) =
non_determinism_claim_and_padded_height(
&factorial_program,
Expand Down Expand Up @@ -1261,7 +1288,12 @@ mod benches {
let code = link_for_isolated_run(Rc::new(RefCell::new(snippet.clone())));
let benchmark = execute_bench(&code, &stack, vec![], non_determinism, None);
let benchmark = NamedBenchmarkResult {
name: format!("{}_{}", snippet.entrypoint(), inner_padded_height),
name: format!(
"{}_inner_padded_height_{}_fri_exp_{}",
snippet.entrypoint(),
inner_padded_height,
stark.fri_expansion_factor
),
benchmark_result: benchmark,
case: BenchmarkCase::CommonCase,
};
Expand Down

0 comments on commit 4411e21

Please sign in to comment.