Skip to content

chore(gpu): write swap bench #2301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged

chore(gpu): write swap bench #2301

merged 1 commit into from
May 5, 2025

Conversation

agnesLeroy
Copy link
Contributor

@agnesLeroy agnesLeroy commented Apr 30, 2025

closes: please link all relevant issues

PR content/description

This PR introduces a new HL API benchmark for the Swap operation, which is executed in the DEX contract.
There are 2 phases in a confidential swap: the request and the claim. Rand described the flow as:

  • user makes swap request by depositing tokens
  • the request is added to the current batch of swaps to do
  • contract decrypts the batch and updates liquidity in the pool
  • each user in the batch can claim their new tokens
    We technically only need to run in FHE the deposit and the claim, the rest is not FHE. We also don't care about having more than 1 user in a batch, so we can benchmark with only 1 deposit and 1 claim.

FHEVM implementation:

I have included a throughput benchmark for the request but maybe it's not necessary.
I have checked with JAT that the Rust implementation corresponds to what's done in Solidity. The claim requires executing 128-bit scalar mul & scalar division for contracts operating on 64-bit encrypted integers.

Check-list:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Relevant issues are marked as resolved/closed, related issues are linked in the description
  • Check for breaking changes (including serialization changes) and add them to commit message following the conventional commit specification

This change is Reviewable

@agnesLeroy agnesLeroy requested review from tmontaigu and soonum April 30, 2025 09:29
@cla-bot cla-bot bot added the cla-signed label Apr 30, 2025
Copy link
Contributor

@soonum soonum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 9 of 9 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @tmontaigu)


.github/workflows/benchmark_gpu_dex_weekly.yml line 7 at r1 (raw file):

  schedule:
    # Weekly benchmarks will be triggered each Saturday at 5a.m.
    - cron: '0 5 * * 6'

We are launching ERC20 benchmarks at the same moment, with the same type of instances. Could you delay this start by, let's say 2 hours ?


tfhe/benches/utilities.rs line 892 at r1 (raw file):

    #[cfg(feature = "integer")]
    pub use cuda_integer_utils::*;
    use tfhe::{set_server_key, ClientKey, CompressedServerKey};

This use should be at the top of the module I think, just for clarity.


tfhe/benches/high_level_api/dex.rs line 59 at r1 (raw file):

where
    FheType: Add<Output = FheType> + for<'a> FheOrd<&'a FheType> + Clone,
    FheBool: IfThenElse<FheType>,

I don't see any reference to FheBool type in this function is it normal?


tfhe/benches/high_level_api/dex.rs line 746 at r1 (raw file):

    }
}

There no throughput benchmarks for swap_claim ?

Copy link
Contributor Author

@agnesLeroy agnesLeroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @soonum and @tmontaigu)


.github/workflows/benchmark_gpu_dex_weekly.yml line 7 at r1 (raw file):

Previously, soonum (David Testé) wrote…

We are launching ERC20 benchmarks at the same moment, with the same type of instances. Could you delay this start by, let's say 2 hours ?

Done.


tfhe/benches/utilities.rs line 892 at r1 (raw file):

Previously, soonum (David Testé) wrote…

This use should be at the top of the module I think, just for clarity.

Done.


tfhe/benches/high_level_api/dex.rs line 59 at r1 (raw file):

Previously, soonum (David Testé) wrote…

I don't see any reference to FheBool type in this function is it normal?

FheBool is not a generic type it's needed to use the IfThenElse trait in this case, because we use select in the transfer.


tfhe/benches/high_level_api/dex.rs line 746 at r1 (raw file):

Previously, soonum (David Testé) wrote…

There no throughput benchmarks for swap_claim ?

I have not implemented it for now, actually I'm not even sure we need the throughput bench for the request I was hesitating to add it 🤔

@agnesLeroy agnesLeroy requested a review from soonum May 5, 2025 07:24
Copy link
Contributor

@soonum soonum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r2.
Reviewable status: all files reviewed (commit messages unreviewed), 2 unresolved discussions (waiting on @agnesLeroy and @tmontaigu)


tfhe/benches/high_level_api/dex.rs line 746 at r1 (raw file):

Previously, agnesLeroy (Agnès Leroy) wrote…

I have not implemented it for now, actually I'm not even sure we need the throughput bench for the request I was hesitating to add it 🤔

Should we go for less code then ? And add throughput benchmarks for both request and claim when they are needed ?

@agnesLeroy
Copy link
Contributor Author

tfhe/benches/high_level_api/dex.rs line 746 at r1 (raw file):

Previously, soonum (David Testé) wrote…

Should we go for less code then ? And add throughput benchmarks for both request and claim when they are needed ?

Ok let's do that, I'll remove it for now.

@agnesLeroy
Copy link
Contributor Author

tfhe/benches/high_level_api/dex.rs line 746 at r1 (raw file):

Previously, agnesLeroy (Agnès Leroy) wrote…

Ok let's do that, I'll remove it for now.

Done

@agnesLeroy agnesLeroy requested a review from soonum May 5, 2025 12:32
Copy link
Contributor

@soonum soonum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3.
Reviewable status: 8 of 9 files reviewed, all discussions resolved (waiting on @tmontaigu)

@agnesLeroy agnesLeroy merged commit 97690ab into main May 5, 2025
96 of 97 checks passed
@agnesLeroy agnesLeroy deleted the al/swap_bench branch May 5, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants