Skip to content

Commit

Permalink
chore(tfhe): add forward compatibility with 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
IceTDrinker committed Apr 22, 2024
1 parent 0a30749 commit 1403663
Show file tree
Hide file tree
Showing 109 changed files with 6,090 additions and 49 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/aws_tfhe_fast_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ on:
description: "Action runner name"
type: string
request_id:
description: 'Slab request ID'
description: "Slab request ID"
type: string
fork_repo:
description: 'Name of forked repo as user/repo'
description: "Name of forked repo as user/repo"
type: string
fork_git_sha:
description: 'Git SHA to checkout from fork'
description: "Git SHA to checkout from fork"
type: string

jobs:
Expand Down Expand Up @@ -115,6 +115,10 @@ jobs:
run: |
make test_safe_deserialization
- name: Run forward compatibility tests
run: |
make test_forward_compatibility
- name: Slack Notification
if: ${{ always() }}
continue-on-error: true
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/aws_tfhe_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ on:
description: "Action runner name"
type: string
request_id:
description: 'Slab request ID'
description: "Slab request ID"
type: string
fork_repo:
description: 'Name of forked repo as user/repo'
description: "Name of forked repo as user/repo"
type: string
fork_git_sha:
description: 'Git SHA to checkout from fork'
description: "Git SHA to checkout from fork"
type: string

jobs:
Expand Down Expand Up @@ -82,6 +82,10 @@ jobs:
run: |
make test_c_api
- name: Run C API tests with forward_compatibility
run: |
FORWARD_COMPAT=ON make test_c_api
- name: Run user docs tests
run: |
make test_user_doc
Expand Down
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,17 @@ clippy_trivium: install_rs_check_toolchain
-p tfhe-trivium -- --no-deps -D warnings

.PHONY: clippy_all_targets # Run clippy lints on all targets (benches, examples, etc.)
clippy_all_targets:
clippy_all_targets: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache \
-p $(TFHE_SPEC) -- --no-deps -D warnings

.PHONY: clippy_all_targets_forward_compatibility # Run clippy lints on all targets (benches, examples, etc.)
clippy_all_targets_forward_compatibility: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,forward_compatibility \
-p $(TFHE_SPEC) -- --no-deps -D warnings

.PHONY: clippy_concrete_csprng # Run clippy lints on concrete-csprng
clippy_concrete_csprng:
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
Expand All @@ -246,7 +252,8 @@ clippy_concrete_csprng:

.PHONY: clippy_all # Run all clippy targets
clippy_all: clippy clippy_boolean clippy_shortint clippy_integer clippy_all_targets clippy_c_api \
clippy_js_wasm_api clippy_tasks clippy_core clippy_concrete_csprng clippy_trivium
clippy_js_wasm_api clippy_tasks clippy_core clippy_concrete_csprng clippy_trivium \
clippy_all_targets_forward_compatibility

.PHONY: clippy_fast # Run main clippy targets
clippy_fast: clippy clippy_all_targets clippy_c_api clippy_js_wasm_api clippy_tasks clippy_core \
Expand Down Expand Up @@ -314,7 +321,6 @@ build_c_api_gpu: install_rs_check_toolchain
build_c_api_experimental_deterministic_fft: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api,experimental-force_fft_algo_dif4,$(FORWARD_COMPAT_FEATURE) \
-p $(TFHE_SPEC)
@"$(MAKE)" symlink_c_libs_without_fingerprint

.PHONY: build_web_js_api # Build the js API targeting the web browser
Expand Down Expand Up @@ -408,7 +414,7 @@ test_c_api_rs: install_rs_check_toolchain

.PHONY: test_c_api_c # Run the C tests for the C API
test_c_api_c: build_c_api
./scripts/c_api_tests.sh
./scripts/c_api_tests.sh --forward-compat "$(FORWARD_COMPAT)"

.PHONY: test_c_api # Run all the tests for the C API
test_c_api: test_c_api_rs test_c_api_c
Expand Down Expand Up @@ -508,6 +514,12 @@ test_high_level_api: install_rs_build_toolchain
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p $(TFHE_SPEC) \
-- high_level_api::

.PHONY: test_forward_compatibility # Run forward compatibility tests
test_forward_compatibility: install_rs_build_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --tests --profile $(CARGO_PROFILE) \
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,forward_compatibility,internal-keycache -p $(TFHE_SPEC) \
-- forward_compatibility::

.PHONY: test_user_doc # Run tests from the .md documentation
test_user_doc: install_rs_build_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) --doc \
Expand Down Expand Up @@ -585,7 +597,9 @@ check_compile_tests:

@if [[ "$(OS)" == "Linux" || "$(OS)" == "Darwin" ]]; then \
"$(MAKE)" build_c_api && \
./scripts/c_api_tests.sh --build-only; \
./scripts/c_api_tests.sh --build-only --forward-compat "$(FORWARD_COMPAT)" && \
FORWARD_COMPAT=ON "$(MAKE)" build_c_api && \
./scripts/c_api_tests.sh --build-only --forward-compat "$(FORWARD_COMPAT)"; \
fi

.PHONY: build_nodejs_test_docker # Build a docker image with tools to run nodejs tests for wasm API
Expand Down
2 changes: 1 addition & 1 deletion apps/trivium/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ use tfhe::prelude::*;
use tfhe_trivium::TriviumStreamShortint;

fn test_shortint() {
let config = ConfigBuilder::all_disabled().enable_default_integers().build();
let config = ConfigBuilder::default().build();
let (hl_client_key, hl_server_key) = generate_keys(config);
let (client_key, server_key): (ClientKey, ServerKey) = gen_keys(PARAM_MESSAGE_1_CARRY_1_KS_PBS);
let ksk = CastingKey::new((&client_key, &server_key), (&hl_client_key, &hl_server_key));
Expand Down
13 changes: 12 additions & 1 deletion scripts/c_api_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ function usage() {
echo "--help Print this message"
echo "--build-only Pass to only build the tests without running them"
echo "--gpu Enable GPU support"
echo "--forward-compat Indicate if we have forward compatibility enabled"
echo
}

BUILD_ONLY=0
WITH_FEATURE_GPU="OFF"
WITH_FORWARD_COMPAT="OFF"

while [ -n "$1" ]
do
case "$1" in
Expand All @@ -28,6 +31,12 @@ do
"--gpu" )
WITH_FEATURE_GPU="ON"
;;

"--forward-compat" )
shift
WITH_FORWARD_COMPAT="$1"
;;

*)
echo "Unknown param : $1"
exit 1
Expand All @@ -44,7 +53,9 @@ mkdir -p "${TFHE_BUILD_DIR}"

cd "${TFHE_BUILD_DIR}"

cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCARGO_PROFILE="${CARGO_PROFILE}" -DWITH_FEATURE_GPU="${WITH_FEATURE_GPU}"
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCARGO_PROFILE="${CARGO_PROFILE}" \
-DWITH_FEATURE_GPU="${WITH_FEATURE_GPU}" \
-DWITH_FORWARD_COMPATIBILITY="${WITH_FORWARD_COMPAT}"

make -j

Expand Down
60 changes: 43 additions & 17 deletions tfhe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tfhe"
version = "0.5.3"
version = "0.5.4"
edition = "2021"
readme = "../README.md"
keywords = ["fully", "homomorphic", "encryption", "fhe", "cryptography"]
Expand Down Expand Up @@ -46,7 +46,7 @@ hex = "0.4.3"
# End regex-engine deps

[build-dependencies]
cbindgen = { version = "0.26.0", optional = true }
cbindgen = { package = "tfhe-c-api-bindgen", version = "0.26.1", optional = true }

[dependencies]
concrete-csprng = { version = "0.4.0", path = "../concrete-csprng", features = [
Expand All @@ -69,6 +69,7 @@ paste = "1.0.7"
fs2 = { version = "0.4.3", optional = true }
# While we wait for repeat_n in rust standard library
itertools = "0.11.0"
next_tfhe = { package = "tfhe", version = "0.6.1", optional = true }

# wasm deps
wasm-bindgen = { version = "0.2.86", features = [
Expand All @@ -82,18 +83,30 @@ getrandom = { version = "0.2.8", optional = true }
bytemuck = "1.14.3"

[features]
boolean = []
shortint = []
integer = ["shortint"]
internal-keycache = ["dep:lazy_static", "dep:fs2"]
forward_compatibility = ["dep:tfhe-c-api-dynamic-buffer", "dep:next_tfhe"]

boolean = ["next_tfhe?/boolean"]
shortint = ["next_tfhe?/shortint"]
integer = ["shortint", "next_tfhe?/integer"]
internal-keycache = [
"dep:lazy_static",
"dep:fs2",
"next_tfhe?/internal-keycache",
]
gpu = ["tfhe-cuda-backend"]

# Experimental section
experimental = []
experimental-force_fft_algo_dif4 = []
experimental-force_fft_algo_dif4 = [
"next_tfhe?/experimental-force_fft_algo_dif4",
]
# End experimental section

__c_api = ["dep:cbindgen", "dep:tfhe-c-api-dynamic-buffer"]
__c_api = [
"dep:cbindgen",
"dep:tfhe-c-api-dynamic-buffer",
"next_tfhe?/__force_skip_cbindgen",
]
# For the semver trick to skip the build.rs
__force_skip_cbindgen = []
boolean-c-api = ["boolean", "__c_api"]
Expand All @@ -114,32 +127,45 @@ integer-client-js-wasm-api = ["integer", "__wasm_api"]
high-level-client-js-wasm-api = ["boolean", "shortint", "integer", "__wasm_api"]
parallel-wasm-api = ["dep:wasm-bindgen-rayon"]

nightly-avx512 = ["concrete-fft/nightly", "pulp/nightly"]
nightly-avx512 = [
"concrete-fft/nightly",
"pulp/nightly",
"next_tfhe?/nightly-avx512",
]

# Enable the x86_64 specific accelerated implementation of the random generator for the default
# backend
generator_x86_64_aesni = ["concrete-csprng/generator_x86_64_aesni"]
generator_x86_64_aesni = [
"concrete-csprng/generator_x86_64_aesni",
"next_tfhe?/generator_x86_64_aesni",
]

# Enable the aarch64 specific accelerated implementation of the random generator for the default
# backend
generator_aarch64_aes = ["concrete-csprng/generator_aarch64_aes"]
generator_aarch64_aes = [
"concrete-csprng/generator_aarch64_aes",
"next_tfhe?/generator_aarch64_aes",
]

# Private features
__profiling = []
__coverage = []

seeder_unix = ["concrete-csprng/seeder_unix"]
seeder_x86_64_rdseed = ["concrete-csprng/seeder_x86_64_rdseed"]
seeder_unix = ["concrete-csprng/seeder_unix", "next_tfhe?/seeder_unix"]
seeder_x86_64_rdseed = [
"concrete-csprng/seeder_x86_64_rdseed",
"next_tfhe?/seeder_x86_64_rdseed",
]

# These target_arch features enable a set of public features for tfhe if users want a known
# good/working configuration for tfhe.
# For a target_arch that does not yet have such a feature, one can still enable features manually or
# create a feature for said target_arch to make its use simpler.
x86_64 = ["generator_x86_64_aesni", "seeder_x86_64_rdseed"]
x86_64-unix = ["x86_64", "seeder_unix"]
x86_64 = ["generator_x86_64_aesni", "seeder_x86_64_rdseed", "next_tfhe?/x86_64"]
x86_64-unix = ["x86_64", "seeder_unix", "next_tfhe?/x86_64-unix"]

aarch64 = ["generator_aarch64_aes"]
aarch64-unix = ["aarch64", "seeder_unix"]
aarch64 = ["generator_aarch64_aes", "next_tfhe?/aarch64"]
aarch64-unix = ["aarch64", "seeder_unix", "next_tfhe?/aarch64-unix"]

[package.metadata.docs.rs]
# TODO: manage builds for docs.rs based on their documentation https://docs.rs/about
Expand Down
14 changes: 9 additions & 5 deletions tfhe/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ fn gen_c_api() {
"integer",
#[cfg(feature = "gpu")]
"gpu",
#[cfg(feature = "forward_compatibility")]
"forward_compatibility",
];

let parse_expand_vec = if parse_expand_features_vec.is_empty() {
Expand All @@ -65,14 +67,16 @@ fn gen_c_api() {
vec![package_name.as_str()]
};

cbindgen::Builder::new()
let builder = cbindgen::Builder::new()
.with_crate(crate_dir.as_path())
.with_config(cbindgen::Config::from_file(crate_dir.join("cbindgen.toml")).unwrap())
.with_parse_expand(&parse_expand_vec)
.with_parse_expand_features(&parse_expand_features_vec)
.generate()
.unwrap()
.write_to_file(output_file);
.with_parse_expand_features(&parse_expand_features_vec);

#[cfg(feature = "forward_compatibility")]
let builder = builder.with_include("tfhe-c-api-dynamic-buffer.h");

builder.generate().unwrap().write_to_file(output_file);
}

fn main() {
Expand Down
5 changes: 5 additions & 0 deletions tfhe/c_api_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ endif()
set(TFHE_C_API_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${CARGO_PROFILE}")

option(WITH_FEATURE_GPU "Enable if tfhe-rs C API was compiled with the 'gpu' feature activated" OFF)
option(WITH_FORWARD_COMPATIBILITY "Enable if tfhe-rs C API was compiled with the 'forward_compatibility' feature activated" OFF)

include_directories(${TFHE_C_API_RELEASE})
# This one is to fetch the dynamic buffer header
Expand All @@ -29,6 +30,10 @@ if (WITH_FEATURE_GPU)
find_package(OpenMP REQUIRED)
endif()

if("${WITH_FORWARD_COMPATIBILITY}" STREQUAL "ON")
add_definitions(-DWITH_FORWARD_COMPATIBILITY)
endif()

file(GLOB TEST_CASES test_*.c)
foreach (testsourcefile ${TEST_CASES})
get_filename_component(testname ${testsourcefile} NAME_WLE)
Expand Down
Loading

0 comments on commit 1403663

Please sign in to comment.