-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(integer): add compression benches
- Loading branch information
1 parent
752cb46
commit b7fbd7b
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters