Adjust default parameters (#406)
- Update formula in `estimate_verif_num_gates` after the update in the recursive verification from https://github.com/0xPARC/pod2/pull/397 - Update the parameters to get better utilization of 2^16 rows - Update metrics report to be more compact
This commit is contained in:
parent
a24bbf7a3b
commit
e1f8a9ad8b
5 changed files with 70 additions and 16 deletions
|
|
@ -1506,7 +1506,7 @@ pub fn calculate_statements_hash_circuit(
|
|||
statements: &[StatementTarget],
|
||||
) -> HashOutTarget {
|
||||
assert!(statements.len() <= params.num_public_statements_hash);
|
||||
let measure = measure_gates_begin!(builder, "CalculateId");
|
||||
let measure = measure_gates_begin!(builder, "CalculateStsHash");
|
||||
let statements_rev_flattened = statements.iter().rev().flat_map(|s| s.flatten());
|
||||
let mut none_st = mainpod::Statement::from(Statement::None);
|
||||
pad_statement(params, &mut none_st);
|
||||
|
|
@ -1561,6 +1561,7 @@ fn build_custom_predicate_table_circuit(
|
|||
let mut custom_predicate_table =
|
||||
Vec::with_capacity(params.max_custom_predicate_batches * params.max_custom_batch_size);
|
||||
for cpb in custom_predicate_batches {
|
||||
let measure_cpb = measure_gates_begin!(builder, "CustomPredBatch");
|
||||
let id = cpb.id(builder); // constrain the id
|
||||
for (index, cp) in cpb.predicates.iter().enumerate() {
|
||||
let statements = cp
|
||||
|
|
@ -1582,6 +1583,7 @@ fn build_custom_predicate_table_circuit(
|
|||
let in_query_hash = entry.hash(builder);
|
||||
custom_predicate_table.push(in_query_hash);
|
||||
}
|
||||
measure_gates_end!(builder, measure_cpb);
|
||||
}
|
||||
measure_gates_end!(builder, measure);
|
||||
Ok(custom_predicate_table)
|
||||
|
|
|
|||
|
|
@ -54,11 +54,23 @@ impl Metrics {
|
|||
pub fn print(&self) {
|
||||
println!("Gate count:");
|
||||
let mut count = HashMap::new();
|
||||
let mut list = Vec::new();
|
||||
for (name, num_gates) in &self.gates {
|
||||
let n = count.entry(name).or_insert(0);
|
||||
let (n, gates) = count.entry(name).or_insert((0, 0));
|
||||
if *n == 0 {
|
||||
list.push(name);
|
||||
}
|
||||
*n += 1;
|
||||
println!("- {} [{}]: {}", name, *n, num_gates);
|
||||
*gates += num_gates;
|
||||
}
|
||||
for name in list.iter().rev() {
|
||||
let (n, total_gates) = count.get(name).expect("key inserted in previous loop");
|
||||
let avg_gates: f64 = (*total_gates as f64) / (*n as f64);
|
||||
println!("- {}: {} x {:.01} = {}", name, n, avg_gates, total_gates);
|
||||
}
|
||||
}
|
||||
pub fn reset(&mut self) {
|
||||
*self = Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +94,15 @@ pub mod measure_macros {
|
|||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! measure_gates_reset {
|
||||
() => {{
|
||||
use $crate::backends::plonky2::circuits::metrics::METRICS;
|
||||
let mut metrics = METRICS.lock().unwrap();
|
||||
metrics.reset();
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! measure_gates_print {
|
||||
() => {{
|
||||
|
|
@ -108,6 +129,11 @@ pub mod measure_macros {
|
|||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! measure_gates_reset {
|
||||
() => {};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! measure_gates_print {
|
||||
() => {{
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ pub(crate) fn layout_statements(
|
|||
}
|
||||
|
||||
// Public statements
|
||||
assert!(inputs.public_statements.len() < params.max_public_statements);
|
||||
assert!(inputs.public_statements.len() <= params.max_public_statements);
|
||||
for i in 0..params.max_public_statements {
|
||||
let mut st = inputs
|
||||
.public_statements
|
||||
|
|
@ -859,6 +859,25 @@ pub mod tests {
|
|||
Ok(pod.verify()?)
|
||||
}
|
||||
|
||||
// `RUST_LOG=pod2::backends=debug cargo test --release --no-default-features --features=backend_plonky2,mem_cache,zk,metrics test_measure_main_pod -- --nocapture --ignored`
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_measure_main_pod() -> frontend::Result<()> {
|
||||
env_logger::init();
|
||||
let params = Params::default();
|
||||
println!("{:#?}", params);
|
||||
let vd_set = VDSet::new(params.max_depth_mt_vds, &[]).unwrap();
|
||||
|
||||
// Calculate rec common first to avoid duplicate metrics in `pod_builder.prove`
|
||||
let _rec_common_circuit_data = cache_get_standard_rec_main_pod_common_circuit_data();
|
||||
let pod_builder = MainPodBuilder::new(¶ms, &vd_set);
|
||||
let prover = Prover {};
|
||||
crate::measure_gates_reset!();
|
||||
let _pod = pod_builder.prove(&prover)?;
|
||||
crate::measure_gates_print!();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_main_tickets() -> frontend::Result<()> {
|
||||
let params = Params::default();
|
||||
|
|
|
|||
|
|
@ -435,13 +435,13 @@ fn estimate_verif_num_gates(degree_bits: usize) -> usize {
|
|||
{
|
||||
// Formula obtained via linear regression using
|
||||
// `test_measure_zk_recursion` results with `standard_recursion_zk_config`.
|
||||
num_gates = 244 * degree_bits + 1127;
|
||||
num_gates = 243 * degree_bits + 1522;
|
||||
}
|
||||
#[cfg(not(feature = "zk"))]
|
||||
{
|
||||
// Formula obtained via linear regression using `test_measure_recursion`
|
||||
// results with `standard_recursion_config`.
|
||||
num_gates = 236 * degree_bits + 1171;
|
||||
num_gates = 236 * degree_bits + 1580;
|
||||
}
|
||||
// Add 2% for error because the results are not a clean line
|
||||
num_gates * 102 / 100
|
||||
|
|
@ -523,6 +523,11 @@ pub fn common_data_for_recursion<I: InnerCircuit>(
|
|||
}
|
||||
|
||||
if total_num_gates < (1 << degree_bits) {
|
||||
log::debug!(
|
||||
"degree_bits = {}, free_gates = {}",
|
||||
degree_bits,
|
||||
(1 << degree_bits) - total_num_gates
|
||||
);
|
||||
break;
|
||||
}
|
||||
degree_bits = log2_ceil(total_num_gates);
|
||||
|
|
@ -956,6 +961,7 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// `cargo test --release --no-default-features --features=backend_plonky2,mem_cache,zk,metrics test_measure_recursion -- --nocapture --ignored`
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_measure_recursion() {
|
||||
|
|
@ -1005,6 +1011,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
// `cargo test --release --no-default-features --features=backend_plonky2,mem_cache,zk,metrics test_measure_zk_recursion -- --nocapture --ignored`
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_measure_zk_recursion() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue