Support for bivariate convolution & normalization with offset (#126)

* Add bivariate-convolution
* Add pair-wise convolution + tests + benches
* Add take_cnv_pvec_[left/right] to Scratch & updated CHANGELOG.md
* cross-base2k normalization with positive offset
* clippy & fix CI doctest avx compile error
* more streamlined bounds derivation for normalization
* Working cross-base2k normalization with pos/neg offset
* Update normalization API & tests
* Add glwe tensoring test
* Add relinearization + preliminary test
* Fix GGLWEToGGSW key infos
* Add (X,Y) convolution by const (1, Y) poly
* Faster normalization test + add bench for cnv_by_const
* Update changelog
This commit is contained in:
Jean-Philippe Bossuat
2025-12-21 16:56:42 +01:00
committed by GitHub
parent 76424d0ab5
commit 4e90e08a71
219 changed files with 6571 additions and 5041 deletions

View File

@@ -162,14 +162,7 @@ where
// This key is required to prepare all Fhe Integers for operations,
// and for performing the operations themselves
let mut bdd_key: BDDKey<Vec<u8>, BRA> = BDDKey::alloc_from_infos(&bdd_layout);
bdd_key.encrypt_sk(
&module,
&sk_lwe,
&sk_glwe,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
bdd_key.encrypt_sk(&module, &sk_lwe, &sk_glwe, &mut source_xa, &mut source_xe, scratch.borrow());
////////// Input Encryption
// Encrypting the inputs
@@ -216,13 +209,7 @@ where
let mut c_enc: FheUint<Vec<u8>, u32> = FheUint::alloc_from_infos(&glwe_layout);
// Performing the operation
c_enc.add(
&module,
&a_enc_prepared,
&b_enc_prepared,
&bdd_key_prepared,
scratch.borrow(),
);
c_enc.add(&module, &a_enc_prepared, &b_enc_prepared, &bdd_key_prepared, scratch.borrow());
// Preparing the intermediate result ciphertext, c_enc, for the next operation
let mut c_enc_prepared: FheUintPrepared<Vec<u8>, u32, BE> = FheUintPrepared::alloc_from_infos(&module, &ggsw_layout);
@@ -230,13 +217,7 @@ where
// Creating the output ciphertext d_enc
let mut selected_enc: FheUint<Vec<u8>, u32> = FheUint::alloc_from_infos(&glwe_layout);
selected_enc.xor(
&module,
&c_enc_prepared,
&a_enc_prepared,
&bdd_key_prepared,
scratch.borrow(),
);
selected_enc.xor(&module, &c_enc_prepared, &a_enc_prepared, &bdd_key_prepared, scratch.borrow());
//////// Homomorphic computation ends here ////////
@@ -301,12 +282,7 @@ where
);
let mut input_selector_enc_prepared: FheUintPrepared<Vec<u8>, u32, BE> =
FheUintPrepared::alloc_from_infos(&module, &ggsw_layout);
input_selector_enc_prepared.prepare(
&module,
&input_selector_enc,
&bdd_key_prepared,
scratch.borrow(),
);
input_selector_enc_prepared.prepare(&module, &input_selector_enc, &bdd_key_prepared, scratch.borrow());
module.glwe_blind_selection(
&mut selected_enc,

View File

@@ -8,10 +8,20 @@ use poulpy_core::{
};
use std::time::Instant;
#[cfg(all(feature = "enable-avx", target_arch = "x86_64", target_feature = "avx2", target_feature = "fma"))]
#[cfg(all(
feature = "enable-avx",
target_arch = "x86_64",
target_feature = "avx2",
target_feature = "fma"
))]
use poulpy_cpu_avx::FFT64Avx as BackendImpl;
#[cfg(not(all(feature = "enable-avx", target_arch = "x86_64", target_feature = "avx2", target_feature = "fma")))]
#[cfg(not(all(
feature = "enable-avx",
target_arch = "x86_64",
target_feature = "avx2",
target_feature = "fma"
)))]
use poulpy_cpu_ref::FFT64Ref as BackendImpl;
use poulpy_hal::{
@@ -162,28 +172,14 @@ fn main() {
let mut ct_lwe: LWE<Vec<u8>> = LWE::alloc_from_infos(&lwe_infos);
// Encrypt LWE Plaintext
ct_lwe.encrypt_sk(
&module,
&pt_lwe,
&sk_lwe,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
ct_lwe.encrypt_sk(&module, &pt_lwe, &sk_lwe, &mut source_xa, &mut source_xe, scratch.borrow());
let now: Instant = Instant::now();
// Circuit bootstrapping evaluation key
let mut cbt_key: CircuitBootstrappingKey<Vec<u8>, CGGI> = CircuitBootstrappingKey::alloc_from_infos(&cbt_layout);
cbt_key.encrypt_sk(
&module,
&sk_lwe,
&sk_glwe,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
cbt_key.encrypt_sk(&module, &sk_lwe, &sk_glwe, &mut source_xa, &mut source_xe, scratch.borrow());
println!("CBT-KGEN: {} ms", now.elapsed().as_millis());
@@ -197,14 +193,7 @@ fn main() {
// Apply circuit bootstrapping: LWE(data * 2^{- (k_lwe_pt + 2)}) -> GGSW(data)
let now: Instant = Instant::now();
cbt_prepared.execute_to_constant(
&module,
&mut res,
&ct_lwe,
k_lwe_pt,
extension_factor,
scratch.borrow(),
);
cbt_prepared.execute_to_constant(&module, &mut res, &ct_lwe, k_lwe_pt, extension_factor, scratch.borrow());
println!("CBT: {} ms", now.elapsed().as_millis());
// Allocate "ideal" GGSW(data) plaintext
@@ -216,16 +205,9 @@ fn main() {
for col in 0..res.rank().as_usize() + 1 {
println!(
"row:{row} col:{col} -> {}",
res.noise(
&module,
row,
col,
&pt_ggsw,
&sk_glwe_prepared,
scratch.borrow()
)
.std()
.log2()
res.noise(&module, row, col, &pt_ggsw, &sk_glwe_prepared, scratch.borrow())
.std()
.log2()
)
}
}

View File

@@ -152,14 +152,7 @@ where
// This key is required to prepare all Fhe Integers for operations,
// and for performing the operations themselves
let mut bdd_key: BDDKey<Vec<u8>, BRA> = BDDKey::alloc_from_infos(&bdd_layout);
bdd_key.encrypt_sk(
&module,
&sk_lwe,
&sk_glwe,
&mut source_xa,
&mut source_xe,
scratch.borrow(),
);
bdd_key.encrypt_sk(&module, &sk_lwe, &sk_glwe, &mut source_xa, &mut source_xe, scratch.borrow());
////////// Input Encryption
// Encrypting the inputs