From ed84387bba9e6bba3bf64286b5e3228ff762242c Mon Sep 17 00:00:00 2001 From: pgardratzama Date: Mon, 29 Dec 2025 11:41:54 +0100 Subject: [PATCH] chore: trying to insure GPU ERC20 bench are not impacted while CPU & HPU uses if_then_zero --- .../benches/high_level_api/erc20.rs | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tfhe-benchmark/benches/high_level_api/erc20.rs b/tfhe-benchmark/benches/high_level_api/erc20.rs index 4d48ceeaf..94c225455 100644 --- a/tfhe-benchmark/benches/high_level_api/erc20.rs +++ b/tfhe-benchmark/benches/high_level_api/erc20.rs @@ -28,12 +28,22 @@ pub fn transfer_whitepaper( amount: &FheType, ) -> (FheType, FheType) where - FheType: Add + for<'a> FheOrd<&'a FheType>, - FheBool: IfThenZero, + FheType: Add + for<'a> FheOrd<&'a FheType> + FheTrivialEncrypt, + FheBool: IfThenZero + IfThenElse, for<'a> &'a FheType: Add + Sub, { let has_enough_funds = (from_amount).ge(amount); - let amount_to_transfer = has_enough_funds.if_then_zero(amount); + let amount_to_transfer = { + #[cfg(feature = "gpu")] + { + let zero_amount = FheType::encrypt_trivial(0u64); + has_enough_funds.select(amount, &zero_amount) + } + #[cfg(not(feature = "gpu"))] + { + has_enough_funds.if_then_zero(amount) + } + }; let new_to_amount = to_amount + &amount_to_transfer; let new_from_amount = from_amount - &amount_to_transfer; @@ -50,13 +60,21 @@ pub fn par_transfer_whitepaper( where FheType: Add + for<'a> FheOrd<&'a FheType> + Send + Sync + FheTrivialEncrypt, - FheBool: IfThenZero, + FheBool: IfThenZero + IfThenElse, for<'a> &'a FheType: Add + Sub, { let has_enough_funds = (from_amount).ge(amount); - //let zero_amount = FheType::encrypt_trivial(0u64); - //let amount_to_transfer = has_enough_funds.select(amount, &zero_amount); - let amount_to_transfer = has_enough_funds.if_then_zero(amount); + let amount_to_transfer = { + #[cfg(feature = "gpu")] + { + let zero_amount = FheType::encrypt_trivial(0u64); + has_enough_funds.select(amount, &zero_amount) + } + #[cfg(not(feature = "gpu"))] + { + has_enough_funds.if_then_zero(amount) + } + }; let (new_to_amount, new_from_amount) = rayon::join( || to_amount + &amount_to_transfer,