From e6625521ad78b56f8c2fb066c4e78d7b05da8846 Mon Sep 17 00:00:00 2001 From: Agnes Leroy Date: Tue, 2 Dec 2025 10:53:48 +0100 Subject: [PATCH] chore(gpu): add the possibility to run classical bench for erc20 and dex --- .github/workflows/benchmark_gpu.yml | 3 +-- Makefile | 18 ++++++++++++++++-- tfhe-benchmark/benches/high_level_api/dex.rs | 15 +++++++++++---- tfhe-benchmark/benches/high_level_api/erc20.rs | 13 ++++++++++--- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.github/workflows/benchmark_gpu.yml b/.github/workflows/benchmark_gpu.yml index 478edb3ff..8c5152ce7 100644 --- a/.github/workflows/benchmark_gpu.yml +++ b/.github/workflows/benchmark_gpu.yml @@ -21,10 +21,9 @@ on: command: description: "Benchmark command to run" type: choice - default: integer_multi_bit + default: integer options: - integer - - integer_multi_bit - integer_compression - pbs - pbs128 diff --git a/Makefile b/Makefile index d995f4c5b..b5c0d2980 100644 --- a/Makefile +++ b/Makefile @@ -1616,7 +1616,14 @@ bench_hlapi_erc20: install_rs_check_toolchain .PHONY: bench_hlapi_erc20_gpu # Run benchmarks for ERC20 operations on GPU bench_hlapi_erc20_gpu: install_rs_check_toolchain - RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ + RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) __TFHE_RS_PARAM_TYPE=$(BENCH_PARAM_TYPE) \ + cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ + --bench hlapi-erc20 \ + --features=integer,gpu,internal-keycache,pbs-stats -p tfhe-benchmark --profile release_lto_off -- + +.PHONY: bench_hlapi_erc20_gpu_classical # Run benchmarks for ERC20 operations on GPU with classical parameters +bench_hlapi_erc20_gpu_classical: install_rs_check_toolchain + RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) __TFHE_RS_PARAM_TYPE=classical \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench hlapi-erc20 \ --features=integer,gpu,internal-keycache,pbs-stats -p tfhe-benchmark --profile release_lto_off -- @@ -1630,7 +1637,14 @@ bench_hlapi_dex: install_rs_check_toolchain .PHONY: bench_hlapi_dex_gpu # Run benchmarks for DEX operations on GPU bench_hlapi_dex_gpu: install_rs_check_toolchain - RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ + RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) __TFHE_RS_PARAM_TYPE=$(BENCH_PARAM_TYPE) \ + cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ + --bench hlapi-dex \ + --features=integer,gpu,internal-keycache,pbs-stats -p tfhe-benchmark --profile release_lto_off -- + +.PHONY: bench_hlapi_dex_gpu_classical # Run benchmarks for DEX operations on GPU with classical parameters +bench_hlapi_dex_gpu_classical: install_rs_check_toolchain + RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) __TFHE_RS_PARAM_TYPE=$(BENCH_PARAM_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench hlapi-dex \ --features=integer,gpu,internal-keycache,pbs-stats -p tfhe-benchmark --profile release_lto_off -- diff --git a/tfhe-benchmark/benches/high_level_api/dex.rs b/tfhe-benchmark/benches/high_level_api/dex.rs index f802a38d7..0592e403e 100644 --- a/tfhe-benchmark/benches/high_level_api/dex.rs +++ b/tfhe-benchmark/benches/high_level_api/dex.rs @@ -1,9 +1,12 @@ -#[cfg(feature = "gpu")] -use benchmark::params_aliases::BENCH_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128; #[cfg(not(feature = "gpu"))] use benchmark::params_aliases::BENCH_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128; #[cfg(feature = "gpu")] -use benchmark::utilities::configure_gpu; +use benchmark::params_aliases::{ + BENCH_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, + BENCH_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, +}; +#[cfg(feature = "gpu")] +use benchmark::utilities::{configure_gpu, get_param_type, ParamType}; use benchmark::utilities::{get_bench_type, write_to_json, BenchmarkType, OperatorType}; use criterion::measurement::WallTime; use criterion::{BenchmarkGroup, Criterion, Throughput}; @@ -1434,9 +1437,13 @@ fn main() { #[cfg(feature = "gpu")] fn main() { - let params = BENCH_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128; + let params: tfhe::shortint::AtomicPatternParameters = match get_param_type() { + ParamType::Classical => BENCH_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into(), + _ => BENCH_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into(), + }; let config = ConfigBuilder::with_custom_parameters(params).build(); + let cks = ClientKey::generate(config); let mut c = Criterion::default().sample_size(10).configure_from_args(); diff --git a/tfhe-benchmark/benches/high_level_api/erc20.rs b/tfhe-benchmark/benches/high_level_api/erc20.rs index 04bd76016..90cc98153 100644 --- a/tfhe-benchmark/benches/high_level_api/erc20.rs +++ b/tfhe-benchmark/benches/high_level_api/erc20.rs @@ -1,5 +1,5 @@ #[cfg(feature = "gpu")] -use benchmark::utilities::configure_gpu; +use benchmark::utilities::{configure_gpu, get_param_type, ParamType}; use benchmark::utilities::{get_bench_type, write_to_json, BenchmarkType, OperatorType}; use criterion::measurement::WallTime; use criterion::{BenchmarkGroup, Criterion, Throughput}; @@ -864,10 +864,17 @@ fn main() { #[cfg(feature = "gpu")] fn main() { - let params = - benchmark::params_aliases::BENCH_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128; + let params: tfhe::shortint::AtomicPatternParameters = match get_param_type() { + ParamType::Classical => { + benchmark::params_aliases::BENCH_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into() + }, + _ => { + benchmark::params_aliases::BENCH_PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128.into() + } + }; let config = tfhe::ConfigBuilder::with_custom_parameters(params).build(); + let cks = ClientKey::generate(config); let mut c = Criterion::default().sample_size(10).configure_from_args();