pbs count

This commit is contained in:
J-B Orfila
2024-03-20 18:28:02 +01:00
parent e81152a630
commit d0937aae20
2 changed files with 154 additions and 12 deletions

View File

@@ -1,7 +1,9 @@
use tfhe::prelude::*;
use tfhe::*;
pub fn main() {
let config = ConfigBuilder::default().build();
let (cks, sks) = generate_keys(config);
@@ -11,19 +13,163 @@ pub fn main() {
set_server_key(sks);
// Negation
let c = -&a;
let neg_32_count = get_pbs_count();
reset_pbs_count();
// Add / Sub
let c = &a + &b;
let add_32_count = get_pbs_count();
reset_pbs_count();
// Mul
let c = &a * &b;
let mul_32_count = get_pbs_count();
reset_pbs_count();
let d = &a & &b;
// Equal / Not Equal
let c = &a.eq(&b);
let eq_32_count = get_pbs_count();
reset_pbs_count();
// Comparisons
let c = &a.gt(&b);
let gt_32_count = get_pbs_count();
reset_pbs_count();
// Max / Min
let c = &a.max(&b);
let max_32_count = get_pbs_count();
reset_pbs_count();
// Bitwise operations
let c = &a & &b;
let and_32_count = get_pbs_count();
reset_pbs_count();
// Div / Rem
let c = &a % &b;
let mod_32_count = get_pbs_count();
reset_pbs_count();
// Left / Right Shifts
let c = &a << &b;
let shift_32_count = get_pbs_count();
reset_pbs_count();
// Left / Right Rotations
let c = &a.rotate_right(&b);
let rotate_32_count = get_pbs_count();
reset_pbs_count();
println!("neg_32_count: {neg_32_count}");
println!("add_32_count: {add_32_count}");
println!("mul_32_count: {mul_32_count}");
println!("eq_32_count: {eq_32_count}");
println!("gt_32_count: {gt_32_count}");
println!("max_32_count: {max_32_count}");
println!("and_32_count: {and_32_count}");
println!("mod_32_count: {mod_32_count}");
println!("shift_32_count: {shift_32_count}");
println!("and_32_count: {rotate_32_count}");
let c_dec: u32 = c.decrypt(&cks);
let d_dec: u32 = d.decrypt(&cks);
assert_eq!(42 * 69, c_dec);
assert_eq!(42 & 69, d_dec);
let config = ConfigBuilder::default().build();
let (cks, sks) = generate_keys(config);
let a = FheUint64::encrypt(42u64, &cks);
let b = FheUint64::encrypt(69u64, &cks);
set_server_key(sks);
// Negation
let c = -&a;
let neg_64_count = get_pbs_count();
reset_pbs_count();
// Add / Sub
let c = &a + &b;
let add_64_count = get_pbs_count();
reset_pbs_count();
// Mul
let c = &a * &b;
let mul_64_count = get_pbs_count();
reset_pbs_count();
// Equal / Not Equal
let c = &a.eq(&b);
let eq_64_count = get_pbs_count();
reset_pbs_count();
// Comparisons
let c = &a.gt(&b);
let gt_64_count = get_pbs_count();
reset_pbs_count();
// Max / Min
let c = &a.max(&b);
let max_64_count = get_pbs_count();
reset_pbs_count();
// Bitwise operations
let c = &a & &b;
let and_64_count = get_pbs_count();
reset_pbs_count();
// Div / Rem
let c = &a % &b;
let mod_64_count = get_pbs_count();
reset_pbs_count();
// Left / Right Shifts
let c = &a << &b;
let shift_64_count = get_pbs_count();
reset_pbs_count();
// Left / Right Rotations
let c = &a.rotate_right(&b);
let rotate_64_count = get_pbs_count();
reset_pbs_count();
println!("neg_64_count: {neg_64_count}");
println!("add_64_count: {add_64_count}");
println!("mul_64_count: {mul_64_count}");
println!("eq_64_count: {eq_64_count}");
println!("gt_64_count: {gt_64_count}");
println!("max_64_count: {max_64_count}");
println!("and_64_count: {and_64_count}");
println!("mod_64_count: {mod_64_count}");
println!("shift_64_count: {shift_64_count}");
println!("and_64_count: {rotate_64_count}");
assert!(false);
}
// pub fn count_all_pbs(){
// let (cks, sks) = generate_keys(config);
// let a = FheUint32::encrypt(42, &cks);
// let b = FheUint32::encrypt(69, &cks);
// set_server_key(sks);
// let c = &a * &b;
// let mul_32_count = get_pbs_count();
// reset_pbs_count();
// let d = &a & &b;
// let and_32_count = get_pbs_count();
// }

View File

@@ -745,9 +745,7 @@ pub const PARAM_MESSAGE_2_CARRY_2_KS_PBS: ClassicPBSParameters = ClassicPBSParam
lwe_dimension: LweDimension(742),
glwe_dimension: GlweDimension(1),
polynomial_size: PolynomialSize(2048),
lwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev(
0.000007069849454709433,
)),
lwe_noise_distribution: DynamicDistribution::new_t_uniform(4),
glwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev(
0.00000000000000029403601535432533,
)),
@@ -1201,9 +1199,7 @@ pub const PARAM_MESSAGE_4_CARRY_4_KS_PBS: ClassicPBSParameters = ClassicPBSParam
lwe_dimension: LweDimension(996),
glwe_dimension: GlweDimension(1),
polynomial_size: PolynomialSize(32768),
lwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev(
0.00000006767666038309478,
)),
lwe_noise_distribution: DynamicDistribution::new_t_uniform(4),
glwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev(
0.0000000000000000002168404344971009,
)),