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

Update toolchain #494

Merged
merged 6 commits into from
Aug 31, 2023
Merged

Update toolchain #494

merged 6 commits into from
Aug 31, 2023

Conversation

mayeul-zama
Copy link
Contributor

PR content/description

Update rust toolchain

@github-actions
Copy link

@slab-ci cpu_fast_test

@github-actions
Copy link

@slab-ci cpu_fast_test

@mayeul-zama
Copy link
Contributor Author

@slab-ci cpu_fast_test

@@ -27,7 +27,7 @@ impl ShortintEngine {
pub(crate) fn smart_add(
&mut self,
server_key: &ServerKey,
ct_left: &mut Ciphertext,
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally all the smart functions should take &mut for both input to clean carries if needed,
but these one do not seems to be correctly written

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok
Do you think we should fix this code by cleaning carries:

  • in this PR (not sure how big this would be)?
  • in another fix PR and in the meantime:
    • keep mut and silence this warning for the smart functions?
    • remove mut (as in this PR) and reintroduce it in the fix PR?

If we only clean carries of outputs, is it not enough (as all inputs will then be clean)? Or maybe we want to do it only when really needed to avoid it in some cases

Copy link
Contributor

Choose a reason for hiding this comment

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

smart_ functions are meant to clean carries of input only when needed

I would say we keep the changes in the PR and try to find some time later to fix the shortint smart functions that
needs to be fixed

apps/trivium/src/lib.rs Outdated Show resolved Hide resolved
@github-actions
Copy link

Pull Request has been approved 🎉
Launching full test suite...
@slab-ci cpu_test
@slab-ci cpu_integer_test
@slab-ci cpu_multi_bit_test
@slab-ci cpu_wasm_test

@tmontaigu
Copy link
Contributor

@slab-ci cpu_test
@slab-ci cpu_integer_test
@slab-ci cpu_multi_bit_test
@slab-ci cpu_wasm_test

@tmontaigu
Copy link
Contributor

Well I saw that Arthur did the same thing as you but also corrected the smart function in this PR: #470 maybe we should just update Arthur's PR

@github-actions
Copy link

@slab-ci cpu_fast_test

@IceTDrinker
Copy link
Member

if this is working we could probably port the smart changes from my PR to this one I remember mine not passing tests IIRC
last commit is broken however in this PR

@github-actions
Copy link

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a 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 looks like some smart ops are still taking some inputs by non mutable reference

Comment on lines 1 to 2
#![allow(clippy::module_inception)]
#![allow(clippy::should_implement_trait)]
Copy link
Member

Choose a reason for hiding this comment

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

why is this needed ? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#![allow(clippy::should_implement_trait)]

In 4 places:
method next can be confused for the standard trait method std::iter::Iterator::next
consider implementing the trait std::iter::Iterator or choosing a less ambiguous method name
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait

#![allow(clippy::module_inception)]

In 3 places:
module has the same name as its containing module
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_inception

By adding this lines, I wanted to avoid moving/renaming things which is not rebase friendly

Please let me know if you think we should fix the lints in the PR.
Feel free to add a commit to this PR with theses fixes

Copy link
Member

Choose a reason for hiding this comment

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

which next function is impacted ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

apps/trivium/src/kreyvium/kreyvium_shortint.rs, line 78
apps/trivium/src/kreyvium/kreyvium.rs, line 152
apps/trivium/src/trivium/trivium_shortint.rs, line 66
apps/trivium/src/trivium/trivium.rs, line 124

I'll put the lint on each function

Copy link
Member

@IceTDrinker IceTDrinker Aug 29, 2023

Choose a reason for hiding this comment

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

otherwise rename the function to "next_byte" or whatever name fits the returned value ?

or implement iterator for those, but really not sure it's worth it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed next_ct and next_bool

ct_left: *mut ShortintCiphertext,
ct_left: *const ShortintCiphertext,
Copy link
Member

Choose a reason for hiding this comment

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

this should still be mut right ? as discussed for the smart stuff

code below should probably be updated as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In smart_scalar_add_assign, if unchecked_scalar_add_assign is impossible, we apply a shifted LUT to the input to get the output (https://github.com/zama-ai/tfhe-rs/blob/241bddccaf87724d123c45d96cb0660357356869/tfhe/src/shortint/engine/server_side/scalar_add.rs#L60C38-L60C38)
So in smart_scalar_add, I think we can either:

  • clone ct and call smart_scalar_add_assign on it -> input not cleaned, output clean
  • clean ct (if necessary), clone ct and call unchecked_scalar_add_assign on it -> input cleaned, output not clean

I kept the first version
I think both versions could be useful to have

Copy link
Member

Choose a reason for hiding this comment

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

the first version you describe sounds like a default operation, i.e. output is always clean
the second is a smart operation as far as I can tell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean
But it seems to me that the first version can give better performance than the second one if the input is never reused
So with this definition of smart operation, using smart operations can be more costly than using default ones (which is not intuitive)

I think the second version is more consistent with the rest of the codebase so I'll use it

Copy link
Member

Choose a reason for hiding this comment

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

indeed, though smart ops have this approach of cleaning inputs to hopefully gain time on later ops if re-used

that's why default ops have been made default, easier to reason about and not that bad performance characteristics ! 🙂

ct_left: *mut ShortintCiphertext,
ct_left: *const ShortintCiphertext,
Copy link
Member

Choose a reason for hiding this comment

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

idem

ct_left: *mut ShortintCiphertext,
ct_left: *const ShortintCiphertext,
Copy link
Member

Choose a reason for hiding this comment

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

idem

ct: *mut ShortintCiphertext,
ct: *const ShortintCiphertext,
Copy link
Member

Choose a reason for hiding this comment

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

idem

@@ -1,3 +1,5 @@
#![allow(clippy::redundant_locals)]
Copy link
Member

Choose a reason for hiding this comment

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

why is this needed ?

Copy link
Contributor Author

@mayeul-zama mayeul-zama Aug 28, 2023

Choose a reason for hiding this comment

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

Otherwise, the line let output_fft_buffer_re0 = &mut *output_fft_buffer_re0; and the 3 next ones are generating a warning which I believe is a false positive

Copy link
Member

Choose a reason for hiding this comment

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

removing the &mut is not enough ? looks like deref returns a mutable ref to a slice

Copy link
Member

Choose a reason for hiding this comment

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

basically I'm all against relaxing lints at file level, hence why I'm aksing this :)

it's an easy way to over disable stuff

Copy link
Member

Choose a reason for hiding this comment

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

if this is really a false positive then I would prefer a function level disable or even a block disable as these rust attributes can be put in a lot of places

Copy link
Member

Choose a reason for hiding this comment

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

could the lines be removed maybe ? maybe the compiler can deref things on its own

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does not work :(
I think that's the first thing I tried

Copy link
Member

Choose a reason for hiding this comment

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

last thing I'm thinking of: annotating the types on the left ? so that deref does not remove the reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the variables and adding &mut where they were used works (the * is not even needed)

Copy link
Member

Choose a reason for hiding this comment

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

perfect

tfhe/src/js_on_wasm_api/mod.rs Show resolved Hide resolved
tfhe/src/lib.rs Show resolved Hide resolved
@github-actions
Copy link

@slab-ci cpu_fast_test

1 similar comment
@github-actions
Copy link

@slab-ci cpu_fast_test

@github-actions
Copy link

@slab-ci cpu_fast_test

@github-actions
Copy link

@slab-ci cpu_fast_test

@github-actions
Copy link

@slab-ci cpu_fast_test

@github-actions
Copy link

@slab-ci cpu_fast_test

@mayeul-zama
Copy link
Contributor Author

@slab-ci cpu_fast_test
@slab-ci cpu_test
@slab-ci cpu_integer_test
@slab-ci cpu_multi_bit_test
@slab-ci cpu_wasm_test

@github-actions
Copy link

@slab-ci cpu_fast_test

@@ -603,9 +603,29 @@ impl ShortintEngine {
where
F: Fn(u64, u64) -> u64,
{
// TODO this looks wrong for the Accumulator generation
Copy link
Contributor Author

@mayeul-zama mayeul-zama Aug 30, 2023

Choose a reason for hiding this comment

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

Should this be checked/fixed now (this commit comes from @IceTDrinker PR) ?

Copy link
Member

Choose a reason for hiding this comment

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

it should have been fixed by Thomas IIRC check the main branch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In commit a0946ac?

Copy link
Member

Choose a reason for hiding this comment

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

think so yes

Copy link
Member

Choose a reason for hiding this comment

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

if you are confident with the current version launch all the test suites and we'll redo a thorough review of the new code

Copy link
Member

Choose a reason for hiding this comment

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

why is the TODO still here ? I thought we had it fixed in main 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove it

Copy link
Member

Choose a reason for hiding this comment

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

is the change you made still required ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took it from your PR
But I think so as it cleans the input if necessary instead of cleaning the result (cloned from the input)

Copy link
Member

Choose a reason for hiding this comment

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

my PR predates the fix from Thomas, i.e. the fix from Thomas should be the one to keep

@mayeul-zama
Copy link
Contributor Author

I think it would be better to split this PR in 2, to handle behavioral changes in a separate PR (2 commits feat(shortint): cleanup input if necessary in **) since I think of similar changes in other files
WDYT?

@IceTDrinker
Copy link
Member

I think it would be better to split this PR in 2, to handle behavioral changes in a separate PR (2 commits feat(shortint): cleanup input if necessary in **) since I think of similar changes in other files WDYT?

fine by me yes

@github-actions
Copy link

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

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

Thanks a lot @mayeul-zama for this tedious work 🙏

@github-actions
Copy link

Pull Request has been approved 🎉
Launching full test suite...
@slab-ci cpu_test
@slab-ci cpu_integer_test
@slab-ci cpu_multi_bit_test
@slab-ci cpu_wasm_test

@mayeul-zama mayeul-zama merged commit a6e4488 into main Aug 31, 2023
17 checks passed
@mayeul-zama mayeul-zama deleted the update_toolchain branch August 31, 2023 07:28
@mayeul-zama mayeul-zama mentioned this pull request Aug 31, 2023
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.

None yet

3 participants