-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Context Existing benchmark `riscv_add` are just for testing single opcode performance. This PR aim to have a first e2e bench which is representative to a workload in real world. ### What has been cover - add fibonacci bench with sp1 platform hardcode - refactor e2e flow into sub-function to maximize code sharing ### what's not being covered Hey @mcalancea, key generation + witness assignment are still encaptulated in same function and not including in bench latency meature. Break down key generation and extract witness assignment will expose massive intermediate variables in between, so probably need another refactor and design to support #624
- Loading branch information
Showing
7 changed files
with
250 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,8 @@ riv64 = [] | |
[[bench]] | ||
harness = false | ||
name = "riscv_add" | ||
|
||
|
||
[[bench]] | ||
harness = false | ||
name = "fibonacci" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use std::{ | ||
fs, | ||
path::PathBuf, | ||
time::{Duration, Instant}, | ||
}; | ||
|
||
use ceno_emul::{CENO_PLATFORM, Platform, Program, WORD_SIZE}; | ||
use ceno_zkvm::{ | ||
self, | ||
e2e::{run_e2e_gen_witness, run_e2e_proof}, | ||
}; | ||
use criterion::*; | ||
|
||
use goldilocks::GoldilocksExt2; | ||
use mpcs::BasefoldDefault; | ||
|
||
criterion_group! { | ||
name = fibonacci; | ||
config = Criterion::default().warm_up_time(Duration::from_millis(20000)); | ||
targets = bench_e2e | ||
} | ||
|
||
criterion_main!(fibonacci); | ||
|
||
const NUM_SAMPLES: usize = 10; | ||
|
||
fn bench_e2e(c: &mut Criterion) { | ||
type Pcs = BasefoldDefault<E>; | ||
let mut file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
file_path.push("examples/fibonacci.elf"); | ||
let stack_size = 32768; | ||
let heap_size = 2097152; | ||
let elf_bytes = fs::read(&file_path).expect("read elf file"); | ||
let program = Program::load_elf(&elf_bytes, u32::MAX).unwrap(); | ||
|
||
// use sp1 platform | ||
let platform = Platform { | ||
// The stack section is not mentioned in ELF headers, so we repeat the constant STACK_TOP here. | ||
stack_top: 0x0020_0400, | ||
rom: program.base_address | ||
..program.base_address + (program.instructions.len() * WORD_SIZE) as u32, | ||
ram: 0x0010_0000..0xFFFF_0000, | ||
unsafe_ecall_nop: true, | ||
..CENO_PLATFORM | ||
}; | ||
|
||
for max_steps in [1usize << 20, 1usize << 21, 1usize << 22] { | ||
// expand more input size once runtime is acceptable | ||
let mut group = c.benchmark_group(format!("fibonacci_max_steps_{}", max_steps)); | ||
group.sample_size(NUM_SAMPLES); | ||
|
||
// Benchmark the proving time | ||
group.bench_function( | ||
BenchmarkId::new( | ||
"prove_fibonacci", | ||
format!("fibonacci_max_steps_{}", max_steps), | ||
), | ||
|b| { | ||
b.iter_with_setup( | ||
|| { | ||
run_e2e_gen_witness::<E, Pcs>( | ||
program.clone(), | ||
platform.clone(), | ||
stack_size, | ||
heap_size, | ||
vec![], | ||
max_steps, | ||
) | ||
}, | ||
|(prover, _, zkvm_witness, pi, _, _, _)| { | ||
let timer = Instant::now(); | ||
let _ = run_e2e_proof(prover, zkvm_witness, pi); | ||
println!( | ||
"Fibonacci::create_proof, max_steps = {}, time = {}", | ||
max_steps, | ||
timer.elapsed().as_secs_f64() | ||
); | ||
}, | ||
); | ||
}, | ||
); | ||
|
||
group.finish(); | ||
} | ||
|
||
type E = GoldilocksExt2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.