diff --git a/Makefile b/Makefile index a9e9683e5..aa16402db 100644 --- a/Makefile +++ b/Makefile @@ -1527,6 +1527,14 @@ bench_hlapi_dex_gpu: install_rs_check_toolchain --bench hlapi-dex \ --features=integer,gpu,internal-keycache,pbs-stats,nightly-avx512 -p tfhe-benchmark -- +.PHONY: bench_hlapi_hpu # Run benchmarks for HLAPI operations on HPU +bench_hlapi_hpu: install_rs_check_toolchain + source ./setup_hpu.sh --config $(HPU_CONFIG) ; \ + RUSTFLAGS="$(RUSTFLAGS)" \ + cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ + --bench hlapi \ + --features=integer,internal-keycache,hpu,hpu-v80 -p tfhe-benchmark -- --quick + .PHONY: bench_hlapi_erc20_hpu # Run benchmarks for ECR20 operations on HPU bench_hlapi_erc20_hpu: install_rs_check_toolchain source ./setup_hpu.sh --config $(HPU_CONFIG) ; \ diff --git a/tfhe-benchmark/benches/high_level_api/bench.rs b/tfhe-benchmark/benches/high_level_api/bench.rs index 7799cf3e8..058a053a0 100644 --- a/tfhe-benchmark/benches/high_level_api/bench.rs +++ b/tfhe-benchmark/benches/high_level_api/bench.rs @@ -29,6 +29,7 @@ fn bench_fhe_type( + RotateRight<&'a FheType, Output = FheType> + OverflowingAdd<&'a FheType, Output = FheType> + OverflowingSub<&'a FheType, Output = FheType>, + for<'a> FheType: FheMin<&'a FheType, Output = FheType> + FheMax<&'a FheType, Output = FheType>, { let mut bench_group = c.benchmark_group(type_name); let bench_prefix = "hlapi::ops"; @@ -66,31 +67,25 @@ fn bench_fhe_type( }); write_record(bench_id, "add"); - #[cfg(not(feature = "hpu"))] - { - bench_id = format!("{bench_prefix}::overflowing_add::{param_name}::{bit_size}_bits"); - bench_group.bench_function(&bench_id, |b| { - b.iter(|| { - let (res, flag) = lhs.overflowing_add(&rhs); - res.wait(); - black_box((res, flag)) - }) - }); - write_record(bench_id, "overflowing_add"); - } + bench_id = format!("{bench_prefix}::overflowing_add::{param_name}::{bit_size}_bits"); + bench_group.bench_function(&bench_id, |b| { + b.iter(|| { + let (res, flag) = lhs.overflowing_add(&rhs); + res.wait(); + black_box((res, flag)) + }) + }); + write_record(bench_id, "overflowing_add"); - #[cfg(not(feature = "hpu"))] - { - bench_id = format!("{bench_prefix}::overflowing_sub::{param_name}::{bit_size}_bits"); - bench_group.bench_function(&bench_id, |b| { - b.iter(|| { - let (res, flag) = lhs.overflowing_sub(&rhs); - res.wait(); - black_box((res, flag)) - }) - }); - write_record(bench_id, "overflowing_sub"); - } + bench_id = format!("{bench_prefix}::overflowing_sub::{param_name}::{bit_size}_bits"); + bench_group.bench_function(&bench_id, |b| { + b.iter(|| { + let (res, flag) = lhs.overflowing_sub(&rhs); + res.wait(); + black_box((res, flag)) + }) + }); + write_record(bench_id, "overflowing_sub"); bench_id = format!("{bench_prefix}::sub::{param_name}::{bit_size}_bits"); bench_group.bench_function(&bench_id, |b| { @@ -142,48 +137,65 @@ fn bench_fhe_type( }); write_record(bench_id, "bitxor"); - #[cfg(not(feature = "hpu"))] - { - bench_id = format!("{bench_prefix}::left_shift::{param_name}::{bit_size}_bits"); - bench_group.bench_function(&bench_id, |b| { - b.iter(|| { - let res = &lhs << &rhs; - res.wait(); - black_box(res) - }) - }); - write_record(bench_id, "left_shift"); + bench_id = format!("{bench_prefix}::left_shift::{param_name}::{bit_size}_bits"); + bench_group.bench_function(&bench_id, |b| { + b.iter(|| { + let res = &lhs << &rhs; + res.wait(); + black_box(res) + }) + }); + write_record(bench_id, "left_shift"); - bench_id = format!("{bench_prefix}::right_shift::{param_name}::{bit_size}_bits"); - bench_group.bench_function(&bench_id, |b| { - b.iter(|| { - let res = &lhs >> &rhs; - res.wait(); - black_box(res) - }) - }); - write_record(bench_id, "right_shift"); + bench_id = format!("{bench_prefix}::right_shift::{param_name}::{bit_size}_bits"); + bench_group.bench_function(&bench_id, |b| { + b.iter(|| { + let res = &lhs >> &rhs; + res.wait(); + black_box(res) + }) + }); + write_record(bench_id, "right_shift"); - bench_id = format!("{bench_prefix}::left_rotate::{param_name}::{bit_size}_bits"); - bench_group.bench_function(&bench_id, |b| { - b.iter(|| { - let res = (&lhs).rotate_left(&rhs); - res.wait(); - black_box(res) - }) - }); - write_record(bench_id, "left_rotate"); + bench_id = format!("{bench_prefix}::left_rotate::{param_name}::{bit_size}_bits"); + bench_group.bench_function(&bench_id, |b| { + b.iter(|| { + let res = (&lhs).rotate_left(&rhs); + res.wait(); + black_box(res) + }) + }); + write_record(bench_id, "left_rotate"); - bench_id = format!("{bench_prefix}::right_rotate::{param_name}::{bit_size}_bits"); - bench_group.bench_function(&bench_id, |b| { - b.iter(|| { - let res = (&lhs).rotate_right(&rhs); - res.wait(); - black_box(res) - }) - }); - write_record(bench_id, "right_rotate"); - } + bench_id = format!("{bench_prefix}::right_rotate::{param_name}::{bit_size}_bits"); + bench_group.bench_function(&bench_id, |b| { + b.iter(|| { + let res = (&lhs).rotate_right(&rhs); + res.wait(); + black_box(res) + }) + }); + write_record(bench_id, "right_rotate"); + + bench_id = format!("{bench_prefix}::min::{param_name}::{bit_size}_bits"); + bench_group.bench_function(&bench_id, |b| { + b.iter(|| { + let res = lhs.min(&rhs); + res.wait(); + black_box(res) + }) + }); + write_record(bench_id, "min"); + + bench_id = format!("{bench_prefix}::max::{param_name}::{bit_size}_bits"); + bench_group.bench_function(&bench_id, |b| { + b.iter(|| { + let res = lhs.max(&rhs); + res.wait(); + black_box(res) + }) + }); + write_record(bench_id, "max"); } macro_rules! bench_type { diff --git a/tfhe-benchmark/benches/integer/bench.rs b/tfhe-benchmark/benches/integer/bench.rs index 63485a71e..fa2755246 100644 --- a/tfhe-benchmark/benches/integer/bench.rs +++ b/tfhe-benchmark/benches/integer/bench.rs @@ -3629,6 +3629,9 @@ fn go_through_hpu_bench_groups(val: &str) { hpu::default_hpu_bitwise(); hpu::default_hpu_cmp(); hpu::default_hpu_select(); + hpu::default_hpu_shiftrot(); + hpu::default_hpu_shiftrot_scalar(); + hpu::default_hpu_bitcnt(); } "fast_default" => { hpu::default_hpu_ops();