Skip to content

Commit

Permalink
replace timing reporter with profiler
Browse files Browse the repository at this point in the history
Also, make some debug output only appear when DEBUG=1.
  • Loading branch information
jan-ferdinand committed Nov 15, 2022
1 parent ccf9f8a commit c40c1bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
7 changes: 0 additions & 7 deletions triton-vm/src/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use twenty_first::shared_math::rescue_prime_digest::Digest;
use twenty_first::shared_math::traits::FiniteField;
use twenty_first::shared_math::traits::{CyclicGroupGenerator, ModPowU32};
use twenty_first::shared_math::x_field_element::XFieldElement;
use twenty_first::timing_reporter::TimingReporter;
use twenty_first::util_types::algebraic_hasher::{AlgebraicHasher, Hashable};
use twenty_first::util_types::merkle_tree::{MerkleTree, PartialAuthenticationPath};

Expand Down Expand Up @@ -127,14 +126,11 @@ impl<H: AlgebraicHasher> Fri<H> {
);

// commit phase
let mut timer = TimingReporter::start();
let (codewords, merkle_trees): (Vec<Vec<XFieldElement>>, Vec<MerkleTree<H>>) =
self.commit(codeword, proof_stream)?.into_iter().unzip();
timer.elapsed("Commit phase");

// Fiat-Shamir to get indices
let top_level_indices: Vec<usize> = self.sample_indices(&proof_stream.prover_fiat_shamir());
timer.elapsed("Sample indices");

// query phase
// query step 0: enqueue authentication paths for all points `A` into proof stream
Expand All @@ -158,11 +154,8 @@ impl<H: AlgebraicHasher> Fri<H> {
.collect();
Self::enqueue_auth_pairs(&b_indices, &codewords[r], &merkle_trees[r], proof_stream);
current_domain_len /= 2;
timer.elapsed(&format!("Query phase {}", r));
}

println!("FRI-prover, timing report\n{}", timer.finish());

let merkle_root_of_1st_round: Digest = merkle_trees[0].get_root();
Ok((top_level_indices, merkle_root_of_1st_round))
}
Expand Down
14 changes: 9 additions & 5 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,12 @@ impl Stark {

prof_stop!(maybe_profiler, "open trace leafs");

println!(
"Created proof containing {} B-field elements",
proof_stream.transcript_length()
);
if std::env::var("DEBUG").is_ok() {
println!(
"Created proof containing {} B-field elements",
proof_stream.transcript_length()
);
}

proof_stream.to_proof()
}
Expand Down Expand Up @@ -464,7 +466,9 @@ impl Stark {
(extension_codewords, extension_degree_bounds, "ext"),
(quotient_codewords, quotient_degree_bounds, "quot"),
] {
println!("{}", identifier);
if std::env::var("DEBUG").is_ok() {
println!(" --- next up: {identifier} codewords");
}
// TODO with the DEBUG CODE and enumerate removed, the iterators can be `into_par_iter`
for (idx, (codeword, degree_bound)) in
codewords.into_iter().zip_eq(bounds.iter()).enumerate()
Expand Down
16 changes: 10 additions & 6 deletions triton-vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ pub mod triton_vm_tests {
use num_traits::{One, Zero};
use rand::rngs::ThreadRng;
use rand::{Rng, RngCore};
use triton_profiler::triton_profiler::TritonProfiler;
use twenty_first::shared_math::mpolynomial::MPolynomial;
use twenty_first::shared_math::other;
use twenty_first::shared_math::other::roundup_npo2;
use twenty_first::shared_math::rescue_prime_regular::{RescuePrimeRegular, NUM_ROUNDS};
use twenty_first::timing_reporter::TimingReporter;

use crate::instruction::{sample_programs, AnInstruction};
use crate::shared_tests::SourceCodeAndInput;
Expand Down Expand Up @@ -823,7 +823,7 @@ pub mod triton_vm_tests {
}

fn processor_table_constraints_evaluate_to_zero(all_programs: &[SourceCodeAndInput]) {
let mut timer = TimingReporter::start();
let mut profiler = TritonProfiler::new("Table Constraints Evaluate to Zero Test");
for (code_idx, program) in all_programs.iter().enumerate() {
let (aet, output, err) = program.simulate();

Expand Down Expand Up @@ -862,6 +862,8 @@ pub mod triton_vm_tests {
let ext_processor_table =
processor_table.extend(&challenges.processor_table_challenges, interpolant_degree);

let program_idx_string = format!("Program number {code_idx:>2}");
profiler.start(&program_idx_string);
for (row_idx, (current_row, next_row)) in ext_processor_table
.data()
.iter()
Expand Down Expand Up @@ -898,11 +900,13 @@ pub mod triton_vm_tests {
}
}
}
timer.elapsed(
format!("Program number {code_idx:>2} (cycles: {num_cycles:>4})").as_str(),
);
let num_cycles_string = format!("took {num_cycles:>4} VM cycles");
profiler.start(&num_cycles_string);
profiler.stop(&num_cycles_string);
profiler.stop(&program_idx_string);
}
println!("{}", timer.finish());
profiler.finish();
println!("{}", profiler.report());
}

fn _assert_air_constraints_on_matrix(
Expand Down

0 comments on commit c40c1bc

Please sign in to comment.