Skip to content

Commit 7789bed

Browse files
committed
feat(bench): fix find_optimal_batch to reduce bench time
1 parent aa1d7dc commit 7789bed

2 files changed

Lines changed: 41 additions & 24 deletions

File tree

tfhe-benchmark/benches/integer/bench.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,27 +3559,27 @@ criterion_group!(
35593559
mul_parallelized,
35603560
div_rem_parallelized,
35613561
bitand_parallelized,
3562-
bitnot,
3563-
left_shift_parallelized,
3564-
rotate_left_parallelized,
3565-
max_parallelized,
3566-
eq_parallelized,
3567-
gt_parallelized,
3568-
if_then_else_parallelized,
3569-
flip_parallelized,
3570-
neg_parallelized,
3571-
leading_zeros_parallelized,
3572-
ilog2_parallelized,
3573-
scalar_add_parallelized,
3574-
scalar_mul_parallelized,
3575-
scalar_div_parallelized,
3576-
scalar_rem_parallelized,
3577-
scalar_bitand_parallelized,
3578-
scalar_left_shift_parallelized,
3579-
scalar_rotate_left_parallelized,
3580-
scalar_max_parallelized,
3581-
scalar_eq_parallelized,
3582-
scalar_gt_parallelized,
3562+
// bitnot,
3563+
// left_shift_parallelized,
3564+
// rotate_left_parallelized,
3565+
// max_parallelized,
3566+
// eq_parallelized,
3567+
// gt_parallelized,
3568+
// if_then_else_parallelized,
3569+
// flip_parallelized,
3570+
// neg_parallelized,
3571+
// leading_zeros_parallelized,
3572+
// ilog2_parallelized,
3573+
// scalar_add_parallelized,
3574+
// scalar_mul_parallelized,
3575+
// scalar_div_parallelized,
3576+
// scalar_rem_parallelized,
3577+
// scalar_bitand_parallelized,
3578+
// scalar_left_shift_parallelized,
3579+
// scalar_rotate_left_parallelized,
3580+
// scalar_max_parallelized,
3581+
// scalar_eq_parallelized,
3582+
// scalar_gt_parallelized,
35833583
);
35843584

35853585
criterion_group!(

tfhe-benchmark/src/find_optimal_batch.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@ use std::time::{Duration, Instant};
44
struct MeasureConfig {
55
pub target_ratio: f64,
66
pub long_target_ratio: f64,
7+
pub min_improvement_ratio: f64,
78
pub starting_batch_size: usize,
89
pub minimum_time_per_batch: Duration,
910
pub duration_threshold_for_long_test: Duration,
11+
pub max_time_per_batch: Duration,
12+
pub max_time_overshoot_ratio: f64,
1013
}
1114

1215
impl MeasureConfig {
1316
pub fn default() -> Self {
1417
Self {
1518
target_ratio: 0.95,
1619
long_target_ratio: 0.80,
20+
min_improvement_ratio: 0.02,
1721
starting_batch_size: 1,
1822
minimum_time_per_batch: Duration::from_secs(3),
1923
duration_threshold_for_long_test: Duration::from_secs(30),
24+
max_time_per_batch: Duration::from_secs(200),
25+
max_time_overshoot_ratio: 1.3,
2026
}
2127
}
2228
}
@@ -63,7 +69,7 @@ where
6369
let target = cores * measure_config.target_ratio;
6470
let long_target = cores * measure_config.long_target_ratio;
6571

66-
let mut low;
72+
let mut low = measure_config.starting_batch_size;
6773
let mut high = measure_config.starting_batch_size;
6874
let mut last_usage = 0.0;
6975

@@ -86,12 +92,23 @@ where
8692
return high;
8793
}
8894

95+
if duration >= measure_config.max_time_per_batch {
96+
if duration
97+
<= measure_config
98+
.max_time_per_batch
99+
.mul_f64(measure_config.max_time_overshoot_ratio)
100+
{
101+
return high;
102+
}
103+
return low;
104+
}
105+
89106
let improvement = (usage - last_usage).abs() / last_usage;
90-
if improvement < 0.05
107+
if improvement < measure_config.min_improvement_ratio
91108
&& duration >= measure_config.duration_threshold_for_long_test
92109
&& last_usage > long_target
93110
{
94-
return high;
111+
return low;
95112
}
96113

97114
low = high;

0 commit comments

Comments
 (0)