mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-09 01:03:08 +00:00
feature-gate stub TimingTree
This commit is contained in:
parent
16ddfcb94c
commit
585495d314
@ -10,6 +10,10 @@ categories = ["cryptography"]
|
||||
edition = "2021"
|
||||
default-run = "generate_constants"
|
||||
|
||||
[features]
|
||||
default = ["timing"]
|
||||
timing = []
|
||||
|
||||
[dependencies]
|
||||
plonky2_field = { path = "../field" }
|
||||
plonky2_util = { path = "../util" }
|
||||
|
||||
@ -71,7 +71,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
|
||||
rate_bits: usize,
|
||||
blinding: bool,
|
||||
cap_height: usize,
|
||||
timing: &mut TimingTree,
|
||||
_timing: &mut TimingTree,
|
||||
fft_root_table: Option<&FftRootTable<F>>,
|
||||
) -> Self
|
||||
where
|
||||
@ -79,7 +79,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
|
||||
{
|
||||
let degree = polynomials[0].len();
|
||||
let lde_values = timed!(
|
||||
timing,
|
||||
_timing,
|
||||
"FFT + blinding",
|
||||
Self::lde_values(&polynomials, rate_bits, blinding, fft_root_table)
|
||||
);
|
||||
@ -87,7 +87,7 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
|
||||
let mut leaves = timed!(timing, "transpose LDEs", transpose(&lde_values));
|
||||
reverse_index_bits_in_place(&mut leaves);
|
||||
let merkle_tree = timed!(
|
||||
timing,
|
||||
_timing,
|
||||
"build Merkle tree",
|
||||
MerkleTree::new(leaves, cap_height)
|
||||
);
|
||||
|
||||
@ -23,7 +23,7 @@ pub fn fri_proof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const
|
||||
lde_polynomial_values: PolynomialValues<F::Extension>,
|
||||
challenger: &mut Challenger<F, C::Hasher>,
|
||||
fri_params: &FriParams,
|
||||
timing: &mut TimingTree,
|
||||
_timing: &mut TimingTree,
|
||||
) -> FriProof<F, C::Hasher, D>
|
||||
where
|
||||
[(); C::Hasher::HASH_SIZE]:,
|
||||
@ -33,7 +33,7 @@ where
|
||||
|
||||
// Commit phase
|
||||
let (trees, final_coeffs) = timed!(
|
||||
timing,
|
||||
_timing,
|
||||
"fold codewords in the commitment phase",
|
||||
fri_committed_trees::<F, C, D>(
|
||||
lde_polynomial_coeffs,
|
||||
@ -46,7 +46,7 @@ where
|
||||
// PoW phase
|
||||
let current_hash = challenger.get_hash();
|
||||
let pow_witness = timed!(
|
||||
timing,
|
||||
_timing,
|
||||
"find proof-of-work witness",
|
||||
fri_proof_of_work::<F, C, D>(current_hash, &fri_params.config)
|
||||
);
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
#[cfg(feature = "timing")]
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use log::{log, Level};
|
||||
|
||||
/// The hierarchy of scopes, and the time consumed by each one. Useful for profiling.
|
||||
#[cfg(feature = "timing")]
|
||||
pub struct TimingTree {
|
||||
/// The name of this scope.
|
||||
name: String,
|
||||
@ -16,13 +18,25 @@ pub struct TimingTree {
|
||||
children: Vec<TimingTree>,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "timing"))]
|
||||
pub struct TimingTree(Level);
|
||||
|
||||
#[cfg(feature = "timing")]
|
||||
impl Default for TimingTree {
|
||||
fn default() -> Self {
|
||||
TimingTree::new("root", Level::Debug)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "timing"))]
|
||||
impl Default for TimingTree {
|
||||
fn default() -> Self {
|
||||
TimingTree::new("", Level::Debug)
|
||||
}
|
||||
}
|
||||
|
||||
impl TimingTree {
|
||||
#[cfg(feature = "timing")]
|
||||
pub fn new(root_name: &str, level: Level) -> Self {
|
||||
Self {
|
||||
name: root_name.to_string(),
|
||||
@ -33,18 +47,26 @@ impl TimingTree {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "timing"))]
|
||||
pub fn new(_root_name: &str, level: Level) -> Self {
|
||||
Self(level)
|
||||
}
|
||||
|
||||
/// Whether this scope is still in scope.
|
||||
#[cfg(feature = "timing")]
|
||||
fn is_open(&self) -> bool {
|
||||
self.exit_time.is_none()
|
||||
}
|
||||
|
||||
/// A description of the stack of currently-open scopes.
|
||||
#[cfg(feature = "timing")]
|
||||
pub fn open_stack(&self) -> String {
|
||||
let mut stack = Vec::new();
|
||||
self.open_stack_helper(&mut stack);
|
||||
stack.join(" > ")
|
||||
}
|
||||
|
||||
#[cfg(feature = "timing")]
|
||||
fn open_stack_helper(&self, stack: &mut Vec<String>) {
|
||||
if self.is_open() {
|
||||
stack.push(self.name.clone());
|
||||
@ -54,6 +76,7 @@ impl TimingTree {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "timing")]
|
||||
pub fn push(&mut self, ctx: &str, mut level: log::Level) {
|
||||
assert!(self.is_open());
|
||||
|
||||
@ -77,6 +100,7 @@ impl TimingTree {
|
||||
}
|
||||
|
||||
/// Close the deepest open scope from this tree.
|
||||
#[cfg(feature = "timing")]
|
||||
pub fn pop(&mut self) {
|
||||
assert!(self.is_open());
|
||||
|
||||
@ -90,6 +114,7 @@ impl TimingTree {
|
||||
self.exit_time = Some(Instant::now());
|
||||
}
|
||||
|
||||
#[cfg(feature = "timing")]
|
||||
fn duration(&self) -> Duration {
|
||||
self.exit_time
|
||||
.unwrap_or_else(Instant::now)
|
||||
@ -97,6 +122,7 @@ impl TimingTree {
|
||||
}
|
||||
|
||||
/// Filter out children with a low duration.
|
||||
#[cfg(feature = "timing")]
|
||||
pub fn filter(&self, min_delta: Duration) -> Self {
|
||||
Self {
|
||||
name: self.name.clone(),
|
||||
@ -112,10 +138,17 @@ impl TimingTree {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "timing")]
|
||||
pub fn print(&self) {
|
||||
self.print_helper(0);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "timing"))]
|
||||
pub fn print(&self) {
|
||||
log!(self.0, "TimingTree is not supported without the 'timing' feature enabled");
|
||||
}
|
||||
|
||||
#[cfg(feature = "timing")]
|
||||
fn print_helper(&self, depth: usize) {
|
||||
let prefix = "| ".repeat(depth);
|
||||
log!(
|
||||
@ -135,16 +168,26 @@ impl TimingTree {
|
||||
#[macro_export]
|
||||
macro_rules! timed {
|
||||
($timing_tree:expr, $level:expr, $ctx:expr, $exp:expr) => {{
|
||||
#[cfg(feature = "timing")]
|
||||
$timing_tree.push($ctx, $level);
|
||||
|
||||
let res = $exp;
|
||||
|
||||
#[cfg(feature = "timing")]
|
||||
$timing_tree.pop();
|
||||
|
||||
res
|
||||
}};
|
||||
// If no context is specified, default to Debug.
|
||||
($timing_tree:expr, $ctx:expr, $exp:expr) => {{
|
||||
#[cfg(feature = "timing")]
|
||||
$timing_tree.push($ctx, log::Level::Debug);
|
||||
|
||||
let res = $exp;
|
||||
|
||||
#[cfg(feature = "timing")]
|
||||
$timing_tree.pop();
|
||||
|
||||
res
|
||||
}};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user