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

Prepare to call jit from block machine. #2098

Merged
merged 31 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fbdabca
Use contiguous data for finalized rows.
chriseth Nov 13, 2024
71d2ebd
Remove last row.
chriseth Nov 13, 2024
f66c5c2
Fix extend.
chriseth Nov 14, 2024
934ebb1
clippy
chriseth Nov 14, 2024
19d544f
remove unused functiion
chriseth Nov 14, 2024
6b83811
Allow non-sorted column IDs.
chriseth Nov 14, 2024
80c24f9
Jit driver and machine.
chriseth Nov 14, 2024
5528a4f
reserve block
chriseth Nov 15, 2024
4d4111c
revie
chriseth Nov 15, 2024
0076d2c
review
chriseth Nov 15, 2024
3c577c1
review
chriseth Nov 15, 2024
4e83830
Add "remove_last_row"
chriseth Nov 15, 2024
9f3130a
Re-added one case.
chriseth Nov 15, 2024
1aadfe0
Merge branch 'improve_finalizable' into call_jit_from_block
chriseth Nov 15, 2024
056a904
jitedijit
chriseth Nov 15, 2024
f2fee46
jitjit
chriseth Nov 15, 2024
9415cc3
Remove try_remove_last_row.
chriseth Nov 15, 2024
ec5d110
compact data ref.
chriseth Nov 15, 2024
7cbbb8d
Remove unwrap.
chriseth Nov 15, 2024
4490dcd
Cleanup
chriseth Nov 15, 2024
7ffdad9
Merge remote-tracking branch 'origin/improve_finalizable' into call_j…
chriseth Nov 15, 2024
09863e8
cleanup
chriseth Nov 15, 2024
cf51774
cleanup
chriseth Nov 15, 2024
825d0eb
Merge remote-tracking branch 'origin/main' into call_jit_from_block
chriseth Nov 15, 2024
d470fd7
Remove type constraints.
chriseth Nov 22, 2024
b8864c8
Avoid dyn iter.
chriseth Nov 22, 2024
ca38415
Correct typo.
chriseth Nov 22, 2024
d47f695
Update executor/src/witgen/data_structures/finalizable_data.rs
chriseth Dec 9, 2024
d482821
Review comments.
chriseth Dec 9, 2024
68be580
Merge remote-tracking branch 'origin/main' into call_jit_from_block
chriseth Dec 10, 2024
46860a1
Merge remote-tracking branch 'origin/main' into call_jit_from_block
chriseth Dec 12, 2024
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
Prev Previous commit
Next Next commit
compact data ref.
  • Loading branch information
chriseth committed Nov 15, 2024
commit ec5d110864dddf26882aed2ac289bbb9f6066928
36 changes: 33 additions & 3 deletions executor/src/witgen/data_structures/finalizable_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,36 @@ impl<T: FieldElement> CompactData<T> {
}
}

/// A mutable reference into CompactData that is meant to be used
/// only for a certain block of rows, starting from row index zero.
/// It allows negative row indices as well.
pub struct CompactDataRef<'a, T: FieldElement> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub struct CompactDataRef<'a, T: FieldElement> {
pub struct CompactDataRef<'a, T> {

?

data: &'a mut CompactData<T>,
row_offset: usize,
}

impl<'a, T: FieldElement> CompactDataRef<'a, T> {
/// Creates a new reference to the data, supplying the offset of the row
/// that is supposed to be "row zero".
pub fn new(data: &'a mut CompactData<T>, row_offset: usize) -> Self {
Self { data, row_offset }
}

pub fn get(&self, row: i32, col: u32) -> T {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the 32 bit values here provide a performance advantage. Any opinions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of get and set, can this implement Index and IndexMut?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't think we will use those functions later on. The current interface used in #2071 uses direct memory slices.

let (v, known) = self.data.get(self.inner_row(row), col as u64);
assert!(known);
v
}

pub fn set(&mut self, row: i32, col: u32, value: T) {
self.data.set(self.inner_row(row), col as u64, value);
}

fn inner_row(&self, row: i32) -> usize {
(row + self.row_offset as i32) as usize
}
}

/// A data structure that stores witness data.
/// It allows to finalize rows, which means that those rows are then stored in a more
/// compact form. Information about range constraints on those rows is lost, but the
Expand Down Expand Up @@ -381,11 +411,11 @@ impl<T: FieldElement> FinalizableData<T> {
}
}

// TODO somehow we need to return a row offset because of the non-finalized rows.
pub fn append_new_finalized_rows(&mut self, count: usize) -> &mut CompactData<T> {
pub fn append_new_finalized_rows<'a>(&'a mut self, count: usize) -> CompactDataRef<'a, T> {
assert!(self.post_finalized_data.is_empty());
let row_zero = self.finalized_data.len();
self.finalized_data.append_new_rows(count);
&mut self.finalized_data
CompactDataRef::new(&mut self.finalized_data, row_zero)
}

/// Takes all data out of the [FinalizableData] and returns it as a list of columns.
Expand Down
41 changes: 10 additions & 31 deletions executor/src/witgen/machines/block_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,6 @@ impl<'a, T: FieldElement> BlockMachine<'a, T> {
RowIndex::from_i64(self.rows() as i64 - 1, self.degree)
}

fn get_row(&self, row: RowIndex) -> &Row<T> {
// The first block is a dummy block corresponding to rows (-block_size, 0),
// so we have to add the block size to the row index.
&self.data[(row + self.block_size).into()]
}

fn process_plookup_internal<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b mut MutableState<'a, 'b, T, Q>,
Expand All @@ -349,19 +343,12 @@ impl<'a, T: FieldElement> BlockMachine<'a, T> {
}
}

// TOOD move this into its own function?
if self.parts.prover_functions.is_empty() {
let known_inputs = outer_query
.left
.iter()
.map(|e| e.is_constant())
.collect::<BitVec>();
if self
.jit_driver
.can_answer_lookup(identity_id, &known_inputs)
{
return self.process_lookup_via_jit(mutable_state, identity_id, outer_query);
}
let known_inputs = outer_query.left.iter().map(|e| e.is_constant()).collect();
if self
.jit_driver
.can_answer_lookup(identity_id, &known_inputs)
{
return self.process_lookup_via_jit(mutable_state, identity_id, outer_query);
}

// TODO this assumes we are always using the same lookup for this machine.
Expand Down Expand Up @@ -444,23 +431,15 @@ impl<'a, T: FieldElement> BlockMachine<'a, T> {
(self.rows() + self.block_size as DegreeType) < self.degree,
"Block machine is full (this should have been checked before)"
);
// TODO minus one?
let row_offset = self.data.len();
self.data
.finalize_range(self.first_in_progress_row..self.data.len());
self.first_in_progress_row = self.data.len() + self.block_size;
//TODO can we properly access the last row of the dummy block?
let data = self.data.append_new_finalized_rows(self.block_size);
// TODO finalize self.data, extend by one (finalized) block.
// un-finalize the last block / last row in the interpreted case if it is finalized.
// TOOD window at which row?

let success = self.jit_driver.process_lookup_direct(
mutable_state,
identity_id,
values,
data,
row_offset,
)?;
let success =
self.jit_driver
.process_lookup_direct(mutable_state, identity_id, values, data)?;
assert!(success);

let mut result = EvalValue::complete(vec![]);
Expand Down
7 changes: 3 additions & 4 deletions executor/src/witgen/machines/jit_machine_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use bit_vec::BitVec;
use powdr_number::FieldElement;

use crate::witgen::{
data_structures::finalizable_data::CompactData, EvalError, FixedData, MutableState,
QueryCallback,
data_structures::finalizable_data::{CompactData, CompactDataRef},
EvalError, FixedData, MutableState, QueryCallback,
};

use super::{LookupCell, MachineParts};
Expand Down Expand Up @@ -40,8 +40,7 @@ impl<'a, T: FieldElement> JitMachineDriver<'a, T> {
_mutable_state: &'b mut MutableState<'a, 'b, T, Q>,
identity_id: u64,
values: Vec<LookupCell<'c, T>>,
data: &'d CompactData<T>,
row_offset: usize,
data: CompactDataRef<'d, T>,
) -> Result<bool, EvalError<T>> {
todo!();
}
Expand Down
Loading