Skip to content

Commit

Permalink
integrate
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Nov 16, 2024
1 parent 8464bce commit 7790924
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 62 deletions.
50 changes: 43 additions & 7 deletions executor/src/witgen/jit/jit_processor.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use bit_vec::BitVec;
use itertools::Itertools;
use powdr_number::FieldElement;

use crate::witgen::{
data_structures::finalizable_data::CompactDataRef,
jit::witgen_inference::WitgenInference,
machines::{LookupCell, MachineParts},
util::try_to_simple_poly,
EvalError, FixedData, MutableState, QueryCallback,
};

pub struct JitProcessor<'a, T: FieldElement> {
_fixed_data: &'a FixedData<'a, T>,
fixed_data: &'a FixedData<'a, T>,
parts: MachineParts<'a, T>,
_block_size: usize,
block_size: usize,
latch_row: usize,
}

Expand All @@ -23,16 +25,50 @@ impl<'a, T: FieldElement> JitProcessor<'a, T> {
latch_row: usize,
) -> Self {
JitProcessor {
_fixed_data: fixed_data,
fixed_data,
parts,
_block_size: block_size,
block_size,
latch_row,
}
}

pub fn can_answer_lookup(&self, _identity_id: u64, _known_inputs: &BitVec) -> bool {
// TODO call the JIT compiler here.
false
pub fn can_answer_lookup(&self, identity_id: u64, known_inputs: &BitVec) -> bool {
// TODO cache the result

// TODO what if the same column is mentioned multiple times on the RHS of the connection?

let right = self.parts.connections[&identity_id].right;
let Some(known_inputs) = known_inputs
.iter()
.zip(&right.expressions)
.filter(|&(known, e)| known)
.map(|(known, e)| try_to_simple_poly(e))
.collect::<Option<Vec<_>>>()
else {
return false;
};
log::debug!(
"Trying to auto-generate witgen code for known inputs: {}",
known_inputs.iter().format(", ")
);

let known_inputs = known_inputs.into_iter().map(|p| p.poly_id);

let mut inference = WitgenInference::new(
self.fixed_data,
&self.parts,
self.block_size,
self.latch_row,
known_inputs,
right,
);
if inference.run() {
log::info!("Successfully generated witgen code for some machine.");
log::trace!("Generated code:\n{}", inference.code());
true
} else {
false
}
}

pub fn process_lookup_direct<'b, 'c, 'd, Q: QueryCallback<T>>(
Expand Down
54 changes: 1 addition & 53 deletions executor/src/witgen/jit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,4 @@
pub mod jit_processor;

use std::hash::{Hash, Hasher};

use itertools::Itertools;
use powdr_ast::analyzed::AlgebraicReference;
use powdr_number::FieldElement;
use witgen_inference::WitgenInference;

use super::{
analysis::detect_connection_type_and_block_size, machines::MachineParts,
util::try_to_simple_poly, FixedData,
};

mod cell;
mod eval_result;
pub mod jit_processor;
mod witgen_inference;

pub fn infer_witgen<'a, T: FieldElement>(
fixed_data: &'a FixedData<'a, T>,
parts: &MachineParts<'a, T>,
) -> Option<()> {
// TODO the nicer interface would be for the inference alg to determine the block size.
let (_, block_size, latch_row) =
detect_connection_type_and_block_size(fixed_data, &parts.connections)?;
// Let's only look at the first connection. TODO
let conn = parts.connections.values().next().unwrap().right;
for num_known in 1..conn.expressions.len() {
if num_known != 13 {
continue;
}
for inputs_known in conn.expressions.iter().combinations(num_known) {
log::debug!(
"Trying to auto-generate witgen code for known inputs: {}",
inputs_known.iter().map(|e| e.to_string()).join(", ")
);
let Some(inputs_known) = inputs_known
.iter()
.map(|e| try_to_simple_poly(e))
.collect::<Option<Vec<_>>>()
else {
continue;
};

let inputs_known = inputs_known.into_iter().map(|p| p.poly_id);

let mut inference =
WitgenInference::new(fixed_data, parts, block_size, latch_row, inputs_known, conn);
if inference.run() {
log::info!("Successfully generated witgen code for some machine.");
log::trace!("Generated code:\n{}", inference.code());
}
}
}
Some(())
}
1 change: 0 additions & 1 deletion executor/src/witgen/machines/machine_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use super::fixed_lookup_machine::FixedLookup;
use super::sorted_witness_machine::SortedWitnesses;
use super::FixedData;
use super::KnownMachine;
use crate::witgen::auto;
use crate::witgen::machines::Connection;
use crate::witgen::{
generator::Generator,
Expand Down
1 change: 0 additions & 1 deletion executor/src/witgen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use self::machines::Machine;

mod affine_expression;
pub(crate) mod analysis;
pub(crate) mod auto;
mod block_processor;
mod data_structures;
mod eval_result;
Expand Down

0 comments on commit 7790924

Please sign in to comment.