Skip to content

Commit

Permalink
Not creating unnecessary instances of arith tables
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Nov 22, 2024
1 parent b1c9daa commit c94771f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions state-machines/arith/src/arith_range_table.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::{
atomic::{AtomicU32, Ordering},
atomic::{AtomicBool, AtomicU32, Ordering},
Arc, Mutex,
};

Expand All @@ -21,6 +21,7 @@ pub struct ArithRangeTableSM<F> {
// Inputs
num_rows: usize,
multiplicity: Mutex<Vec<u64>>,
used: AtomicBool,
}

impl<F: Field> ArithRangeTableSM<F> {
Expand All @@ -34,6 +35,7 @@ impl<F: Field> ArithRangeTableSM<F> {
registered_predecessors: AtomicU32::new(0),
num_rows: air.num_rows(),
multiplicity: Mutex::new(vec![0; air.num_rows()]),
used: AtomicBool::new(false),
};
let arith_range_table_sm = Arc::new(arith_range_table_sm);

Expand All @@ -47,7 +49,9 @@ impl<F: Field> ArithRangeTableSM<F> {
}

pub fn unregister_predecessor(&self) {
if self.registered_predecessors.fetch_sub(1, Ordering::SeqCst) == 1 {
if self.registered_predecessors.fetch_sub(1, Ordering::SeqCst) == 1 &&
self.used.load(Ordering::SeqCst)
{
self.create_air_instance();
}
}
Expand All @@ -58,6 +62,7 @@ impl<F: Field> ArithRangeTableSM<F> {
for (row, value) in inputs {
_multiplicity[row] += value;
}
self.used.store(true, Ordering::Relaxed);
}
pub fn create_air_instance(&self) {
let ectx = self.wcm.get_ectx();
Expand Down Expand Up @@ -86,7 +91,7 @@ impl<F: Field> ArithRangeTableSM<F> {
.for_each(|(i, input)| *input = F::from_canonical_u64(multiplicity_[i]));

info!(
"{}: ··· Creating Binary basic table instance [{} rows filled 100%]",
"{}: ··· Creating Arith range basic table instance [{} rows filled 100%]",
Self::MY_NAME,
self.num_rows,
);
Expand Down
11 changes: 8 additions & 3 deletions state-machines/arith/src/arith_table.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::{
atomic::{AtomicU32, Ordering},
atomic::{AtomicBool, AtomicU32, Ordering},
Arc, Mutex,
};

Expand All @@ -21,6 +21,7 @@ pub struct ArithTableSM<F> {
// Inputs
num_rows: usize,
multiplicity: Mutex<Vec<u64>>,
used: AtomicBool,
}

impl<F: Field> ArithTableSM<F> {
Expand All @@ -34,6 +35,7 @@ impl<F: Field> ArithTableSM<F> {
registered_predecessors: AtomicU32::new(0),
num_rows: air.num_rows(),
multiplicity: Mutex::new(vec![0; air.num_rows()]),
used: AtomicBool::new(false),
};
let arith_table_sm = Arc::new(_arith_table_sm);

Expand All @@ -47,7 +49,9 @@ impl<F: Field> ArithTableSM<F> {
}

pub fn unregister_predecessor(&self) {
if self.registered_predecessors.fetch_sub(1, Ordering::SeqCst) == 1 {
if self.registered_predecessors.fetch_sub(1, Ordering::SeqCst) == 1 &&
self.used.load(Ordering::SeqCst)
{
self.create_air_instance();
}
}
Expand All @@ -60,6 +64,7 @@ impl<F: Field> ArithTableSM<F> {
info!("{}: ··· Processing row {} with value {}", Self::MY_NAME, row, value);
_multiplicity[row] += value;
}
self.used.store(true, Ordering::Relaxed);
}
pub fn create_air_instance(&self) {
let ectx = self.wcm.get_ectx();
Expand Down Expand Up @@ -88,7 +93,7 @@ impl<F: Field> ArithTableSM<F> {
.for_each(|(i, input)| *input = F::from_canonical_u64(multiplicity_[i]));

info!(
"{}: ··· Creating Binary basic table instance [{} rows filled 100%]",
"{}: ··· Creating Arith basic table instance [{} rows filled 100%]",
Self::MY_NAME,
self.num_rows,
);
Expand Down

0 comments on commit c94771f

Please sign in to comment.