Skip to content

Commit

Permalink
add create buffer fast function
Browse files Browse the repository at this point in the history
  • Loading branch information
xavi-pinsach committed Oct 7, 2024
1 parent eb30ba5 commit 75dd845
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
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 @@ -210,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
3 changes: 2 additions & 1 deletion 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 @@ -114,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
3 changes: 2 additions & 1 deletion 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 @@ -111,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
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);
}
}
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
}

0 comments on commit 75dd845

Please sign in to comment.