Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor giza benchmarks #194

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ codegen-units = 1
lto = "thin"
opt-level = 3
debug = 2

17 changes: 17 additions & 0 deletions cairo_programs/fibonacci_10000.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
func main() {
// Call fib(1, 1, 500).
let result: felt = fib(1, 1, 1048675);

ret;
}

func fib(first_element, second_element, n) -> (res: felt) {
jmp fib_body if n != 0;
tempvar result = second_element;
return (second_element,);

fib_body:
tempvar y = first_element + second_element;
return fib(second_element, y, n - 1);
}

1 change: 1 addition & 0 deletions cairo_prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ harness = false
[[bench]]
name = "criterion_giza"
harness = false
required-features = ["giza"]

[package.metadata.wasm-pack.profile.dev]
# Should `wasm-opt` be used to further optimize the wasm binary generated after
Expand Down
29 changes: 9 additions & 20 deletions cairo_prover/benches/criterion_giza.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
#[cfg(feature = "giza")]
use criterion::{black_box, measurement::WallTime, BenchmarkGroup};
use criterion::{criterion_group, criterion_main, Criterion};

use cairo_platinum_prover::{
air::generate_cairo_proof, cairo_layout::CairoLayout, runner::run::generate_prover_args,
};
#[cfg(feature = "giza")]
use criterion::{black_box, measurement::WallTime, BenchmarkGroup};
use criterion::{criterion_group, criterion_main, Criterion};
#[cfg(feature = "giza")]
use stark_platinum_prover::proof::options::{self, SecurityLevel};
use stark_platinum_prover::proof::options::{ProofOptions, SecurityLevel};

#[cfg(feature = "giza")]
pub mod functions;

#[cfg(not(feature = "giza"))]
fn cairo_benches(_: &mut Criterion) {
println!("Enable giza feature to run giza benchmarks");
}

#[cfg(feature = "giza")]
fn cairo_benches(c: &mut Criterion) {
#[cfg(feature = "parallel")]
{
Expand All @@ -33,7 +24,7 @@ fn cairo_benches(c: &mut Criterion) {

let mut group = c.benchmark_group("CAIRO");
group.sample_size(10);
let proof_options = options::ProofOptions::new_secure(SecurityLevel::Provable80Bits, 3);
let proof_options = ProofOptions::new_secure(SecurityLevel::Provable80Bits, 3);

run_lambdaworks_bench(
&mut group,
Expand Down Expand Up @@ -68,36 +59,34 @@ fn cairo_benches(c: &mut Criterion) {
);
}

#[cfg(feature = "giza")]
fn cairo0_program_path(program_name: &str) -> String {
const CARGO_DIR: &str = env!("CARGO_MANIFEST_DIR");
const PROGRAM_BASE_REL_PATH: &str = "/cairo_programs/cairo0/";
let program_base_path = CARGO_DIR.to_string() + PROGRAM_BASE_REL_PATH;
program_base_path + program_name
}

#[cfg(feature = "giza")]
fn run_lambdaworks_bench(
group: &mut BenchmarkGroup<'_, WallTime>,
proof_options: &options::ProofOptions,
proof_options: &ProofOptions,
benchname: &str,
program_path: &str,
layout: CairoLayout,
) {
let program_content = std::fs::read(program_path).unwrap();
let proof_options = ProofOptions::new_secure(SecurityLevel::Provable80Bits, 3);
let (main_trace, pub_inputs) = generate_prover_args(&program_content, &None, layout).unwrap();

group.bench_function(benchname, |bench| {
bench.iter(|| {
black_box(generate_cairo_proof(&main_trace, &pub_inputs, proof_options).unwrap())
black_box(generate_cairo_proof(&main_trace, &pub_inputs, &proof_options).unwrap())
});
});
}

#[cfg(feature = "giza")]
fn run_giza_bench(
group: &mut BenchmarkGroup<'_, WallTime>,
proof_options: &options::ProofOptions,
proof_options: &ProofOptions,
benchname: &str,
program_path: &str,
trace_path: &str,
Expand Down
Loading
Loading