-
Notifications
You must be signed in to change notification settings - Fork 119
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
refactor(core): start refactoring pbs code #627
base: main
Are you sure you want to change the base?
Conversation
@slab-ci cpu_fast_test |
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.
First batch of comments, thanks for the work, I'll check the remainder after lunch :)
@@ -3,14 +3,14 @@ | |||
//! like the Fourier domain. | |||
|
|||
use crate::core_crypto::commons::computation_buffers::ComputationBuffers; | |||
use crate::core_crypto::commons::math::fft::{Fft, FftView}; |
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.
should we maybe plan for the fft64/fft128 split as we had in the fft_impl module ? I believe we want to also move the f128 at some point, we can check with JB
use dyn_stack::{PodStack, SizeOverflow, StackReq}; | ||
use dyn_stack::{PodStack, ReborrowMut, SizeOverflow, StackReq}; | ||
|
||
impl<'a> FourierLweBootstrapKeyMutView<'a> { |
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.
should this be in the entities module for now ?
My reasoning : the algorithm for now is tied to the entity, what we would do is the same you did in the ggsw_conversion module i.e. rewrite the algorithm in this file as a function not in an impl block ?
let mut stack = PodStack::new(&mut stack); | ||
|
||
for (fourier_poly, standard_poly) in izip!( | ||
fourier_poly_chunk.chunks_exact_mut(f_polynomial_size), | ||
standard_poly_chunk.chunks_exact(polynomial_size.0) | ||
) { | ||
fft.forward_as_torus( | ||
FourierPolynomialMutView { data: fourier_poly }, | ||
FourierPolynomialMutView::from_container(fourier_poly), | ||
PolynomialView::from_container(standard_poly), | ||
stack.rb_mut(), | ||
); |
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.
could we put the mod tests that is at the the end of the file towards the top ?
@@ -1,3 +0,0 @@ | |||
pub mod decomposition; | |||
pub mod fft; |
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.
looks like fft has not been deleted ?
) -> Self { | ||
assert_eq!( | ||
data.container_len(), | ||
polynomial_size.to_fourier_polynomial_size().0 * glwe_size.0 * row_count |
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.
row_count should be equal to glwe_size you can check ggsw_ciphertext.rs I think there are some size functions :)
} | ||
|
||
pub fn output_lwe_dimension(&self) -> LweDimension { | ||
LweDimension((self.glwe_size.0 - 1) * self.polynomial_size().0) |
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.
you can now use self.glwe_size.to_glwe_dimension().to_equivalent_lwe_dimension(self.polynomial_size())
data: C, | ||
glwe_size: GlweSize, | ||
polynomial_size: PolynomialSize, | ||
row_count: usize, |
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.
should not be needed row_count == glwe_size
pub fn row_count(&self) -> usize { | ||
self.row_count | ||
} | ||
|
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.
should not be required
impl<Scalar> FourierBootstrapKey<Scalar> for FourierLweBootstrapKeyOwned | ||
where |
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.
I think this impl should be in the entity file for now
} | ||
|
||
#[cfg_attr(__profiling, inline(never))] | ||
pub(crate) fn update_with_fmadd( |
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.
I believe the update_with_fmadd could be seen as FFT primitives ? As this allows to make polynomial mulitplications in an efficient way ? what do you think ?
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.
makes sense to me. i can put them with the fft
}) | ||
} | ||
|
||
pub(crate) fn update_with_fmadd_factor( |
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.
same comment :)
@@ -335,6 +480,155 @@ pub fn add_external_product_assign<Scalar, OutputGlweCont, InputGlweCont, GgswCo | |||
add_external_product_assign_mem_optimized(out, ggsw, glwe, fft, buffers.stack()); | |||
} | |||
|
|||
#[cfg_attr(__profiling, inline(never))] | |||
pub(crate) fn collect_next_term<Scalar: UnsignedTorus>( |
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.
could it be a method on the TensorSignedDecomposition struct ?
impl<'a> FourierLweBootstrapKeyView<'a> { | ||
// CastInto required for PBS modulus switch which returns a usize |
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.
for now I believe this should be in the entity module
e246bb3
to
fae7ca9
Compare
@slab-ci cpu_fast_test |
i pushed a new commit with your suggestions. lemme know if there's anything else to fix |
no regressions found on my machine |
created a follow up issue https://github.com/zama-ai/tfhe-rs-internal/issues/287 This looks very good, finishing reading up ! |
|
||
impl<Scalar> FourierBootstrapKey<Scalar> for FourierLweBootstrapKeyOwned |
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.
Any reason to remove this implementation ?
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.
that might have been a mistake on my part
closes: please link all relevant issues
PR content/description
Check-list: