mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-08 22:28:01 -05:00
chore(bench): new parameters set to run core_crypto bench for docs
This creates extended parameters set to reflect what's displayed in the documentation.
This commit is contained in:
@@ -4,14 +4,13 @@ use benchmark::params::{
|
||||
benchmark_compression_parameters, benchmark_parameters, multi_bit_benchmark_parameters,
|
||||
};
|
||||
use benchmark::utilities::{
|
||||
get_bench_type, throughput_num_threads, write_to_json, BenchmarkType, CryptoParametersRecord,
|
||||
OperatorType,
|
||||
get_bench_type, get_param_type, throughput_num_threads, write_to_json, BenchmarkType,
|
||||
CryptoParametersRecord, OperatorType, ParamType,
|
||||
};
|
||||
use criterion::{black_box, Criterion, Throughput};
|
||||
use itertools::Itertools;
|
||||
use rayon::prelude::*;
|
||||
use serde::Serialize;
|
||||
use std::env;
|
||||
use tfhe::core_crypto::prelude::*;
|
||||
|
||||
// TODO Refactor KS, PBS and KS-PBS benchmarks into a single generic function.
|
||||
@@ -788,6 +787,13 @@ mod cuda {
|
||||
cuda_packing_keyswitch(&mut criterion, &benchmark_parameters());
|
||||
}
|
||||
|
||||
pub fn cuda_ks_group_documentation() {
|
||||
let mut criterion: Criterion<_> = (Criterion::default().sample_size(15))
|
||||
.measurement_time(std::time::Duration::from_secs(60))
|
||||
.configure_from_args();
|
||||
cuda_keyswitch(&mut criterion, &benchmark_parameters());
|
||||
}
|
||||
|
||||
pub fn cuda_multi_bit_ks_group() {
|
||||
let mut criterion: Criterion<_> =
|
||||
(Criterion::default().sample_size(2000)).configure_from_args();
|
||||
@@ -798,10 +804,23 @@ mod cuda {
|
||||
cuda_keyswitch(&mut criterion, &multi_bit_parameters);
|
||||
cuda_packing_keyswitch(&mut criterion, &multi_bit_parameters);
|
||||
}
|
||||
|
||||
pub fn cuda_multi_bit_ks_group_documentation() {
|
||||
let mut criterion: Criterion<_> =
|
||||
(Criterion::default().sample_size(2000)).configure_from_args();
|
||||
let multi_bit_parameters = multi_bit_benchmark_parameters()
|
||||
.into_iter()
|
||||
.map(|(string, params, _)| (string, params))
|
||||
.collect_vec();
|
||||
cuda_keyswitch(&mut criterion, &multi_bit_parameters);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gpu")]
|
||||
use cuda::{cuda_ks_group, cuda_multi_bit_ks_group};
|
||||
use cuda::{
|
||||
cuda_ks_group, cuda_ks_group_documentation, cuda_multi_bit_ks_group,
|
||||
cuda_multi_bit_ks_group_documentation,
|
||||
};
|
||||
|
||||
pub fn ks_group() {
|
||||
let mut criterion: Criterion<_> = (Criterion::default()
|
||||
@@ -846,39 +865,32 @@ pub fn packing_ks_group() {
|
||||
}
|
||||
|
||||
#[cfg(feature = "gpu")]
|
||||
fn go_through_gpu_bench_groups(val: &str) {
|
||||
match val.to_lowercase().as_str() {
|
||||
"classical" => cuda_ks_group(),
|
||||
"multi_bit" => cuda_multi_bit_ks_group(),
|
||||
_ => panic!("unknown benchmark operations flavor"),
|
||||
fn go_through_gpu_bench_groups() {
|
||||
match get_param_type() {
|
||||
ParamType::Classical => cuda_ks_group(),
|
||||
ParamType::ClassicalDocumentation => cuda_ks_group_documentation(),
|
||||
ParamType::MultiBit => cuda_multi_bit_ks_group(),
|
||||
ParamType::MultiBitDocumentation => cuda_multi_bit_ks_group_documentation(),
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
fn go_through_cpu_bench_groups(val: &str) {
|
||||
match val.to_lowercase().as_str() {
|
||||
"classical" => {
|
||||
fn go_through_cpu_bench_groups() {
|
||||
match get_param_type() {
|
||||
ParamType::Classical => {
|
||||
ks_group();
|
||||
packing_ks_group()
|
||||
}
|
||||
"multi_bit" => multi_bit_ks_group(),
|
||||
_ => panic!("unknown benchmark operations flavor"),
|
||||
ParamType::ClassicalDocumentation => ks_group(),
|
||||
ParamType::MultiBit | ParamType::MultiBitDocumentation => multi_bit_ks_group(),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match env::var("__TFHE_RS_PARAM_TYPE") {
|
||||
Ok(val) => {
|
||||
#[cfg(feature = "gpu")]
|
||||
go_through_gpu_bench_groups(&val);
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
go_through_cpu_bench_groups(&val);
|
||||
}
|
||||
Err(_) => {
|
||||
ks_group();
|
||||
packing_ks_group()
|
||||
}
|
||||
};
|
||||
#[cfg(feature = "gpu")]
|
||||
go_through_gpu_bench_groups();
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
go_through_cpu_bench_groups();
|
||||
|
||||
Criterion::default().configure_from_args().final_summary();
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@ use benchmark::params::{
|
||||
benchmark_parameters, multi_bit_benchmark_parameters_with_grouping, multi_bit_num_threads,
|
||||
};
|
||||
use benchmark::utilities::{
|
||||
get_bench_type, throughput_num_threads, write_to_json, BenchmarkType, CryptoParametersRecord,
|
||||
OperatorType,
|
||||
get_bench_type, get_param_type, throughput_num_threads, write_to_json, BenchmarkType,
|
||||
CryptoParametersRecord, OperatorType, ParamType,
|
||||
};
|
||||
use criterion::{black_box, Criterion, Throughput};
|
||||
use rayon::prelude::*;
|
||||
use serde::Serialize;
|
||||
use std::env;
|
||||
use tfhe::core_crypto::prelude::*;
|
||||
|
||||
// TODO Refactor KS, PBS and KS-PBS benchmarks into a single generic function.
|
||||
@@ -1147,11 +1146,6 @@ pub fn ks_pbs_group() {
|
||||
|
||||
pub fn multi_bit_ks_pbs_group() {
|
||||
let mut criterion: Criterion<_> = (Criterion::default()).configure_from_args();
|
||||
multi_bit_ks_pbs(
|
||||
&mut criterion,
|
||||
&multi_bit_benchmark_parameters_with_grouping(),
|
||||
false,
|
||||
);
|
||||
multi_bit_ks_pbs(
|
||||
&mut criterion,
|
||||
&multi_bit_benchmark_parameters_with_grouping(),
|
||||
@@ -1160,36 +1154,26 @@ pub fn multi_bit_ks_pbs_group() {
|
||||
}
|
||||
|
||||
#[cfg(feature = "gpu")]
|
||||
fn go_through_gpu_bench_groups(val: &str) {
|
||||
match val.to_lowercase().as_str() {
|
||||
"classical" => cuda_ks_pbs_group(),
|
||||
"multi_bit" => cuda_multi_bit_ks_pbs_group(),
|
||||
_ => panic!("unknown benchmark operations flavor"),
|
||||
fn go_through_gpu_bench_groups() {
|
||||
match get_param_type() {
|
||||
ParamType::Classical | ParamType::ClassicalDocumentation => cuda_ks_pbs_group(),
|
||||
ParamType::MultiBit | ParamType::MultiBitDocumentation => cuda_multi_bit_ks_pbs_group(),
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
fn go_through_cpu_bench_groups(val: &str) {
|
||||
match val.to_lowercase().as_str() {
|
||||
"classical" => ks_pbs_group(),
|
||||
"multi_bit" => multi_bit_ks_pbs_group(),
|
||||
_ => panic!("unknown benchmark operations flavor"),
|
||||
fn go_through_cpu_bench_groups() {
|
||||
match get_param_type() {
|
||||
ParamType::Classical | ParamType::ClassicalDocumentation => ks_pbs_group(),
|
||||
ParamType::MultiBit | ParamType::MultiBitDocumentation => multi_bit_ks_pbs_group(),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match env::var("__TFHE_RS_PARAM_TYPE") {
|
||||
Ok(val) => {
|
||||
#[cfg(feature = "gpu")]
|
||||
go_through_gpu_bench_groups(&val);
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
go_through_cpu_bench_groups(&val);
|
||||
}
|
||||
Err(_) => {
|
||||
ks_pbs_group();
|
||||
multi_bit_ks_pbs_group()
|
||||
}
|
||||
};
|
||||
#[cfg(feature = "gpu")]
|
||||
go_through_gpu_bench_groups();
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
go_through_cpu_bench_groups();
|
||||
|
||||
Criterion::default().configure_from_args().final_summary();
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@ use benchmark::params::{
|
||||
multi_bit_benchmark_parameters_with_grouping, multi_bit_num_threads,
|
||||
};
|
||||
use benchmark::utilities::{
|
||||
get_bench_type, throughput_num_threads, write_to_json, BenchmarkType, CryptoParametersRecord,
|
||||
OperatorType,
|
||||
get_bench_type, get_param_type, throughput_num_threads, write_to_json, BenchmarkType,
|
||||
CryptoParametersRecord, OperatorType, ParamType,
|
||||
};
|
||||
use criterion::{black_box, Criterion, Throughput};
|
||||
use rayon::prelude::*;
|
||||
use serde::Serialize;
|
||||
use std::env;
|
||||
use tfhe::core_crypto::commons::math::ntt::ntt64::Ntt64;
|
||||
use tfhe::core_crypto::prelude::*;
|
||||
|
||||
@@ -1461,6 +1460,11 @@ pub fn pbs_group() {
|
||||
mem_optimized_batched_pbs(&mut criterion, &benchmark_parameters());
|
||||
}
|
||||
|
||||
pub fn pbs_group_documentation() {
|
||||
let mut criterion: Criterion<_> = (Criterion::default()).configure_from_args();
|
||||
mem_optimized_pbs(&mut criterion, &benchmark_parameters());
|
||||
}
|
||||
|
||||
pub fn multi_bit_pbs_group() {
|
||||
let mut criterion: Criterion<_> = (Criterion::default()).configure_from_args();
|
||||
multi_bit_pbs(
|
||||
@@ -1475,37 +1479,40 @@ pub fn multi_bit_pbs_group() {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn multi_bit_pbs_group_documentation() {
|
||||
let mut criterion: Criterion<_> = (Criterion::default()).configure_from_args();
|
||||
multi_bit_pbs(
|
||||
&mut criterion,
|
||||
&multi_bit_benchmark_parameters_with_grouping(),
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "gpu")]
|
||||
fn go_through_gpu_bench_groups(val: &str) {
|
||||
match val.to_lowercase().as_str() {
|
||||
"classical" => cuda_pbs_group(),
|
||||
"multi_bit" => cuda_multi_bit_pbs_group(),
|
||||
_ => panic!("unknown benchmark operations flavor"),
|
||||
fn go_through_gpu_bench_groups() {
|
||||
match get_param_type() {
|
||||
ParamType::Classical => cuda_pbs_group(),
|
||||
ParamType::ClassicalDocumentation => cuda_pbs_group(),
|
||||
ParamType::MultiBit => cuda_multi_bit_pbs_group(),
|
||||
ParamType::MultiBitDocumentation => cuda_multi_bit_pbs_group(),
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
fn go_through_cpu_bench_groups(val: &str) {
|
||||
match val.to_lowercase().as_str() {
|
||||
"classical" => pbs_group(),
|
||||
"multi_bit" => multi_bit_pbs_group(),
|
||||
_ => panic!("unknown benchmark operations flavor"),
|
||||
fn go_through_cpu_bench_groups() {
|
||||
match get_param_type() {
|
||||
ParamType::Classical => pbs_group(),
|
||||
ParamType::ClassicalDocumentation => pbs_group_documentation(),
|
||||
ParamType::MultiBit => multi_bit_pbs_group(),
|
||||
ParamType::MultiBitDocumentation => multi_bit_pbs_group_documentation(),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match env::var("__TFHE_RS_PARAM_TYPE") {
|
||||
Ok(val) => {
|
||||
#[cfg(feature = "gpu")]
|
||||
go_through_gpu_bench_groups(&val);
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
go_through_cpu_bench_groups(&val);
|
||||
}
|
||||
Err(_) => {
|
||||
pbs_group();
|
||||
multi_bit_pbs_group()
|
||||
}
|
||||
};
|
||||
#[cfg(feature = "gpu")]
|
||||
go_through_gpu_bench_groups();
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
go_through_cpu_bench_groups();
|
||||
|
||||
Criterion::default().configure_from_args().final_summary();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user