11#[ path = "../utilities.rs" ]
22mod utilities;
33
4- use crate :: utilities:: { write_to_json, CryptoParametersRecord , OperatorType } ;
5- use criterion:: { black_box, criterion_main, Criterion } ;
4+ use crate :: utilities:: {
5+ filter_parameters, init_parameters_set, write_to_json, CryptoParametersRecord , DesiredBackend ,
6+ DesiredNoiseDistribution , OperatorType , ParametersSet , PARAMETERS_SET ,
7+ } ;
8+ use criterion:: { black_box, Criterion } ;
69use serde:: Serialize ;
710use tfhe:: boolean:: prelude:: * ;
811use tfhe:: core_crypto:: prelude:: * ;
912use tfhe:: keycache:: NamedParam ;
1013use tfhe:: shortint:: parameters:: current_params:: {
1114 V1_0_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M128 ,
1215 V1_0_PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128 ,
13- V1_0_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128 ,
16+ V1_0_PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128 , VEC_ALL_MULTI_BIT_PBS_PARAMETERS ,
1417} ;
1518#[ cfg( not( feature = "gpu" ) ) ]
1619use tfhe:: shortint:: parameters:: current_params:: {
@@ -29,9 +32,11 @@ use tfhe::shortint::parameters::{
2932#[ cfg( feature = "gpu" ) ]
3033use tfhe:: shortint:: parameters:: {
3134 PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M64 ,
35+ PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_1_CARRY_1_KS_PBS_TUNIFORM_2M64 ,
3236 PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64 ,
3337 PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64 ,
3438 PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64 ,
39+ PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_TUNIFORM_2M64 ,
3540} ;
3641use tfhe:: shortint:: prelude:: * ;
3742use tfhe:: shortint:: { MultiBitPBSParameters , PBSParameters } ;
@@ -64,8 +69,10 @@ const SHORTINT_MULTI_BIT_BENCH_PARAMS: [MultiBitPBSParameters; 6] = [
6469] ;
6570
6671#[ cfg( feature = "gpu" ) ]
67- const SHORTINT_MULTI_BIT_BENCH_PARAMS : [ MultiBitPBSParameters ; 4 ] = [
72+ const SHORTINT_MULTI_BIT_BENCH_PARAMS : [ MultiBitPBSParameters ; 6 ] = [
73+ PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_1_CARRY_1_KS_PBS_TUNIFORM_2M64 ,
6874 PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64 ,
75+ PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_TUNIFORM_2M64 ,
6976 PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M64 ,
7077 PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64 ,
7178 PARAM_GPU_MULTI_BIT_GROUP_3_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64 ,
@@ -80,28 +87,78 @@ const BOOLEAN_BENCH_PARAMS: [(&str, BooleanParameters); 2] = [
8087] ;
8188
8289fn benchmark_parameters_64bits ( ) -> Vec < ( String , CryptoParametersRecord < u64 > ) > {
83- let classic = SHORTINT_BENCH_PARAMS
84- . iter ( )
85- . map ( |params| {
86- (
87- params. name ( ) ,
88- <ClassicPBSParameters as Into < PBSParameters > >:: into ( * params)
89- . to_owned ( )
90- . into ( ) ,
90+ let ( classic, multi_bit) = match PARAMETERS_SET . get ( ) . unwrap ( ) {
91+ ParametersSet :: Default => {
92+ let classic = SHORTINT_BENCH_PARAMS
93+ . iter ( )
94+ . map ( |params| {
95+ (
96+ params. name ( ) ,
97+ <ClassicPBSParameters as Into < PBSParameters > >:: into ( * params)
98+ . to_owned ( )
99+ . into ( ) ,
100+ )
101+ } )
102+ . collect :: < Vec < ( String , CryptoParametersRecord < u64 > ) > > ( ) ;
103+
104+ let multi_bit = SHORTINT_MULTI_BIT_BENCH_PARAMS
105+ . iter ( )
106+ . map ( |params| {
107+ (
108+ params. name ( ) ,
109+ <MultiBitPBSParameters as Into < PBSParameters > >:: into ( * params)
110+ . to_owned ( )
111+ . into ( ) ,
112+ )
113+ } )
114+ . collect ( ) ;
115+
116+ ( classic, multi_bit)
117+ }
118+ ParametersSet :: All => {
119+ let desired_noise = DesiredNoiseDistribution :: Both ;
120+ let desired_backend = if cfg ! ( feature = "gpu" ) {
121+ DesiredBackend :: Gpu
122+ } else {
123+ DesiredBackend :: Cpu
124+ } ;
125+
126+ let classic = filter_parameters (
127+ & VEC_ALL_CLASSIC_PBS_PARAMETERS ,
128+ desired_noise,
129+ DesiredBackend :: Cpu , // No parameters set are specific to GPU in this vector
91130 )
92- } )
93- . collect :: < Vec < ( String , CryptoParametersRecord < u64 > ) > > ( ) ;
94- let multi_bit = SHORTINT_MULTI_BIT_BENCH_PARAMS
95- . iter ( )
96- . map ( |params| {
97- (
98- params. name ( ) ,
99- <MultiBitPBSParameters as Into < PBSParameters > >:: into ( * params)
100- . to_owned ( )
101- . into ( ) ,
131+ . into_iter ( )
132+ . map ( |( params, name) | {
133+ (
134+ name. to_string ( ) ,
135+ <ClassicPBSParameters as Into < PBSParameters > >:: into ( * params)
136+ . to_owned ( )
137+ . into ( ) ,
138+ )
139+ } )
140+ . collect :: < Vec < ( String , CryptoParametersRecord < u64 > ) > > ( ) ;
141+
142+ let multi_bit = filter_parameters (
143+ & VEC_ALL_MULTI_BIT_PBS_PARAMETERS ,
144+ desired_noise,
145+ desired_backend,
102146 )
103- } )
104- . collect ( ) ;
147+ . into_iter ( )
148+ . map ( |( params, name) | {
149+ (
150+ name. to_string ( ) ,
151+ <MultiBitPBSParameters as Into < PBSParameters > >:: into ( * params)
152+ . to_owned ( )
153+ . into ( ) ,
154+ )
155+ } )
156+ . collect ( ) ;
157+
158+ ( classic, multi_bit)
159+ }
160+ } ;
161+
105162 [ classic, multi_bit] . concat ( )
106163}
107164
@@ -526,6 +583,7 @@ mod cuda {
526583
527584#[ cfg( feature = "gpu" ) ]
528585use cuda:: cuda_keyswitch_group;
586+ use tfhe:: shortint:: parameters:: v1_0:: VEC_ALL_CLASSIC_PBS_PARAMETERS ;
529587
530588pub fn keyswitch_group ( ) {
531589 let mut criterion: Criterion < _ > = ( Criterion :: default ( )
@@ -555,7 +613,24 @@ pub fn packing_keyswitch_group() {
555613 ) ;
556614}
557615
558- #[ cfg( not( feature = "gpu" ) ) ]
559- criterion_main ! ( keyswitch_group, packing_keyswitch_group) ;
560616#[ cfg( feature = "gpu" ) ]
561- criterion_main ! ( cuda_keyswitch_group) ;
617+ fn go_through_gpu_bench_groups ( ) {
618+ cuda_keyswitch_group ( ) ;
619+ }
620+
621+ #[ cfg( not( feature = "gpu" ) ) ]
622+ fn go_through_cpu_bench_groups ( ) {
623+ keyswitch_group ( ) ;
624+ packing_keyswitch_group ( ) ;
625+ }
626+
627+ fn main ( ) {
628+ init_parameters_set ( ) ;
629+
630+ #[ cfg( feature = "gpu" ) ]
631+ go_through_gpu_bench_groups ( ) ;
632+ #[ cfg( not( feature = "gpu" ) ) ]
633+ go_through_cpu_bench_groups ( ) ;
634+
635+ Criterion :: default ( ) . configure_from_args ( ) . final_summary ( ) ;
636+ }
0 commit comments