From 8e17e31fbdabf5168bb02305a7f554da68501c6c Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Wed, 28 Feb 2024 19:00:18 +0100 Subject: [PATCH] chore(tfhe): update toolchain to avoid SIMD breakage, fix lints --- Makefile | 6 ++++++ tasks/src/format_latex_doc.rs | 4 ++-- tfhe/Cargo.toml | 6 +++--- tfhe/benches/shortint/bench.rs | 2 +- tfhe/examples/regex_engine/engine.rs | 2 +- tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/tests.rs | 1 + tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs | 5 +++-- tfhe/src/core_crypto/fft_impl/fft64/crypto/ggsw.rs | 4 ++-- tfhe/src/high_level_api/integers/keys.rs | 4 +--- tfhe/src/high_level_api/integers/parameters.rs | 1 + tfhe/src/high_level_api/integers/types/mod.rs | 1 + tfhe/src/high_level_api/internal_traits.rs | 5 +++++ tfhe/src/high_level_api/keys/mod.rs | 1 + tfhe/src/high_level_api/keys/public.rs | 2 ++ tfhe/src/high_level_api/mod.rs | 1 + tfhe/src/js_on_wasm_api/shortint.rs | 2 +- tfhe/src/lib.rs | 8 +++++++- .../shortint/parameters/parameters_wopbs_prime_moduli.rs | 1 + toolchain.txt | 2 +- 19 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index a67a8cb321..572b77f1a3 100644 --- a/Makefile +++ b/Makefile @@ -158,6 +158,12 @@ clippy_core: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ --features=$(TARGET_ARCH_FEATURE),experimental \ -p $(TFHE_SPEC) -- --no-deps -D warnings + RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ + --features=$(TARGET_ARCH_FEATURE),nightly-avx512 \ + -p $(TFHE_SPEC) -- --no-deps -D warnings + RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ + --features=$(TARGET_ARCH_FEATURE),experimental,nightly-avx512 \ + -p $(TFHE_SPEC) -- --no-deps -D warnings .PHONY: clippy_boolean # Run clippy lints enabling the boolean features clippy_boolean: install_rs_check_toolchain diff --git a/tasks/src/format_latex_doc.rs b/tasks/src/format_latex_doc.rs index 6504c79ef1..253b2490a1 100644 --- a/tasks/src/format_latex_doc.rs +++ b/tasks/src/format_latex_doc.rs @@ -196,7 +196,7 @@ fn find_contiguous_doc_test<'a>( fn find_contiguous_part_in_doc_test_or_comment( part_is_code_block: bool, - full_doc_comment_content: &Vec, + full_doc_comment_content: &[CommentContent], part_start_idx: usize, ) -> (usize, usize) { let mut next_line_idx = part_start_idx + 1; @@ -348,7 +348,7 @@ fn process_doc_lines_until_impossible<'a>( } fn process_non_doc_lines_until_impossible( - lines: &Vec<&str>, + lines: &[&str], rewritten_content: &mut String, mut line_idx: usize, ) -> usize { diff --git a/tfhe/Cargo.toml b/tfhe/Cargo.toml index 3d4b1e2c63..057154d341 100644 --- a/tfhe/Cargo.toml +++ b/tfhe/Cargo.toml @@ -57,8 +57,8 @@ lazy_static = { version = "1.4.0", optional = true } serde = { version = "1.0", features = ["derive"] } rayon = { version = "1.5.0" } bincode = { version = "1.3.3", optional = true } -concrete-fft = { version = "0.3.0", features = ["serde", "fft128"] } -pulp = "0.13" +concrete-fft = { version = "0.4.0", features = ["serde", "fft128"] } +pulp = "0.18.8" aligned-vec = { version = "0.5", features = ["serde"] } dyn-stack = { version = "0.9" } paste = { version = "1.0.7", optional = true } @@ -79,7 +79,7 @@ js-sys = { version = "0.3", optional = true } console_error_panic_hook = { version = "0.1.7", optional = true } serde-wasm-bindgen = { version = "0.6.0", optional = true } getrandom = { version = "0.2.8", optional = true } -bytemuck = "=1.14.1" +bytemuck = "1.14.3" [features] forward_compatibility = [ diff --git a/tfhe/benches/shortint/bench.rs b/tfhe/benches/shortint/bench.rs index 1b7ade2bac..67e3fe4c17 100644 --- a/tfhe/benches/shortint/bench.rs +++ b/tfhe/benches/shortint/bench.rs @@ -393,7 +393,7 @@ fn _bench_wopbs_param_message_8_norm2_5(c: &mut Criterion) { let mut bench_group = c.benchmark_group("programmable_bootstrap"); let param = WOPBS_PARAM_MESSAGE_4_NORM2_6_KS_PBS; - let param_set: ShortintParameterSet = param.try_into().unwrap(); + let param_set: ShortintParameterSet = param.into(); let pbs_params = param_set.pbs_parameters().unwrap(); let keys = KEY_CACHE_WOPBS.get_from_param((pbs_params, param)); diff --git a/tfhe/examples/regex_engine/engine.rs b/tfhe/examples/regex_engine/engine.rs index cb0611438c..9fdb486ac2 100644 --- a/tfhe/examples/regex_engine/engine.rs +++ b/tfhe/examples/regex_engine/engine.rs @@ -19,7 +19,7 @@ pub fn has_match( let res = if branches.len() <= 1 { branches - .get(0) + .first() .map_or(exec.ct_false(), |branch| branch(&mut exec)) .0 } else { diff --git a/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/tests.rs b/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/tests.rs index 128bd54de5..8d04f296d7 100644 --- a/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/tests.rs +++ b/tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/tests.rs @@ -1,6 +1,7 @@ use dyn_stack::{GlobalPodBuffer, PodStack, ReborrowMut}; use super::super::super::{fft128, fft128_u128}; +#[allow(unused_imports)] use super::super::math::fft::{Fft128, Fft128View}; use crate::core_crypto::prelude::*; use aligned_vec::CACHELINE_ALIGN; diff --git a/tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs b/tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs index ed05535195..597e9ff63f 100644 --- a/tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs +++ b/tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs @@ -1,13 +1,14 @@ use crate::core_crypto::commons::utils::izip; +#[allow(unused_imports)] pub use crate::core_crypto::fft_impl::fft128::math::fft::{Fft128, Fft128View}; use concrete_fft::fft128::f128; use dyn_stack::PodStack; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -use pulp::x86::{f64x4, u64x4, V3}; +use pulp::{f64x4, u64x4, x86::V3}; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(feature = "nightly-avx512")] -use pulp::x86::{f64x8, u64x8, V4}; +use pulp::{f64x8, u64x8, x86::V4}; #[inline(always)] pub fn zeroing_shl(x: u64, shift: u64) -> u64 { diff --git a/tfhe/src/core_crypto/fft_impl/fft64/crypto/ggsw.rs b/tfhe/src/core_crypto/fft_impl/fft64/crypto/ggsw.rs index f0d894ced2..7c143d46eb 100644 --- a/tfhe/src/core_crypto/fft_impl/fft64/crypto/ggsw.rs +++ b/tfhe/src/core_crypto/fft_impl/fft64/crypto/ggsw.rs @@ -671,7 +671,7 @@ pub(crate) fn update_with_fmadd( let lhs = S::c64s_as_simd(ggsw_poly).0; for (out, &lhs, &rhs) in izip!(out, lhs, rhs) { - *out = simd.c64s_mul_adde(lhs, rhs, *out); + *out = simd.c64s_mul_add_e(lhs, rhs, *out); } } } @@ -737,7 +737,7 @@ pub(crate) fn update_with_fmadd_factor( } else { for (out, &lhs, &rhs) in izip!(out, lhs, rhs) { // NOTE: see above - *out = simd.c64s_mul_adde(factor, simd.c64s_mul(lhs, rhs), *out); + *out = simd.c64s_mul_add_e(factor, simd.c64s_mul(lhs, rhs), *out); } } } diff --git a/tfhe/src/high_level_api/integers/keys.rs b/tfhe/src/high_level_api/integers/keys.rs index e4be7f9f80..49b4d08d88 100644 --- a/tfhe/src/high_level_api/integers/keys.rs +++ b/tfhe/src/high_level_api/integers/keys.rs @@ -204,9 +204,7 @@ impl IntegerCompactPublicKey { where T: crate::integer::block_decomposition::DecomposableInto, { - let Some(key) = self.key.as_ref() else { - return None; - }; + let key = self.key.as_ref()?; let ct = key.encrypt_slice_radix_compact(values, num_blocks); Some(ct) } diff --git a/tfhe/src/high_level_api/integers/parameters.rs b/tfhe/src/high_level_api/integers/parameters.rs index ec81696cce..e0c1be4474 100644 --- a/tfhe/src/high_level_api/integers/parameters.rs +++ b/tfhe/src/high_level_api/integers/parameters.rs @@ -2,6 +2,7 @@ use crate::high_level_api::internal_traits::ParameterType; /// Meant to be implemented on the inner server key /// eg the crate::integer::ServerKey +#[allow(dead_code)] pub trait EvaluationIntegerKey { fn new(client_key: &ClientKey) -> Self; diff --git a/tfhe/src/high_level_api/integers/types/mod.rs b/tfhe/src/high_level_api/integers/types/mod.rs index 2a16d7f080..a1e36ca5bd 100644 --- a/tfhe/src/high_level_api/integers/types/mod.rs +++ b/tfhe/src/high_level_api/integers/types/mod.rs @@ -1,3 +1,4 @@ +#[allow(unused_imports)] pub use base::GenericInteger; expand_pub_use_fhe_type!( diff --git a/tfhe/src/high_level_api/internal_traits.rs b/tfhe/src/high_level_api/internal_traits.rs index 00c64483c5..35026cf402 100644 --- a/tfhe/src/high_level_api/internal_traits.rs +++ b/tfhe/src/high_level_api/internal_traits.rs @@ -1,25 +1,30 @@ /// Trait to be implemented on keys that encrypts clear values into ciphertexts +#[allow(dead_code)] pub(crate) trait EncryptionKey { /// The encryption process fn encrypt(&self, value: ClearType) -> CiphertextType; } /// Trait to be implemented on keys that decrypts ciphertext into clear values +#[allow(dead_code)] pub(crate) trait DecryptionKey { /// The decryption process fn decrypt(&self, ciphertext: &CiphertextType) -> ClearType; } +#[allow(dead_code)] pub trait FromParameters

{ fn from_parameters(parameters: P) -> Self; } +#[allow(dead_code)] pub trait ParameterType: Clone { /// The Id allows to differentiate the different parameters /// as well as retrieving the corresponding client key and server key type Id: Copy; } +#[allow(dead_code)] pub trait TypeIdentifier { fn type_variant(&self) -> crate::high_level_api::errors::Type; } diff --git a/tfhe/src/high_level_api/keys/mod.rs b/tfhe/src/high_level_api/keys/mod.rs index 48219a936b..feebef60cb 100644 --- a/tfhe/src/high_level_api/keys/mod.rs +++ b/tfhe/src/high_level_api/keys/mod.rs @@ -6,6 +6,7 @@ mod server; use crate::high_level_api::config::Config; pub use client::{ClientKey, RefKeyFromKeyChain}; +#[allow(unused_imports)] pub use public::{ CompactPublicKey, CompressedCompactPublicKey, CompressedPublicKey, PublicKey, RefKeyFromCompressedPublicKeyChain, RefKeyFromPublicKeyChain, diff --git a/tfhe/src/high_level_api/keys/public.rs b/tfhe/src/high_level_api/keys/public.rs index 10677ef7a3..0947071bbf 100644 --- a/tfhe/src/high_level_api/keys/public.rs +++ b/tfhe/src/high_level_api/keys/public.rs @@ -53,6 +53,7 @@ impl PublicKey { /// in the `PublicKey`. /// /// This is to allow the writing of generic functions. +#[allow(dead_code)] pub trait RefKeyFromPublicKeyChain: Sized { type Key; @@ -141,6 +142,7 @@ impl CompressedPublicKey { } } +#[allow(dead_code)] pub trait RefKeyFromCompressedPublicKeyChain: Sized { type Key; diff --git a/tfhe/src/high_level_api/mod.rs b/tfhe/src/high_level_api/mod.rs index 9448300b08..9675cf6df0 100644 --- a/tfhe/src/high_level_api/mod.rs +++ b/tfhe/src/high_level_api/mod.rs @@ -24,6 +24,7 @@ macro_rules! expand_pub_use_fhe_type( } ); +#[allow(unused_imports)] pub use crate::core_crypto::commons::math::random::Seed; pub use config::{Config, ConfigBuilder}; pub use errors::{Error, OutOfRangeError}; diff --git a/tfhe/src/js_on_wasm_api/shortint.rs b/tfhe/src/js_on_wasm_api/shortint.rs index a25d8210ca..0826fb4057 100644 --- a/tfhe/src/js_on_wasm_api/shortint.rs +++ b/tfhe/src/js_on_wasm_api/shortint.rs @@ -352,7 +352,7 @@ impl Shortint { let mut seeder = DeterministicSeeder::::new(Seed(seed)); crate::shortint::engine::ShortintEngine::new_from_seeder(&mut seeder) - .new_client_key(parameters.0.try_into().unwrap()) + .new_client_key(parameters.0.into()) .map_err(|e| wasm_bindgen::JsError::new(format!("{e:?}").as_str())) .map(ShortintClientKey) } diff --git a/tfhe/src/lib.rs b/tfhe/src/lib.rs index ca85f32bdb..d37c92ca08 100644 --- a/tfhe/src/lib.rs +++ b/tfhe/src/lib.rs @@ -3,7 +3,13 @@ //! TFHE-rs is a fully homomorphic encryption (FHE) library that implements Zama's variant of TFHE. #![cfg_attr(feature = "__wasm_api", allow(dead_code))] -#![cfg_attr(feature = "nightly-avx512", feature(stdsimd, avx512_target_feature))] +#![cfg_attr( + all( + any(target_arch = "x86", target_arch = "x86_64"), + feature = "nightly-avx512" + ), + feature(avx512_target_feature, stdarch_x86_avx512) +)] #![cfg_attr(all(doc, not(doctest)), feature(doc_auto_cfg))] #![cfg_attr(all(doc, not(doctest)), feature(doc_cfg))] #![warn(rustdoc::broken_intra_doc_links)] diff --git a/tfhe/src/shortint/parameters/parameters_wopbs_prime_moduli.rs b/tfhe/src/shortint/parameters/parameters_wopbs_prime_moduli.rs index ba2d50c216..95986003b6 100644 --- a/tfhe/src/shortint/parameters/parameters_wopbs_prime_moduli.rs +++ b/tfhe/src/shortint/parameters/parameters_wopbs_prime_moduli.rs @@ -1,3 +1,4 @@ +#[allow(unused_imports)] pub use crate::core_crypto::commons::dispersion::{DispersionParameter, StandardDev}; pub use crate::core_crypto::commons::parameters::{ DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize, diff --git a/toolchain.txt b/toolchain.txt index 5f169ab8fe..32a59aa422 100644 --- a/toolchain.txt +++ b/toolchain.txt @@ -1 +1 @@ -nightly-2023-08-28 +nightly-2024-02-13