Skip to content

Commit

Permalink
Better logging and perf improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush committed Dec 21, 2021
1 parent 82ba6db commit f7cd635
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
3 changes: 2 additions & 1 deletion phase1-cli/src/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn combine<T: Engine + Sync>(
.open(combined_filename)
.expect("unable to create new combined file in this directory");

println!("parameters for output: {:?}", parameters_for_output);
tracing::debug!("Parameters for output: {:?}", parameters_for_output);

writer
.set_len(parameters_for_output.accumulator_size as u64)
Expand All @@ -94,6 +94,7 @@ pub fn combine<T: Engine + Sync>(
parameters.total_size_in_log2,
parameters.batch_size,
);
tracing::debug!("Parameters for aggregation: {:?}", parameters);
let res = Phase1::aggregation(
&readers
.iter()
Expand Down
1 change: 1 addition & 0 deletions phase1-cli/src/contribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn contribute<T: Engine + Sync>(
metadata.len()
);
}
dbg!(metadata.len());
}

let readable_map = unsafe {
Expand Down
40 changes: 31 additions & 9 deletions phase1/src/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
let span = info_span!("phase1-aggregation");
let _enter = span.enter();

info!("starting...");
info!("Starting Aggregation");

for (chunk_index, (input, compressed_input)) in inputs.iter().enumerate() {
let chunk_parameters =
Expand All @@ -33,9 +33,10 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
let start = chunk_index * chunk_parameters.chunk_size;
let end = (chunk_index + 1) * chunk_parameters.chunk_size;

debug!("combining chunk from {} to {}", start, end);
debug!("Combining chunk from {} to {}", start, end);
debug!("Chunk parameters: {:?}", chunk_parameters);

let span = info_span!("batch", start, end);
let span = info_span!("Batch", start, end);
let _enter = span.enter();

match parameters.proving_system {
Expand All @@ -53,24 +54,37 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
.write_batch(&elements, compressed_output)
.expect("should have written batch");

trace!("tau_g1 aggregation for chunk {} successful", chunk_index);
debug!(
"Tau G1 aggregation for chunk {} successful; {} G1 elements written",
chunk_index,
elements.len()
);
});

debug!(
"`start = {}, chunk_parameters.powers_length = {}, start < chunk_parameters.powers_length = {}`",
start,
chunk_parameters.powers_length,
start < chunk_parameters.powers_length
);
if start < chunk_parameters.powers_length {
rayon::scope(|t| {
let _enter = span.enter();

t.spawn(|_| {
let _enter = span.enter();

let elements: Vec<E::G2Affine> = in_tau_g2
.read_batch(compressed_input, CheckForCorrectness::No)
.expect("should have read batch");
tau_g2
.write_batch(&elements, compressed_output)
.expect("should have written batch");

trace!("tau_g2 aggregation for chunk {} successful", chunk_index);
debug!(
"Tau G2 aggregation for chunk {} successful; {} G2 elements written",
chunk_index,
elements.len()
);
});

t.spawn(|_| {
Expand All @@ -83,7 +97,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
.write_batch(&elements, compressed_output)
.expect("should have written batch");

trace!("alpha_g1 aggregation for chunk {} successful", chunk_index);
debug!(
"alpha_g1 aggregation for chunk {} successful; {} G1 elements written",
chunk_index,
elements.len()
);
});

t.spawn(|_| {
Expand All @@ -96,7 +114,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
.write_batch(&elements, compressed_output)
.expect("should have written batch");

trace!("beta_g1 aggregation for chunk {} successful", chunk_index);
debug!(
"beta_g1 aggregation for chunk {} successful; {} G1 elements written",
chunk_index,
elements.len()
);
});
});
}
Expand All @@ -108,7 +130,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
beta_g2
.write_element(&element, compressed_output)
.expect("should have written element");
trace!("beta_g2 aggregation for chunk {} successful", chunk_index);
debug!("beta_g2 aggregation for chunk {} successful", chunk_index);
}
});
}
Expand Down
39 changes: 22 additions & 17 deletions phase1/src/computation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
parameters: &'a Phase1Parameters<E>,
) -> Result<()> {
let span = info_span!("phase1-computation");
let _ = span.enter();
let _enter = span.enter();

info!("starting...");

Expand All @@ -31,6 +31,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
// Get mutable references of the outputs.
let (tau_g1_outputs, tau_g2_outputs, alpha_g1_outputs, beta_g1_outputs, beta_g2_outputs) =
split_mut(output, parameters, compressed_output);
info!("Parameters for contribution: {:?}", parameters);

match parameters.proving_system {
ProvingSystem::Groth16 => {
Expand All @@ -50,7 +51,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
debug!("contributing to chunk from {} to {}", start, end);

let span = info_span!("batch", start, end);
let _ = span.enter();
let _enter = span.enter();

// Determine the chunk start and end indices based on the contribution mode.
let (start_chunk, end_chunk) = match parameters.contribution_mode {
Expand All @@ -62,10 +63,10 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
};

rayon_cfg::scope(|t| {
let _ = span.enter();
let _enter = span.enter();

t.spawn(|_| {
let _ = span.enter();
let _enter = span.enter();

// Generate powers from `start` to `end` (e.g. [0,4) then [4, 8) etc.)
let powers = generate_powers_of_tau::<E>(&key.tau, start, end);
Expand All @@ -76,10 +77,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
// and write the updated value (without allocating) to the
// output buffer
rayon_cfg::scope(|t| {
let _ = span.enter();
let _enter = span.enter();
info!("Starting powers of Tau in G1");

t.spawn(|_| {
let _ = span.enter();
let _enter = span.enter();

// Check that the chunk is of nonzero length.
assert!(tau_g1_inputs.len() > 0);
Expand All @@ -93,7 +95,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
)
.expect("could not apply powers of tau to tau_g1 elements");

trace!("applied powers to tau_g1 elements");
info!("Applied powers to tau_g1 elements");
});
if start < parameters.powers_length {
// if the `end` would be out of bounds, then just process until
Expand All @@ -118,10 +120,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
};

rayon_cfg::scope(|t| {
let _ = span.enter();
let _enter = span.enter();

t.spawn(|_| {
let _ = span.enter();
let _enter = span.enter();
info!("Starting powers of Tau in G2");

// Check that the chunk is of nonzero length.
assert!(tau_g2_inputs.len() > 0);
Expand All @@ -135,11 +138,12 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
)
.expect("could not apply powers of tau to tau_g2 elements");

trace!("applied powers to tau_g2 elements");
trace!("Applied powers of Tau in G2");
});

t.spawn(|_| {
let _ = span.enter();
let _enter = span.enter();
info!("Starting Alpha G1 elements");

// Check that the chunk is of nonzero length.
assert!(alpha_g1_inputs.len() > 0);
Expand All @@ -153,11 +157,12 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
)
.expect("could not apply powers of tau to alpha_g1 elements");

trace!("applied powers to alpha_g1 elements");
info!("Applied powers to Alpha G1 elements");
});

t.spawn(|_| {
let _ = span.enter();
info!("Starting beta G1 elements");
let _enter = span.enter();

// Check that the chunk is of nonzero length.
assert!(beta_g1_inputs.len() > 0);
Expand All @@ -171,7 +176,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
)
.expect("could not apply powers of tau to beta_g1 elements");

trace!("applied powers to beta_g1 elements");
trace!("Applied powers to Beta G1 elements");
});
});
}
Expand Down Expand Up @@ -249,7 +254,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
debug!("contributing to chunk from {} to {}", start, end);

let span = info_span!("batch", start, end);
let _ = span.enter();
let _enter = span.enter();

// Determine the chunk start and end indices based on the contribution mode.
let (start_chunk, end_chunk) = match parameters.contribution_mode {
Expand All @@ -261,10 +266,10 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> {
};

rayon_cfg::scope(|t| {
let _ = span.enter();
let _enter = span.enter();

t.spawn(|_| {
let _ = span.enter();
let _enter = span.enter();

// Generate powers from `start` to `end` (e.g. [0,4) then [4, 8) etc.)
let powers = generate_powers_of_tau::<E>(&key.tau, start, end);
Expand Down
7 changes: 4 additions & 3 deletions phase1/src/helpers/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ pub(crate) fn apply_powers<C: AffineCurve>(
powers: &[C::ScalarField],
coeff: Option<&C::ScalarField>,
) -> Result<()> {
tracing::debug!("Applying powers {} to {}", start, end);
let in_size = buffer_size::<C>(input_compressed);
let out_size = buffer_size::<C>(output_compressed);

// Read the input
let mut elements =
let elements =
&mut input[start * in_size..end * in_size].read_batch::<C>(input_compressed, check_input_for_correctness)?;
// calculate the powers
batch_exp(&mut elements, &powers[..end - start], coeff)?;
batch_exp(elements, &powers[..(end - start)], coeff)?;
// write back
output[start * out_size..end * out_size].write_batch(&elements, output_compressed)?;
output[(start * out_size)..(end * out_size)].write_batch(elements, output_compressed)?;

Ok(())
}
Expand Down

0 comments on commit f7cd635

Please sign in to comment.