mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-07 22:04:10 -05:00
chore: trying to insure GPU ERC20 bench are not impacted while CPU & HPU uses if_then_zero
This commit is contained in:
committed by
Pierre Gardrat
parent
1f4ba33a50
commit
ed84387bba
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user