Skip to content

Commit

Permalink
fix-sctx (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavi-pinsach authored Oct 28, 2024
1 parent 56dc7b3 commit 0cec4a5
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 122 deletions.
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions state-machines/arith/src/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ pub struct ArithSM {
arith32_sm: Arc<Arith32SM>,
arith64_sm: Arc<Arith64SM>,
arith3264_sm: Arc<Arith3264SM>,

sctx: Arc<SetupCtx>,
}

impl ArithSM {
pub fn new<F>(wcm: Arc<WitnessManager<F>>, sctx: Arc<SetupCtx>) -> Arc<Self> {
pub fn new<F>(wcm: Arc<WitnessManager<F>>) -> Arc<Self> {
let arith32_sm = Arith32SM::new(wcm.clone());
let arith64_sm = Arith64SM::new(wcm.clone());
let arith3264_sm = Arith3264SM::new(wcm.clone());
Expand All @@ -47,7 +45,6 @@ impl ArithSM {
arith32_sm,
arith64_sm,
arith3264_sm,
sctx,
};
let arith_sm = Arc::new(arith_sm);

Expand Down
17 changes: 3 additions & 14 deletions state-machines/binary/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{BinaryBasicSM, BinaryBasicTableSM, BinaryExtensionSM, BinaryExtensio
use p3_field::PrimeField;
use pil_std_lib::Std;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::SetupCtx;
use rayon::Scope;
use sm_common::{OpResult, Provable, ThreadController};
use zisk_core::ZiskRequiredOperation;
Expand All @@ -34,36 +33,27 @@ pub struct BinarySM<F: PrimeField> {
// Secondary State machines
binary_basic_sm: Arc<BinaryBasicSM<F>>,
binary_extension_sm: Arc<BinaryExtensionSM<F>>,

sctx: Arc<SetupCtx>,
}

impl<F: PrimeField> BinarySM<F> {
pub fn new(wcm: Arc<WitnessManager<F>>, std: Arc<Std<F>>, sctx: Arc<SetupCtx>) -> Arc<Self> {
let binary_basic_table_sm = BinaryBasicTableSM::new(
wcm.clone(),
sctx.clone(),
BINARY_TABLE_AIRGROUP_ID,
BINARY_TABLE_AIR_IDS,
);
pub fn new(wcm: Arc<WitnessManager<F>>, std: Arc<Std<F>>) -> Arc<Self> {
let binary_basic_table_sm =
BinaryBasicTableSM::new(wcm.clone(), BINARY_TABLE_AIRGROUP_ID, BINARY_TABLE_AIR_IDS);
let binary_basic_sm = BinaryBasicSM::new(
wcm.clone(),
sctx.clone(),
binary_basic_table_sm,
BINARY_AIRGROUP_ID,
BINARY_AIR_IDS,
);

let binary_extension_table_sm = BinaryExtensionTableSM::new(
wcm.clone(),
sctx.clone(),
BINARY_EXTENSION_TABLE_AIRGROUP_ID,
BINARY_EXTENSION_TABLE_AIR_IDS,
);
let binary_extension_sm = BinaryExtensionSM::new(
wcm.clone(),
std,
sctx.clone(),
binary_extension_table_sm,
BINARY_EXTENSION_AIRGROUP_ID,
BINARY_EXTENSION_AIR_IDS,
Expand All @@ -76,7 +66,6 @@ impl<F: PrimeField> BinarySM<F> {
inputs_extension: Mutex::new(Vec::new()),
binary_basic_sm,
binary_extension_sm,
sctx,
};
let binary_sm = Arc::new(binary_sm);

Expand Down
20 changes: 9 additions & 11 deletions state-machines/binary/src/binary_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::{
use log::info;
use p3_field::Field;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{AirInstance, SetupCtx};
use proofman_common::AirInstance;
use proofman_util::{timer_start_trace, timer_stop_and_log_trace};
use rayon::Scope;
use sm_common::{create_prover_buffer, OpResult, Provable, ThreadController};
Expand All @@ -30,8 +30,6 @@ pub struct BinaryBasicSM<F> {

// Secondary State machines
binary_basic_table_sm: Arc<BinaryBasicTableSM<F>>,

sctx: Arc<SetupCtx>,
}

#[derive(Debug)]
Expand All @@ -44,14 +42,12 @@ impl<F: Field> BinaryBasicSM<F> {

pub fn new(
wcm: Arc<WitnessManager<F>>,
sctx: Arc<SetupCtx>,
binary_basic_table_sm: Arc<BinaryBasicTableSM<F>>,
airgroup_id: usize,
air_ids: &[usize],
) -> Arc<Self> {
let binary_basic = Self {
wcm: wcm.clone(),
sctx,
registered_predecessors: AtomicU32::new(0),
threads_controller: Arc::new(ThreadController::new()),
inputs: Mutex::new(Vec::new()),
Expand Down Expand Up @@ -676,9 +672,10 @@ impl<F: Field> BinaryBasicSM<F> {
scope: &Scope,
) {
timer_start_trace!(BINARY_TRACE);
let air = wcm.get_pctx().pilout.get_air(BINARY_AIRGROUP_ID, BINARY_AIR_IDS[0]);
let pctx = wcm.get_pctx();
let air = pctx.pilout.get_air(BINARY_AIRGROUP_ID, BINARY_AIR_IDS[0]);
let air_binary_table =
wcm.get_pctx().pilout.get_air(BINARY_TABLE_AIRGROUP_ID, BINARY_TABLE_AIR_IDS[0]);
pctx.pilout.get_air(BINARY_TABLE_AIRGROUP_ID, BINARY_TABLE_AIR_IDS[0]);
assert!(operations.len() <= air.num_rows());

info!(
Expand Down Expand Up @@ -747,7 +744,8 @@ impl<F: Field> Provable<ZiskRequiredOperation, OpResult> for BinaryBasicSM<F> {
if let Ok(mut inputs) = self.inputs.lock() {
inputs.extend_from_slice(operations);

let air = self.wcm.get_pctx().pilout.get_air(BINARY_AIRGROUP_ID, BINARY_AIR_IDS[0]);
let pctx = self.wcm.get_pctx();
let air = pctx.pilout.get_air(BINARY_AIRGROUP_ID, BINARY_AIR_IDS[0]);

while inputs.len() >= air.num_rows() || (drain && !inputs.is_empty()) {
let num_drained = std::cmp::min(air.num_rows(), inputs.len());
Expand All @@ -759,12 +757,12 @@ impl<F: Field> Provable<ZiskRequiredOperation, OpResult> for BinaryBasicSM<F> {
self.threads_controller.add_working_thread();
let thread_controller = self.threads_controller.clone();

let sctx = self.sctx.clone();
let sctx = self.wcm.get_sctx().clone();

scope.spawn(move |scope| {
let (mut prover_buffer, offset) = create_prover_buffer(
wcm.get_ectx(),
wcm.get_sctx(),
&wcm.get_ectx(),
&wcm.get_sctx(),
BINARY_AIRGROUP_ID,
BINARY_AIR_IDS[0],
);
Expand Down
Loading

0 comments on commit 0cec4a5

Please sign in to comment.