Skip to content

belfortlabs/hello-fpga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Belfort FHE Accelerator


Belfort FHE Accelerator

This repo provides demo applications implemented on TFHE-rs, and enables FPGA acceleration on it.

Check out the How to migrate your code for FPGA acceleration? section below to migrate your application. The following steps enable Belfort FPGA acceleration of your THFE-rs code:

// Import the Belfort dependency
use tfhe::integer::fpga::BelfortServerKey;

// Generates the FPGA key from server_key
let mut fpga_key = BelfortServerKey::from(&server_key);

// Connect to the FPGAs
fpga_key.connect();

// Accelerates operations with FPGA
set_server_key(fpga_key.clone());

// The rest of your code stays unchanged

⚠️ This is the early access version Belfort's Velox Accelerator. Contact us if you want access through our website.

How to run a demo?

In case you're looking for our AWS image, you can find the relevant instructions on the f2 branch.

Prepare execution environment

  1. SSH into the the Belfort FPGA server assigned to your use
ssh -i <ssh_key> <username>@<server_dns_name>
  1. Clone this repo into your home directory
git clone https://github.com/belfortlabs/hello-fpga.git
  1. Run the setup script
cd hello-fpga && ./scripts/prepare_env.sh

Run the weighted-sum tutorial

You can run both CPU and FPGA version of the application and compare the execution time differences;

cargo run --release --package example --bin weighted-sum
cargo run --release --package example --bin weighted-sum --features fpga

You should see the result of the weighted-sum complete much faster with the FPGA feature!

Other demos

This repository also contains more comprehensive demo applications. Below you can find the applications and the related commands. They should be run from the root repository and expects an initialized environment.

AES

AES demo implements the transciphering of AES into FHE. You can run the interactive demo with:

cargo run --release --package fhe-aes --bin demo --features fpga

Leuvenshtein

Leuvenshtein demo implements the fuzzy matching algorithm to compare two strings while allowing a limited amount of mistakes. You can run the interactive demo with:

cargo run --release --package leuvenshtein --bin demo --features fpga

Other Demos:

  • ERC20 demo is a terminal-based Rust demo that visualizes encrypted ERC20-like token transactions.
  • Trivium demo for the transciphering of trivium into FHE.

How to migrate your code for FPGA acceleration?

The acceleration requires a BelfortServerKey created from the server_key, which connects to the FPGA cores. You can find the weighted-sum example with the code differences for both CPU and FPGA execution below.

Change 5 lines of code:

The changes focus solely on key creation, which is standard for every TFHE application. The modifications are limited to using fpga_key as your server_key. All other computation code remains unchanged and will automatically benefit from FPGA acceleration.

/// Import dependencies                                         // Import dependencies
                                                          |     use tfhe::integer::fpga::BelfortServerKey;

/// Create Keys                                                 // Create Keys
let config = ConfigBuilder::default().build();                  let config = ConfigBuilder::default().build();
let client_key = ClientKey::generate(config);                   let client_key = ClientKey::generate(config);
let server_key = client_key.generate_server_key();              let server_key = client_key.generate_server_key();

                                                          |     let mut fpga_key = BelfortServerKey::from(&server_key);
                                                          |     fpga_key.connect();
set_server_key(server_key);                               |     set_server_key(fpga_key.clone());

// Compute on encrypted data                                    // Compute on encrypted data

                                                                // Disconnect from FPGA
                                                          |     fpga_key.disconnect();

Update your Cargo.toml:

  1. Change the tfhe dependency to use your local fpga-enabled tfhe-rs repo:
[dependencies]
tfhe = { path = "../../tfhe-rs/tfhe", features = [
    "shortint",
    "integer",
    "experimental-force_fft_algo_dif4",
] }
  1. Add the fpga feature to your application's Cargo.toml:
[features]
fpga = ["tfhe/fpga"]
emulate_fpga = ["tfhe/emulate_fpga"]

These are the only changes to your code to enable FPGA acceleration.

Specify FPGA cores

If you want to specify the number of FPGA cores to use, you can use the alternative connect_to() instead of the connect() function. This can be useful for development purposes or distributing access of the resources to multiple users.

let mut fpga_key = BelfortServerKey::from(&server_key);
fpga_key.connect_to(vec![0,1,2,3]); // Specifies connection to FPGA cores with indices 0,1,2 and 3
set_server_key(fpga_key);

Caveats

  • Lesser used operations are stubbed out with a software implementation. Our team is continuously replacing them with HW optimized versions.
  • Enabling the logger (as in env_logger::init(); in the tutorial) gives you runtime warnings if a non-accelerated function is used. Contact us if you would like priority support for a function that emits a warning.
  • Current implementations use FFT, but NTT support is under development.
  • Development for a specialized cloud environment with optimized performance is ongoing.
  • The FPGAs can also be emulated while running the demos (useful when hardware access is unavailable) by replacing:
    --features fpga
    with:
    --features "fpga,emulate_fpga"

Contributors

License

Belfort's AMI is free to use only for development, research, prototyping, and experimentation purposes. However, for any commercial use of Belfort's AMI, companies must purchase Belfort’s commercial AMI license.

This software is distributed under the BSD 3-Clause Clear license. Read the license for more details.

Each demo contributed by independent developers includes its own license file in the corresponding folder.

About

Belfort FPGA acceleration for TFHE-rs; for demo use on AWS

Resources

License

Stars

Watchers

Forks

Contributors