chore: trying to insure GPU ERC20 bench are not impacted while CPU & HPU uses if_then_zero

This commit is contained in:
pgardratzama
2025-12-29 11:41:54 +01:00
committed by Pierre Gardrat
parent 1f4ba33a50
commit ed84387bba

View File

@@ -28,12 +28,22 @@ pub fn transfer_whitepaper<FheType>(
amount: &FheType,
) -> (FheType, FheType)
where
FheType: Add<Output = FheType> + for<'a> FheOrd<&'a FheType>,
FheBool: IfThenZero<FheType>,
FheType: Add<Output = FheType> + for<'a> FheOrd<&'a FheType> + FheTrivialEncrypt<u64>,
FheBool: IfThenZero<FheType> + IfThenElse<FheType>,
for<'a> &'a FheType: Add<Output = FheType> + Sub<Output = FheType>,
{
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<FheType>(
where
FheType:
Add<Output = FheType> + for<'a> FheOrd<&'a FheType> + Send + Sync + FheTrivialEncrypt<u64>,
FheBool: IfThenZero<FheType>,
FheBool: IfThenZero<FheType> + IfThenElse<FheType>,
for<'a> &'a FheType: Add<Output = FheType> + Sub<Output = FheType>,
{
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,