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

improve std performance and console output #69

Merged
merged 3 commits into from
Oct 7, 2024
Merged
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 .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
with:
repository: 0xPolygonHermez/pil2-compiler
token: ${{ secrets.GITHUB_TOKEN }}
ref: develop
ref: 5e4185c07b717f27d627a4249e7665881593f32d
path: pil2-compiler

- name: Install pil2-compiler dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx};
use proofman_hints::{
get_hint_field, get_hint_field_constant, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue,
};
use proofman_util::create_buffer_fast;

use crate::Range;

Expand Down Expand Up @@ -59,8 +60,6 @@ impl<F: PrimeField> SpecifiedRanges<F> {

// Update the multiplicity column
self.update_multiplicity(drained_inputs);

log::info!("{}: Updated inputs for AIR '{}'", Self::MY_NAME, "SpecifiedRanges");
}
}

Expand All @@ -85,7 +84,7 @@ impl<F: PrimeField> SpecifiedRanges<F> {
set_hint_field(self.wcm.get_sctx(), air_instance, *hint, "reference", &mul[index - 1]);
}

log::info!("{}: Drained inputs for AIR '{}'", Self::MY_NAME, "SpecifiedRanges");
log::trace!("{}: ··· Drained inputs for AIR '{}'", Self::MY_NAME, "SpecifiedRanges");
}

fn update_multiplicity(&self, drained_inputs: Vec<(Range<F>, F)>) {
Expand Down Expand Up @@ -212,7 +211,7 @@ impl<F: PrimeField> WitnessComponent<F> for SpecifiedRanges<F> {

let (buffer_size, _) =
ectx.buffer_allocator.as_ref().get_buffer_info(&sctx, self.airgroup_id, self.air_id).unwrap();
let buffer = vec![F::zero(); buffer_size as usize];
let buffer = create_buffer_fast(buffer_size as usize);

// Add a new air instance. Since Specified Ranges is a table, only this air instance is needed
let mut air_instance = AirInstance::new(self.airgroup_id, self.air_id, None, buffer);
Expand Down
7 changes: 3 additions & 4 deletions pil2-components/lib/std/rs/src/range_check/u16air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx};

use proofman_hints::{get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue};
use proofman_util::create_buffer_fast;
use std::sync::atomic::Ordering;

const PROVE_CHUNK_SIZE: usize = 1 << 5;
Expand Down Expand Up @@ -55,8 +56,6 @@ impl<F: PrimeField> U16Air<F> {

// Update the multiplicity column
self.update_multiplicity(drained_inputs);

log::info!("{}: Updated inputs for AIR '{}'", Self::MY_NAME, "U16Air");
}
}

Expand All @@ -76,7 +75,7 @@ impl<F: PrimeField> U16Air<F> {
let mul = &*self.mul.lock().unwrap();
set_hint_field(self.wcm.get_sctx(), air_instance, self.hint.load(Ordering::Acquire), "reference", mul);

log::info!("{}: Drained inputs for AIR '{}'", Self::MY_NAME, "U16Air");
log::trace!("{}: ··· Drained inputs for AIR '{}'", Self::MY_NAME, "U16Air");
}

fn update_multiplicity(&self, drained_inputs: Vec<F>) {
Expand Down Expand Up @@ -116,7 +115,7 @@ impl<F: PrimeField> WitnessComponent<F> for U16Air<F> {

let (buffer_size, _) =
ectx.buffer_allocator.as_ref().get_buffer_info(&sctx, self.airgroup_id, self.air_id).unwrap();
let buffer = vec![F::zero(); buffer_size as usize];
let buffer = create_buffer_fast(buffer_size as usize);

// Add a new air instance. Since U16Air is a table, only this air instance is needed
let mut air_instance = AirInstance::new(self.airgroup_id, self.air_id, None, buffer);
Expand Down
7 changes: 3 additions & 4 deletions pil2-components/lib/std/rs/src/range_check/u8air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use p3_field::PrimeField;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{AirInstance, ExecutionCtx, ProofCtx, SetupCtx};
use proofman_hints::{get_hint_field, get_hint_ids_by_name, set_hint_field, HintFieldOptions, HintFieldValue};
use proofman_util::create_buffer_fast;
use std::sync::atomic::Ordering;

const PROVE_CHUNK_SIZE: usize = 1 << 5;
Expand Down Expand Up @@ -52,8 +53,6 @@ impl<F: PrimeField> U8Air<F> {

// Update the multiplicity column
self.update_multiplicity(drained_inputs);

log::info!("{}: Updated inputs for AIR '{}'", Self::MY_NAME, "U8Air");
}
}

Expand All @@ -73,7 +72,7 @@ impl<F: PrimeField> U8Air<F> {
let mul = &*self.mul.lock().unwrap();
set_hint_field(self.wcm.get_sctx(), air_instance, self.hint.load(Ordering::Acquire), "reference", mul);

log::info!("{}: Drained inputs for AIR '{}'", Self::MY_NAME, "U8Air");
log::trace!("{}: ··· Drained inputs for AIR '{}'", Self::MY_NAME, "U8Air");
}

fn update_multiplicity(&self, drained_inputs: Vec<F>) {
Expand Down Expand Up @@ -113,7 +112,7 @@ impl<F: PrimeField> WitnessComponent<F> for U8Air<F> {

let (buffer_size, _) =
ectx.buffer_allocator.as_ref().get_buffer_info(&sctx, self.airgroup_id, self.air_id).unwrap();
let buffer = vec![F::zero(); buffer_size as usize];
let buffer = create_buffer_fast(buffer_size as usize);

// Add a new air instance. Since U8Air is a table, only this air instance is needed
let mut air_instance = AirInstance::new(self.airgroup_id, self.air_id, None, buffer);
Expand Down
4 changes: 2 additions & 2 deletions pil2-components/lib/std/rs/src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ pub struct Std<F: PrimeField> {
}

impl<F: PrimeField> Std<F> {
const _MY_NAME: &'static str = "STD";
const MY_NAME: &'static str = "STD ";

pub fn new(wcm: Arc<WitnessManager<F>>, rc_air_data: Option<Vec<RCAirData>>) -> Arc<Self> {
let mode = StdMode::new(ModeName::Standard, None, 10);

log::info!("The STD has been initialized on mode {}", mode.name);
log::info!("{}: ··· The PIL2 STD library has been initialized on mode {}", Self::MY_NAME, mode.name);

// Instantiate the STD components
StdProd::new(mode.clone(), wcm.clone());
Expand Down
8 changes: 4 additions & 4 deletions proofman/src/proofman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<F: Field + 'static> ProofMan<F> {
}

fn initialize_provers(sctx: Arc<SetupCtx>, provers: &mut Vec<Box<dyn Prover<F>>>, pctx: Arc<ProofCtx<F>>) {
info!("{}: Initializing prover and creating buffers", Self::MY_NAME);
info!("{}: ··· INITIALIZING PROVER CLIENTS", Self::MY_NAME);

timer_start!(INITIALIZING_PROVERS);
for (prover_idx, air_instance) in pctx.air_instance_repo.air_instances.read().unwrap().iter().enumerate() {
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<F: Field + 'static> ProofMan<F> {
transcript: &mut FFITranscript,
debug_mode: u64,
) {
info!("{}: Calculating challenges for stage {}", Self::MY_NAME, stage);
info!("{}: ··· CALCULATING CHALLENGES FOR STAGE {}", Self::MY_NAME, stage);
let airgroups = proof_ctx.global_info.subproofs.clone();
for (airgroup_id, _airgroup) in airgroups.iter().enumerate() {
if debug_mode != 0 {
Expand Down Expand Up @@ -468,7 +468,7 @@ impl<F: Field + 'static> ProofMan<F> {
let mut air_groups: Vec<_> = air_instances.keys().collect();
air_groups.sort();

info!("{}: >>> PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME);
info!("{}: --- PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME);
info!("{}: ► {} Air instances found:", Self::MY_NAME, air_instances_repo.len());
for air_group in air_groups {
let air_group_instances = air_instances.get(air_group).unwrap();
Expand All @@ -485,6 +485,6 @@ impl<F: Field + 'static> ProofMan<F> {
);
}
}
info!("{}: <<< PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME);
info!("{}: --- PROOF INSTANCES SUMMARY ------------------------", Self::MY_NAME);
}
}
13 changes: 7 additions & 6 deletions proofman/src/witness_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ pub trait WitnessComponent<F>: Send + Sync {

fn calculate_witness(
&self,
stage: u32,
air_instance: Option<usize>,
pctx: Arc<ProofCtx<F>>,
ectx: Arc<ExecutionCtx>,
sctx: Arc<SetupCtx>,
);
_stage: u32,
_air_instance: Option<usize>,
_pctx: Arc<ProofCtx<F>>,
_ectx: Arc<ExecutionCtx>,
_sctx: Arc<SetupCtx>,
) {
}

fn end_proof(&self) {}
}
11 changes: 11 additions & 0 deletions util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
pub mod cli;
pub mod timer_macro;

use std::mem::MaybeUninit;

pub fn create_buffer_fast<F>(buffer_size: usize) -> Vec<F> {
let mut buffer: Vec<MaybeUninit<F>> = Vec::with_capacity(buffer_size);
unsafe {
buffer.set_len(buffer_size);
}
let buffer: Vec<F> = unsafe { std::mem::transmute(buffer) };
buffer
}
Loading