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

feat: Benchmark halo2 flamegraphs #1200

Closed
wants to merge 8 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
2 changes: 1 addition & 1 deletion benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pprof = { version = "0.13", features = [

[features]
default = ["parallel", "mimalloc", "bench-metrics"]
bench-metrics = ["openvm-native-recursion/bench-metrics"]
bench-metrics = ["openvm-native-recursion/bench-metrics", "openvm-native-compiler/bench-metrics"]
profiling = ["openvm-sdk/profiling"]
aggregation = []
static-verifier = ["openvm-native-recursion/static-verifier"]
Expand Down
1 change: 1 addition & 0 deletions benchmarks/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl BenchmarkCli {
halo2_config: Halo2Config {
verifier_k: self.halo2_outer_k.unwrap_or(24),
wrapper_k: self.halo2_wrapper_k,
profiling: self.profiling,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ default = ["parallel"]
bench-metrics = [
"openvm-circuit/bench-metrics",
"openvm-native-recursion/bench-metrics",
"openvm-native-compiler/bench-metrics",
]
profiling = ["openvm-circuit/function-span", "openvm-transpiler/function-span"]
parallel = ["openvm-circuit/parallel"]
Expand Down
3 changes: 3 additions & 0 deletions crates/sdk/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct Halo2Config {
pub verifier_k: usize,
/// If not specified, keygen will tune wrapper_k automatically.
pub wrapper_k: Option<usize>,
/// Sets the profiling mode of halo2 VM
pub profiling: bool,
}

impl<VC> AppConfig<VC> {
Expand Down Expand Up @@ -101,6 +103,7 @@ impl Default for AggConfig {
halo2_config: Halo2Config {
verifier_k: 24,
wrapper_k: None,
profiling: false,
},
}
}
Expand Down
8 changes: 7 additions & 1 deletion crates/sdk/src/keygen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub struct Halo2ProvingKey {
pub verifier: Halo2VerifierProvingKey,
/// Wrapper circuit to verify static verifier and reduce the verification costs in the final proof.
pub wrapper: Halo2WrapperProvingKey,
/// Whether to collect detailed profiling metrics
pub profiling: bool,
}

impl<VC: VmConfig<F>> AppProvingKey<VC>
Expand Down Expand Up @@ -315,7 +317,11 @@ impl AggProvingKey {
} else {
Halo2WrapperProvingKey::keygen_auto_tune(reader, dummy_snark)
};
let halo2_pk = Halo2ProvingKey { verifier, wrapper };
let halo2_pk = Halo2ProvingKey {
verifier,
wrapper,
profiling: halo2_config.profiling,
};
Self {
agg_stark_pk,
halo2_pk,
Expand Down
7 changes: 5 additions & 2 deletions crates/sdk/src/prover/halo2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ impl Halo2Prover {
pub fn prove_for_evm(&self, root_proof: &Proof<RootSC>) -> EvmProof {
let mut witness = Witness::default();
root_proof.write(&mut witness);
let snark = info_span!("prove", group = "halo2_outer")
.in_scope(|| self.halo2_pk.verifier.prove(&self.verifier_srs, witness));
let snark = info_span!("prove", group = "halo2_outer").in_scope(|| {
self.halo2_pk
.verifier
.prove(&self.verifier_srs, witness, self.halo2_pk.profiling)
});
info_span!("prove_for_evm", group = "halo2_wrapper").in_scope(|| {
self.halo2_pk
.wrapper
Expand Down
1 change: 1 addition & 0 deletions crates/sdk/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fn agg_config_for_test() -> AggConfig {
halo2_config: Halo2Config {
verifier_k: 24,
wrapper_k: None,
profiling: false,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion extensions/native/recursion/src/halo2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,15 @@ impl Halo2Prover {
pk: &ProvingKey<G1Affine>,
dsl_operations: DslOperations<C>,
witness: Witness<C>,
profiling: bool,
) -> Snark {
let k = config_params.k;
#[cfg(feature = "bench-metrics")]
let start = std::time::Instant::now();
let builder = Self::builder(CircuitBuilderStage::Prover, k)
.use_params(config_params)
.use_break_points(break_points);
let builder = Self::populate(builder, dsl_operations, witness, false);
let builder = Self::populate(builder, dsl_operations, witness, profiling);
#[cfg(feature = "bench-metrics")]
{
let stats = builder.statistics();
Expand Down
2 changes: 1 addition & 1 deletion extensions/native/recursion/src/halo2/testing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn run_static_verifier_test(
.entered();
let mut witness = Witness::default();
vparams.data.proof.write(&mut witness);
let static_verifier_snark = stark_verifier_circuit.prove(params, witness);
let static_verifier_snark = stark_verifier_circuit.prove(params, witness, false);
info_span.exit();
(stark_verifier_circuit, static_verifier_snark)
}
8 changes: 7 additions & 1 deletion extensions/native/recursion/src/halo2/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ pub fn generate_halo2_verifier_proving_key(
}

impl Halo2VerifierProvingKey {
pub fn prove(&self, params: &Halo2Params, witness: Witness<OuterConfig>) -> Snark {
pub fn prove(
&self,
params: &Halo2Params,
witness: Witness<OuterConfig>,
profiling: bool,
) -> Snark {
Halo2Prover::prove(
params,
self.pinning.metadata.config_params.clone(),
self.pinning.metadata.break_points.clone(),
&self.pinning.pk,
self.dsl_ops.clone(),
witness,
profiling,
)
}
// TODO: Add verify method
Expand Down
Loading