Skip to content

Commit

Permalink
chore(tfhe): update toolchain to avoid SIMD breakage, fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
IceTDrinker committed Feb 28, 2024
1 parent c0240af commit 8e17e31
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 17 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tasks/src/format_latex_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommentContent>,
full_doc_comment_content: &[CommentContent],
part_start_idx: usize,
) -> (usize, usize) {
let mut next_line_idx = part_start_idx + 1;
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions tfhe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion tfhe/benches/shortint/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion tfhe/examples/regex_engine/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tfhe/src/core_crypto/fft_impl/fft128_u128/crypto/tests.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 3 additions & 2 deletions tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/fft_impl/fft64/crypto/ggsw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions tfhe/src/high_level_api/integers/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ impl IntegerCompactPublicKey {
where
T: crate::integer::block_decomposition::DecomposableInto<u64>,
{
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)
}
Expand Down
1 change: 1 addition & 0 deletions tfhe/src/high_level_api/integers/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClientKey> {
fn new(client_key: &ClientKey) -> Self;

Expand Down
1 change: 1 addition & 0 deletions tfhe/src/high_level_api/integers/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_imports)]
pub use base::GenericInteger;

expand_pub_use_fhe_type!(
Expand Down
5 changes: 5 additions & 0 deletions tfhe/src/high_level_api/internal_traits.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
/// Trait to be implemented on keys that encrypts clear values into ciphertexts
#[allow(dead_code)]
pub(crate) trait EncryptionKey<ClearType, CiphertextType> {
/// 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<CiphertextType, ClearType> {
/// The decryption process
fn decrypt(&self, ciphertext: &CiphertextType) -> ClearType;
}

#[allow(dead_code)]
pub trait FromParameters<P> {
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;
}
1 change: 1 addition & 0 deletions tfhe/src/high_level_api/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tfhe/src/high_level_api/keys/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -141,6 +142,7 @@ impl CompressedPublicKey {
}
}

#[allow(dead_code)]
pub trait RefKeyFromCompressedPublicKeyChain: Sized {
type Key;

Expand Down
1 change: 1 addition & 0 deletions tfhe/src/high_level_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/js_on_wasm_api/shortint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl Shortint {

let mut seeder = DeterministicSeeder::<ActivatedRandomGenerator>::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)
}
Expand Down
8 changes: 7 additions & 1 deletion tfhe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion toolchain.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2023-08-28
nightly-2024-02-13

0 comments on commit 8e17e31

Please sign in to comment.