Skip to content
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

C++ Wrapper #37

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

C++ Wrapper #37

wants to merge 7 commits into from

Conversation

nindanaoto
Copy link

I have implemented a C++ wrapper for my TFHE library, TFHEpp, using the cxx crate. This wrapper is based on the SPQLIOS API and supports CMake. While I recognize that adding a C++ wrapper might currently be outside the scope of this library, my intention with this PR is to provide a clear example, that can be easily reachable by just searching this repository, for users who wish to create their own C++ wrappers for TFHE libraries.

I understand that this PR might not be merged (even if the C++ wrapper has a higher value than I expected, I guess that the official API should be more plain), but if the maintainers see value in officially implementing a C++ wrapper into the library by seeing this PR, I'm happy with that.

Copy link

cla-bot bot commented Aug 16, 2024

Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @nindanaoto on file. In order for us to review and merge your code, please sign:

  • For individual contribution: our CLA
  • for Bounty submission, if you are an individual: our T&C
  • for Bounty submission, if you are a company: our T&C
    to get yourself added.

If you already signed one of this document, just wait to be added to the bot config.

@IceTDrinker
Copy link
Member

hello @nindanaoto thanks a lot for this PR, as I understand it, this is a C++ wrapper for concrete-fft for use in C++, could you share why you wrote the wrapper, and talk a bit about the desing of the wrapper ?

cheers

@nindanaoto
Copy link
Author

Thank you for your reply.

I created this C++ wrapper because it was difficult to determine whether this library is the fastest FFT library for TFHE, especially in comparison to SPQLIOS, without actually integrating it into TFHEpp. Additionally, this library appears to support 128-bit FFT, which could be valuable for integrating into TFHEpp to support larger security parameters. Given that OpenFHE and SEAL are also C++ libraries, I believe some users might want to use concrete-fft for their own C++ FHE libraries (or any other lattice related programs?) as well.

The wrapper is designed to allow this library to work as a drop-in replacement for SPQLIOS (as you may know, it is the orginal TFHE library's assembly FFT library). While the original SPQLIOS library does not include CMake compatibility, I have added it and using it over several years, so I also added that.

If you need further information, let me know.

@IceTDrinker
Copy link
Member

I’m curious about performance numbers you measured with this wrapper.

Copy link

cla-bot bot commented Aug 16, 2024

Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @nindanaoto on file. In order for us to review and merge your code, please sign:

  • For individual contribution: our CLA
  • for Bounty submission, if you are an individual: our T&C
  • for Bounty submission, if you are a company: our T&C
    to get yourself added.

If you already signed one of this document, just wait to be added to the bot config.

@nindanaoto
Copy link
Author

nindanaoto commented Aug 16, 2024

Here is the result on Ryzen 7950X3D running HomNAND with different FFTs.

Benchmarking HomNAND using different FFTs
Benchmarking SPQLIOS
1
Passed
7.846ms
Benchmarking concrete-fft
1
Passed
8.521ms
Benchmarking MKL
1
Passed
11.543ms
Benchmarking FFTW3
1
Passed
10.079ms

You can reproduce this with docker. I couldn't find a way to use AVX-512 with concrete-fft, so only AVX2 is used for SPQLIOS and concrete-fft. If you have configured your machine to allow executing docker without sudo, you can remove sudo in the command.
git clone --recursive https://github.com/virtualsecureplatform/TFHEpp.git && cd TFHEpp && sudo bash docker-fft-bench.bash

@IceTDrinker
Copy link
Member

You can use avx512 with the nightly feature and a nightly rust toolchain

Copy link

cla-bot bot commented Aug 18, 2024

Thank you for your pull request. We require contributors to sign our Contributor License Agreement / Terms and Conditions, and we don't seem to have the users @nindanaoto on file. In order for us to review and merge your code, please sign:

  • For individual contribution: our CLA
  • for Bounty submission, if you are an individual: our T&C
  • for Bounty submission, if you are a company: our T&C
    to get yourself added.

If you already signed one of this document, just wait to be added to the bot config.

@nindanaoto
Copy link
Author

I updated the repository to support AVX512 but seem to be not getting any performance improvement. I guess that this is coming from how AVX512 is implemented in ZEN4.
I also found some performance variations. I should have fixed the CPU core to remove the effect of 3D VCache existence......

Benchmarking HomNAND using different FFTs
Benchmarking SPQLIOS
1
Passed
8.063ms
Benchmarking SPQLIOS AVX512
1
Passed
8.048ms
Benchmarking concrete-fft
1
Passed
9.528ms
Benchmarking concrete-fft AVX512
1
Passed
9.659ms
Benchmarking MKL
1
Passed
10.735ms
Benchmarking FFTW3
1
Passed
7.686ms

@IceTDrinker
Copy link
Member

thanks I'm not sure we will take the C++ wrapper as we would have to maintain it and we don't have C++ needs around that FFT, it's cool to see you were able to use though !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants