-
Notifications
You must be signed in to change notification settings - Fork 130
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
Update toolchain #494
Conversation
@slab-ci cpu_fast_test |
f3dda23
to
3ae3124
Compare
@slab-ci cpu_fast_test |
@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, |
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.
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
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.
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?
- keep
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
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.
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
Pull Request has been approved 🎉 |
@slab-ci cpu_test |
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 |
@slab-ci cpu_fast_test |
if this is working we could probably port the smart changes from my PR to this one I remember mine not passing tests IIRC |
a2a4efc
to
89fdde3
Compare
@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 looks like some smart ops are still taking some inputs by non mutable reference
apps/trivium/src/lib.rs
Outdated
#![allow(clippy::module_inception)] | ||
#![allow(clippy::should_implement_trait)] |
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.
why is this needed ? 🤔
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.
#![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
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.
which next function is impacted ?
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.
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
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.
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 ?
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.
Renamed next_ct
and next_bool
ct_left: *mut ShortintCiphertext, | ||
ct_left: *const ShortintCiphertext, |
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 should still be mut right ? as discussed for the smart stuff
code below should probably be updated as well
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.
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 callsmart_scalar_add_assign
on it -> input not cleaned, output clean - clean
ct
(if necessary), clonect
and callunchecked_scalar_add_assign
on it -> input cleaned, output not clean
I kept the first version
I think both versions could be useful to have
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.
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
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 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
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.
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, |
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.
idem
ct_left: *mut ShortintCiphertext, | ||
ct_left: *const ShortintCiphertext, |
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.
idem
ct: *mut ShortintCiphertext, | ||
ct: *const ShortintCiphertext, |
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.
idem
@@ -1,3 +1,5 @@ | |||
#![allow(clippy::redundant_locals)] |
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.
why is this needed ?
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.
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
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.
removing the &mut is not enough ? looks like deref returns a mutable ref to a slice
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.
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
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.
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
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 the lines be removed maybe ? maybe the compiler can deref things on its own
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 does not work :(
I think that's the first thing I tried
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.
last thing I'm thinking of: annotating the types on the left ? so that deref does not remove the reference
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.
Removing the variables and adding &mut
where they were used works (the *
is not even needed)
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.
perfect
89fdde3
to
d84cd9f
Compare
@slab-ci cpu_fast_test |
1 similar comment
@slab-ci cpu_fast_test |
d6f5d37
to
c0bd0cd
Compare
@slab-ci cpu_fast_test |
c0bd0cd
to
4841137
Compare
@slab-ci cpu_fast_test |
4841137
to
4bec46e
Compare
@slab-ci cpu_fast_test |
4bec46e
to
959b71b
Compare
@slab-ci cpu_fast_test |
@slab-ci cpu_fast_test |
@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 |
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 checked/fixed now (this commit comes from @IceTDrinker PR) ?
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.
it should have been fixed by Thomas IIRC check the main branch
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.
In commit a0946ac?
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.
think so yes
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.
if you are confident with the current version launch all the test suites and we'll redo a thorough review of the new code
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.
why is the TODO still here ? I thought we had it fixed in main 🤔
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 will remove it
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.
is the change you made still required ?
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 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)
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.
my PR predates the fix from Thomas, i.e. the fix from Thomas should be the one to keep
I think it would be better to split this PR in 2, to handle behavioral changes in a separate PR (2 commits |
fine by me yes |
09368f2
to
677c911
Compare
@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.
Thanks a lot @mayeul-zama for this tedious work 🙏
Pull Request has been approved 🎉 |
PR content/description
Update rust toolchain