This repository was archived by the owner on Sep 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
FastCompute implementation of GPA witness layer low-to-high HAL op #813
Open
djadjka
wants to merge
1
commit into
main
Choose a base branch
from
adziadziuk/cry-490-fastcompute-implementation-of-gpa-witness-layer-low-to-high
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,12 +46,12 @@ use binius_utils::{ | |
| strided_array::StridedArray2DViewMut, | ||
| }; | ||
| use bytemuck::{Pod, zeroed_vec}; | ||
| use itertools::izip; | ||
| use itertools::{Itertools, izip}; | ||
| use thread_local::ThreadLocal; | ||
|
|
||
| use crate::{ | ||
| arith_circuit::ArithCircuitPoly, | ||
| memory::{PackedMemory, PackedMemorySliceMut}, | ||
| memory::{PackedMemory, PackedMemorySlice, PackedMemorySliceMut}, | ||
| }; | ||
|
|
||
| /// Optimized CPU implementation of the compute layer. | ||
|
|
@@ -176,14 +176,11 @@ impl<T: TowerFamily, P: PackedTop<T>> ComputeLayer<T::B128> for FastCpuLayer<T, | |
| slice: &mut <Self::DevMem as ComputeMemory<T::B128>>::FSliceMut<'_>, | ||
| value: T::B128, | ||
| ) -> Result<(), Error> { | ||
| match slice { | ||
| PackedMemorySliceMut::Slice(items) => { | ||
| items.fill(P::broadcast(value)); | ||
| } | ||
| PackedMemorySliceMut::SingleElement { owned, .. } => { | ||
| owned.fill(value); | ||
| } | ||
| }; | ||
| let value = P::broadcast(value); | ||
|
|
||
| for element in slice.as_slice_mut() { | ||
| *element = value; | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
@@ -622,11 +619,68 @@ impl<'a, T: TowerFamily, P: PackedTop<T>> ComputeLayerExecutor<T::B128> | |
|
|
||
| fn pairwise_product_reduce( | ||
| &mut self, | ||
| _input: <Self::DevMem as ComputeMemory<T::B128>>::FSlice<'_>, | ||
| _round_outputs: &mut [<Self::DevMem as ComputeMemory<T::B128>>::FSliceMut<'_>], | ||
| input: <Self::DevMem as ComputeMemory<T::B128>>::FSlice<'_>, | ||
| round_outputs: &mut [<Self::DevMem as ComputeMemory<T::B128>>::FSliceMut<'_>], | ||
| ) -> Result<(), Error> { | ||
| // TODO(CRY-490) | ||
| todo!() | ||
| let log_num_inputs = match strict_log_2(input.len()) { | ||
| None => { | ||
| return Err(Error::InputValidation(format!( | ||
| "input length must be a power of 2: {}", | ||
| input.len() | ||
| ))); | ||
| } | ||
| Some(0) => { | ||
| return Err(Error::InputValidation(format!( | ||
| "input length must be greater than or equal to 2 in order to perform at least one reduction: {}", | ||
| input.len() | ||
| ))); | ||
| } | ||
| Some(log_num_inputs) => log_num_inputs, | ||
| }; | ||
| let expected_round_outputs_len = log_num_inputs; | ||
| if round_outputs.len() != expected_round_outputs_len as usize { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe move the logic verifying the input and output dimensions to a separate helper function to share between the reference and fast implementations? |
||
| return Err(Error::InputValidation(format!( | ||
| "round_outputs.len() does not match the expected length: {} != {expected_round_outputs_len}", | ||
| round_outputs.len() | ||
| ))); | ||
| } | ||
| for (round_idx, round_output_data) in round_outputs.iter().enumerate() { | ||
| let expected_output_size = 1usize << (log_num_inputs as usize - round_idx - 1); | ||
| if round_output_data.len() != expected_output_size { | ||
| return Err(Error::InputValidation(format!( | ||
| "round_outputs[{}].len() = {}, expected {expected_output_size}", | ||
| round_idx, | ||
| round_output_data.len() | ||
| ))); | ||
| } | ||
| } | ||
|
|
||
| let mut round_data_source = input; | ||
| for round_output_data in round_outputs.iter_mut() { | ||
| match round_data_source { | ||
| PackedMemorySlice::Slice(input) => { | ||
| input | ||
| .par_chunks(2) | ||
| .zip(round_output_data.as_slice_mut().par_iter_mut()) | ||
| .for_each(|(chunk, output)| { | ||
| let scalar_iter = P::iter_slice(chunk) | ||
| .tuples() | ||
| .map(|(left, right)| left * right); | ||
| *output = P::from_scalars(scalar_iter); | ||
| }); | ||
| } | ||
|
Comment on lines
+665
to
+671
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potentially it would be faster to re-use the packed multiplication by interleaving values: |
||
| PackedMemorySlice::Owned(..) => { | ||
| let scalar_iter = P::iter_slice(round_data_source.as_slice()) | ||
| .tuples() | ||
| .map(|(left, right)| left * right); | ||
|
|
||
| round_output_data.as_slice_mut()[0] = P::from_scalars(scalar_iter); | ||
| } | ||
| } | ||
| round_data_source = round_output_data.as_const(); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice!
Can be simplified even further: