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

test(core): add a many LUT test in core crypto #742

Merged
merged 3 commits into from
Feb 5, 2024
Merged

Conversation

IceTDrinker
Copy link
Member

PR content/description

  • it does not require any new primitive so was made into a test at the core crypto level
  • shortint will have a more user friendly API but it requires some design

Check-list:

  • Tests for the changes have been added (for bug fixes / features)
    * [ ] Docs have been added / updated (for bug fixes / features)
    * [ ] Relevant issues are marked as resolved/closed, related issues are linked in the description
    * [ ] Check for breaking changes (including serialization changes) and add them to commit message following the conventional commit specification

Copy link

@slab-ci cpu_fast_test

@IceTDrinker
Copy link
Member Author

IceTDrinker commented Jan 4, 2024

using the MSB to manage the LUT location looks more interesting to avoid delta/encoding mixing (as discovered while checking this with @mayeul-zama)

Copy link

github-actions bot commented Jan 9, 2024

@slab-ci cpu_fast_test

ciphertext_modulus: CiphertextModulus<Scalar>,
delta: Scalar,
funcs: &[&dyn Fn(Scalar) -> Scalar],
) -> (GlweCiphertextOwned<Scalar>, usize) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be cleaner to assert!(funcs.len() * input_max_degree * mega_case_size < poly_size)
And then cut the LUT into funcs.len() chunks of size input_max_degree * mega_case_size (the end of the LUT may be filled with 0)
And then, fill each mega case i of each chunk j with f_j(i)

This way, fn_count does not need to be a power of 2

Copy link
Contributor

Choose a reason for hiding this comment

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

Or we may choose the biggest possible input_max_degree and then in the shortint API, we return an error if the degree is bigger than this inferred max degree

Copy link
Member Author

Choose a reason for hiding this comment

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

We do not require the power of 2 in that case it's just that we use power of 2 to organize the data which IMO is much less of a headache

Copy link
Contributor

Choose a reason for hiding this comment

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

But it seems to me that it limits the maximum possible degree of the inputs of the many LUT

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 think the first implementation will be based on the power of 2 approach, and if we see we are missing some optimizations we'll likely update to be able to be more flexible wrt to the degree.

The only time we would have a limit is if we have a small degree and lots of functions then there may be a world where some functions will not be evaluated because of wasted space if we use the power of 2, I think it's an acceptable tradeoff at first.

Plus here for core we don't really care, it's a first implementation to check the principles, the question will be of more interest later when it goes up to shortint

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that the non power of 2 approach is not more complex

Plus here for core we don't really care, it's a first implementation to check the principles, the question will be of more interest later when it goes up to shortint

Why merge it then? Shouldn't we only merge the shortint version in main once ready?

Copy link
Member Author

@IceTDrinker IceTDrinker Jan 16, 2024

Choose a reason for hiding this comment

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

well at least from a design perspective it means the LUT generation does not need the input ciphertext degree in the power of 2 approach as it's a pessimistic case, in the degree approach the lut needs to be tailor made for the ciphertext

Copy link
Contributor

Choose a reason for hiding this comment

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

As described in my second comment, I believe we can take the biggest possible input_max_degree (which depend on fn_count and full_msg_mod) to build the LUT and we can use it for all compatible ciphertexts

// N/(p/2) = size of each block, to correct noise from the input we introduce the
// notion of box, which manages redundancy to yield a denoised value
// for several noisy values around a true input value.
let box_size = polynomial_size.0 / message_modulus;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does message_modulus include the carries?
I think it should, but the name, as used in shortint does not reflect that.
Does message_modulus have a differen meaning in core_crypto?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah in core crypto it's most likely the full msg space here, it would be adapted for the port to shortint

Copy link

@slab-ci cpu_fast_test
@slab-ci gpu_test

Copy link

@slab-ci gpu_test

tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
- it does not require any new primitive so was made into a test at the core
crypto level
- shortint will have a more user friendly API, using the MSBs for selecting
the function means it should not require too much design as deltas are
always the same
Copy link

@slab-ci gpu_test

Copy link

github-actions bot commented Feb 1, 2024

Pull Request has been approved 🎉
Launching full test suite...
@slab-ci cpu_test
@slab-ci cpu_unsigned_integer_test
@slab-ci cpu_signed_integer_test
@slab-ci cpu_wasm_test
@slab-ci csprng_randomness_testing

@IceTDrinker IceTDrinker merged commit a0b75d9 into main Feb 5, 2024
24 checks passed
@IceTDrinker IceTDrinker deleted the am/test/many-lut branch February 5, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants