Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
feat: General optimizations#65
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f4c6336c95c70e3d75eb5fb7d1d903b142bbaea772File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,4 +21,7 @@ benchmark.csv | ||
| # Build Artifacts | ||
| recursion/gnark-ffi/build | ||
| prover/build | ||
| prover/*.tar.gz | ||
| prover/*.tar.gz | ||
| # IDE Conf | ||
| .idea | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,7 +5,6 @@ pub mod opcode; | ||
| pub mod trace; | ||
| pub mod utils; | ||
| use alloc::collections::BTreeMap; | ||
| use core::borrow::BorrowMut; | ||
| use std::marker::PhantomData; | ||
| @@ -35,19 +34,10 @@ pub const NUM_BYTE_LOOKUP_CHANNELS: u32 = 16; | ||
| pub struct ByteChip<F>(PhantomData<F>); | ||
| impl<F: Field> ByteChip<F> { | ||
| /// Creates the preprocessed byte trace and event map. | ||
| /// Creates the preprocessed byte trace. | ||
| /// | ||
| /// This function returns a pair `(trace, map)`, where: | ||
| /// - `trace` is a matrix containing all possible byte operations. | ||
| /// - `map` is a map from a byte lookup to the corresponding row it appears in the table and | ||
| /// the index of the result in the array of multiplicities. | ||
| pub fn trace_and_map( | ||
| shard: u32, | ||
| ) -> (RowMajorMatrix<F>, BTreeMap<ByteLookupEvent, (usize, usize)>) { | ||
| // A map from a byte lookup to its corresponding row in the table and index in the array of | ||
| // multiplicities. | ||
| let mut event_map = BTreeMap::new(); | ||
| /// This function returns a `trace` which is a matrix containing all possible byte operations. | ||
| pub fn trace() -> RowMajorMatrix<F> { | ||
| // The trace containing all values, with all multiplicities set to zero. | ||
| let mut initial_trace = RowMajorMatrix::new( | ||
| vec![F::zero(); NUM_ROWS * NUM_BYTE_PREPROCESSED_COLS], | ||
| @@ -65,10 +55,11 @@ impl<F: Field> ByteChip<F> { | ||
| col.b = F::from_canonical_u8(b); | ||
| col.c = F::from_canonical_u8(c); | ||
| let shard = 0; | ||
| // Iterate over all operations for results and updating the table map. | ||
| for channel in 0..NUM_BYTE_LOOKUP_CHANNELS { | ||
| for (i, opcode) in opcodes.iter().enumerate() { | ||
| let event = match opcode { | ||
| for opcode in opcodes.iter() { | ||
| match opcode { | ||
| ByteOpcode::AND => { | ||
| let and = b & c; | ||
| col.and = F::from_canonical_u8(and); | ||
| @@ -176,11 +167,25 @@ impl<F: Field> ByteChip<F> { | ||
| ByteLookupEvent::new(shard, channel, *opcode, v, 0, 0, 0) | ||
| } | ||
| }; | ||
| event_map.insert(event, (row_index, i)); | ||
| } | ||
| } | ||
| } | ||
| (initial_trace, event_map) | ||
| initial_trace | ||
| } | ||
| } | ||
| #[cfg(test)] | ||
| mod tests { | ||
| use p3_baby_bear::BabyBear; | ||
| use std::time::Instant; | ||
| use super::*; | ||
| #[test] | ||
| fn test_trace_and_map() { | ||
| let start = Instant::now(); | ||
| ByteChip::<BabyBear>::trace(); | ||
| println!("trace and map: {:?}", start.elapsed()); | ||
| } | ||
Comment on lines
+186
to
190
| ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not really necessary for any of the optimizations, but I removed this
Copyderive to try to minimize accidental/implicit copies of byte lookups. There's only one place in core/src/runtime/record.rs that required adding a.clone()due to removing this bound