Skip to content

Commit

Permalink
chore(integer): add compression benches
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Jul 24, 2024
1 parent 752cb46 commit b7fbd7b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tfhe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ path = "benches/shortint/glwe_packing_compression.rs"
harness = false
required-features = ["shortint", "internal-keycache"]

[[bench]]
name = "glwe_packing_compression-integer-bench"
path = "benches/integer/glwe_packing_compression.rs"
harness = false
required-features = ["integer", "internal-keycache"]


[[bench]]
name = "integer-bench"
Expand Down Expand Up @@ -329,5 +335,5 @@ crate-type = ["lib", "staticlib", "cdylib"]
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(bench)',
'cfg(tarpaulin)',
'cfg(tfhe_lints)'
'cfg(tfhe_lints)',
] }
81 changes: 81 additions & 0 deletions tfhe/benches/integer/glwe_packing_compression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use criterion::{black_box, criterion_group, Criterion};
use tfhe::integer::ciphertext::CompressedCiphertextListBuilder;
use tfhe::integer::{ClientKey, RadixCiphertext};
use tfhe::shortint::parameters::list_compression::COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64;

fn glwe_packing(c: &mut Criterion) {
let param = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64;

let comp_param = COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64;

let bench_name = "integer_packing_compression";

let mut bench_group = c.benchmark_group(bench_name);

let cks = ClientKey::new(param);

let private_compression_key = cks.new_compression_private_key(comp_param);

let (compression_key, decompression_key) =
cks.new_compression_decompression_keys(&private_compression_key);

let log_message_modulus = param.message_modulus.0.ilog2() as usize;

for num_bits in [
8,
16,
32,
64,
128,
256,
256,
comp_param.lwe_per_glwe.0 * log_message_modulus,
] {
assert_eq!(num_bits % log_message_modulus, 0);
let num_blocks = num_bits / log_message_modulus;

let ct = cks.encrypt_radix(0_u32, num_blocks);

let mut builder = CompressedCiphertextListBuilder::new();

builder.push(ct);

bench_group.bench_function(format!("pack_u{num_bits}"), |b| {
b.iter(|| {
let compressed = builder.build(&compression_key);

_ = black_box(compressed);
})
});

let compressed = builder.build(&compression_key);

bench_group.bench_function(format!("unpack_u{num_bits}"), |b| {
b.iter(|| {
let unpacked: RadixCiphertext =
compressed.get(0, &decompression_key).unwrap().unwrap();

_ = black_box(unpacked);
})
});

bench_group.bench_function(format!("pack_unpack_u{num_bits}"), |b| {
b.iter(|| {
let compressed = builder.build(&compression_key);

let unpacked: RadixCiphertext =
compressed.get(0, &decompression_key).unwrap().unwrap();

_ = black_box(unpacked);
})
});
}
}

criterion_group!(glwe_packing2, glwe_packing);

fn main() {
glwe_packing2();
Criterion::default().configure_from_args().final_summary();
}
1 change: 1 addition & 0 deletions tfhe/src/integer/ciphertext/compressed_ciphertext_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl Compressible for SignedRadixCiphertext {
}
}

#[derive(Clone)]
pub struct CompressedCiphertextListBuilder {
pub(crate) ciphertexts: Vec<Ciphertext>,
pub(crate) info: Vec<DataKind>,
Expand Down

0 comments on commit b7fbd7b

Please sign in to comment.