forked from scroll-tech/ceno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further break down e2e logic (scroll-tech#703)
Fixes scroll-tech#691. - Refactors e2e into smaller steps. - Introduces a `run_partial` method which takes a `prefix` argument, indicating when to stop the run of the pipeline. According to this argument, different parts of the state are yielded back. This part isn't too pretty type-wise, but ultimately I think it's not dangerous and a reasonable compromise for the moment. Later edit: I've also included a benchmark for witness generation of the Fibonacci program, since it is a consumer of this refactor and helps to exemplify it.
- Loading branch information
Showing
11 changed files
with
479 additions
and
196 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use std::{fs, path::PathBuf, time::Duration}; | ||
|
||
use ceno_emul::{CENO_PLATFORM, Platform, Program, WORD_SIZE}; | ||
use ceno_zkvm::{ | ||
self, | ||
e2e::{Checkpoint, run_e2e_with_checkpoint}, | ||
}; | ||
use criterion::*; | ||
|
||
use goldilocks::GoldilocksExt2; | ||
use mpcs::BasefoldDefault; | ||
|
||
criterion_group! { | ||
name = fibonacci; | ||
config = Criterion::default().warm_up_time(Duration::from_millis(20000)); | ||
targets = fibonacci_witness | ||
} | ||
|
||
criterion_main!(fibonacci); | ||
|
||
const NUM_SAMPLES: usize = 10; | ||
type Pcs = BasefoldDefault<E>; | ||
type E = GoldilocksExt2; | ||
|
||
// Relevant init data for fibonacci run | ||
fn setup() -> (Program, Platform, u32, u32) { | ||
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(); | ||
|
||
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 | ||
}; | ||
|
||
(program, platform, stack_size, heap_size) | ||
} | ||
|
||
fn fibonacci_witness(c: &mut Criterion) { | ||
let (program, platform, stack_size, heap_size) = setup(); | ||
|
||
let max_steps = usize::MAX; | ||
let mut group = c.benchmark_group(format!("fib_wit_max_steps_{}", max_steps)); | ||
group.sample_size(NUM_SAMPLES); | ||
|
||
// Benchmark the proving time | ||
group.bench_function( | ||
BenchmarkId::new( | ||
"fibonacci_witness", | ||
format!("fib_wit_max_steps_{}", max_steps), | ||
), | ||
|b| { | ||
b.iter_with_setup( | ||
|| { | ||
run_e2e_with_checkpoint::<E, Pcs>( | ||
program.clone(), | ||
platform.clone(), | ||
stack_size, | ||
heap_size, | ||
vec![], | ||
max_steps, | ||
Checkpoint::PrepWitnessGen, | ||
) | ||
}, | ||
|(_, generate_witness)| { | ||
generate_witness(); | ||
}, | ||
); | ||
}, | ||
); | ||
|
||
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.