Skip to content

Commit

Permalink
chore(tfhe)!: remove arch specific features
Browse files Browse the repository at this point in the history
BREAKING_CHANGE:
-	The x86_64, x86_64-unix, aarch64, aarch64-unix have been removed, the target
architecture and os family are now automatically detected. A `software_prng`
feature has been added to force the use of a software implementation on older
CPUs
  • Loading branch information
nsarlin-zama committed Dec 10, 2024
1 parent 3b22760 commit 2cd7df1
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 266 deletions.
210 changes: 101 additions & 109 deletions Makefile

Large diffs are not rendered by default.

16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,8 @@ production-ready library for all the advanced features of TFHE.
### Cargo.toml configuration
To use the latest version of `TFHE-rs` in your project, you first need to add it as a dependency in your `Cargo.toml`:

+ For x86_64-based machines running Unix-like OSes:

```toml
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64-unix"] }
```

+ For Apple Silicon or aarch64-based machines running Unix-like OSes:

```toml
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "aarch64-unix"] }
```

+ For x86_64-based machines with the [`rdseed instruction`](https://en.wikipedia.org/wiki/RDRAND) running Windows:

```toml
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64"] }
tfhe = { version = "*", features = ["boolean", "shortint", "integer"] }
```

> [!Note]
Expand Down
9 changes: 1 addition & 8 deletions apps/trivium/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ edition = "2021"

[dependencies]
rayon = { version = "1.7.0"}

[target.'cfg(target_arch = "x86_64")'.dependencies.tfhe]
path = "../../tfhe"
features = [ "boolean", "shortint", "integer", "x86_64" ]

[target.'cfg(target_arch = "aarch64")'.dependencies.tfhe]
path = "../../tfhe"
features = [ "boolean", "shortint", "integer", "aarch64-unix" ]
tfhe = { path = "../../tfhe", features = [ "boolean", "shortint", "integer" ] }

[dev-dependencies]
criterion = { version = "0.5.1", features = [ "html_reports" ]}
Expand Down
19 changes: 0 additions & 19 deletions scripts/get_arch_feature.sh

This file was deleted.

5 changes: 2 additions & 3 deletions scripts/integer-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ if [[ "${backend}" == "gpu" ]]; then
fi

CURR_DIR="$(dirname "$0")"
ARCH_FEATURE="$("${CURR_DIR}/get_arch_feature.sh")"

# TODO autodetect/have a finer CPU count depending on memory
num_cpu_threads="$("${CURR_DIR}"/cpu_count.sh)"
Expand Down Expand Up @@ -155,15 +154,15 @@ cargo "${RUST_TOOLCHAIN}" nextest run \
--cargo-profile "${cargo_profile}" \
--package "${tfhe_package}" \
--profile ci \
--features="${ARCH_FEATURE}",integer,internal-keycache,zk-pok,experimental,"${avx512_feature}","${gpu_feature}" \
--features=integer,internal-keycache,zk-pok,experimental,"${avx512_feature}","${gpu_feature}" \
--test-threads "${test_threads}" \
-E "$filter_expression"

if [[ -z ${multi_bit_argument} ]]; then
cargo "${RUST_TOOLCHAIN}" test \
--profile "${cargo_profile}" \
--package "${tfhe_package}" \
--features="${ARCH_FEATURE}",integer,internal-keycache,experimental,"${avx512_feature}","${gpu_feature}" \
--features=integer,internal-keycache,experimental,"${avx512_feature}","${gpu_feature}" \
--doc \
-- --test-threads="${doctest_threads}" integer::"${gpu_feature}"
fi
Expand Down
11 changes: 5 additions & 6 deletions scripts/shortint-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ if [[ "${FAST_TESTS}" == TRUE ]]; then
fi

CURR_DIR="$(dirname "$0")"
ARCH_FEATURE="$("${CURR_DIR}/get_arch_feature.sh")"

n_threads_small="$("${CURR_DIR}"/cpu_count.sh)"
n_threads_big="${n_threads_small}"
Expand Down Expand Up @@ -94,7 +93,7 @@ if [[ "${BIG_TESTS_INSTANCE}" != TRUE ]]; then
--cargo-profile "${cargo_profile}" \
--package "${tfhe_package}" \
--profile ci \
--features="${ARCH_FEATURE}",shortint,internal-keycache,zk-pok,experimental \
--features=shortint,internal-keycache,zk-pok,experimental \
--test-threads "${n_threads_small}" \
-E "${filter_expression_small_params}"

Expand All @@ -111,7 +110,7 @@ and not test(~smart_add_and_mul)"""
--cargo-profile "${cargo_profile}" \
--package "${tfhe_package}" \
--profile ci \
--features="${ARCH_FEATURE}",shortint,internal-keycache,zk-pok,experimental \
--features=shortint,internal-keycache,zk-pok,experimental \
--test-threads "${n_threads_big}" \
--no-tests=warn \
-E "${filter_expression_big_params}"
Expand All @@ -120,7 +119,7 @@ and not test(~smart_add_and_mul)"""
cargo "${RUST_TOOLCHAIN}" test \
--profile "${cargo_profile}" \
--package "${tfhe_package}" \
--features="${ARCH_FEATURE}",shortint,internal-keycache,zk-pok,experimental \
--features=shortint,internal-keycache,zk-pok,experimental \
--doc \
-- shortint::
fi
Expand All @@ -134,15 +133,15 @@ else
--cargo-profile "${cargo_profile}" \
--package "${tfhe_package}" \
--profile ci \
--features="${ARCH_FEATURE}",shortint,internal-keycache,experimental \
--features=shortint,internal-keycache,experimental \
--test-threads "${n_threads_big}" \
-E "${filter_expression}"

if [[ "${multi_bit}" == "" ]]; then
cargo "${RUST_TOOLCHAIN}" test \
--profile "${cargo_profile}" \
--package "${tfhe_package}" \
--features="${ARCH_FEATURE}",shortint,internal-keycache,experimental \
--features=shortint,internal-keycache,experimental \
--doc \
-- --test-threads="${n_threads_big}" shortint::
fi
Expand Down
7 changes: 0 additions & 7 deletions tfhe-csprng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ clap = "=4.4.4"

[features]
parallel = ["rayon"]
generator_fallback = []

x86_64 = ["parallel", "generator_fallback"]
x86_64-unix = ["x86_64"]
aarch64 = ["parallel", "generator_fallback"]
aarch64-unix = ["aarch64"]
software_prng = []

[[bench]]
Expand All @@ -41,4 +35,3 @@ harness = false
[[example]]
name = "generate"
path = "examples/generate.rs"
required-features = ["generator_fallback"]
17 changes: 3 additions & 14 deletions tfhe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ tfhe-backward-compat-data = { git = "https://github.com/zama-ai/tfhe-backward-co
cbindgen = { version = "0.26.0", optional = true }

[dependencies]
tfhe-csprng = { version = "0.4.1", path = "../tfhe-csprng", features = [
"generator_fallback",
"parallel",
] }
tfhe-csprng = { version = "0.4.1", path = "../tfhe-csprng", features = ["parallel", "software_prng"] }
lazy_static = { version = "1.4.0", optional = true }
serde = { workspace = true, features = ["default", "derive"] }
rayon = { version = "1.5.0" }
Expand Down Expand Up @@ -136,19 +133,11 @@ nightly-avx512 = ["tfhe-fft/nightly", "tfhe-ntt/nightly", "pulp/nightly"]
__profiling = []
__long_run_tests = []

# 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 = []
x86_64-unix = ["x86_64"]

aarch64 = []
aarch64-unix = ["aarch64"]
software_prng = []

[package.metadata.docs.rs]
# TODO: manage builds for docs.rs based on their documentation https://docs.rs/about
features = ["x86_64-unix", "boolean", "shortint", "integer", "gpu", "zk-pok"]
features = ["boolean", "shortint", "integer", "gpu", "zk-pok", "software_prng"]
rustdoc-args = ["--html-in-header", "katex-header.html"]

###########
Expand Down
2 changes: 1 addition & 1 deletion tfhe/docs/fundamentals/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ In the following example, we use [bincode](https://crates.io/crates/bincode) for

[dependencies]
# ...
tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] }
tfhe = { version = "0.10.0", features = ["integer"] }
bincode = "1.3.3"
```

Expand Down
36 changes: 16 additions & 20 deletions tfhe/docs/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,8 @@ This document provides instructions to set up **TFHE-rs** in your project.

First, add **TFHE-rs** as a dependency in your `Cargo.toml`.

**For `x86_64` machine running a Unix-like OS:**

```toml
tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "x86_64-unix"] }
```

**For `ARM` machine running a Unix-like OS:**

```toml
tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "aarch64-unix"] }
```

**For `x86_64` machines with the** [**`rdseed instruction`**](https://en.wikipedia.org/wiki/RDRAND) **running Windows:**

```toml
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64"] }
tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer"] }
```

{% hint style="info" %}
Expand All @@ -36,8 +22,18 @@ tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64"]

**TFHE-rs** currently supports the following platforms:

| OS | x86 | aarch64 |
| ------- | ---------------------------------- | ---------------- |
| Linux | `x86_64-unix` | `aarch64-unix`\* |
| macOS | `x86_64-unix` | `aarch64-unix`\* |
| Windows | `x86_64` with `RDSEED` instruction | Unsupported |
| OS | x86_64 | aarch64 |
|---------|-------------------------------------|-------------|
| Linux | Supported | Supported\* |
| macOS | Supported | Supported\* |
| Windows | Supported with `RDSEED` instruction | Unsupported |

By default, **TFHE-rs** makes the assumption that hardware AES features are enabled on the target CPU. The required CPU features are:
- x86_64: sse2, aesni
- aarch64: aes, neon

To add support for older CPU, import **TFHE-rs** with the `software_prng` feature in your `Cargo.toml`:

```toml
tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "software_prng"] }
``
6 changes: 3 additions & 3 deletions tfhe/docs/getting_started/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ edition = "2021"
[dependencies]
```

For x86 Unix systems, add the following configuration to include **TFHE-rs**:
Then add the following configuration to include **TFHE-rs**:

```toml
tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] }
tfhe = { version = "0.10.0", features = ["integer"] }
```

Your updated `Cargo.toml` file should look like this:
Expand All @@ -71,7 +71,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] }
tfhe = { version = "0.10.0", features = ["integer"] }
```

If you are on a different platform please refer to the [installation documentation](installation.md) for configuration options of other supported platforms.
Expand Down
2 changes: 1 addition & 1 deletion tfhe/docs/guides/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The following example shows a complete workflow of working with encrypted arrays
# Cargo.toml

[dependencies]
tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] }
tfhe = { version = "0.10.0", features = ["integer"] }
```

```rust
Expand Down
10 changes: 2 additions & 8 deletions tfhe/docs/guides/c_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ This document describes the C bindings to the **TFHE-rs** high-level primitives

## Setting up TFHE-rs C API for C programming.

You can build **TFHE-rs** C API on a Unix x86\_64 machine using the following command:
You can build **TFHE-rs** C API using the following command:

```shell
RUSTFLAGS="-C target-cpu=native" cargo +nightly build --release --features=x86_64-unix,high-level-c-api -p tfhe && make symlink_c_libs_without_fingerprint
```

For a Unix aarch64 machine, use the following command:

```shell
RUSTFLAGS="-C target-cpu=native" cargo +nightly build --release --features=aarch64-unix,high-level-c-api -p tfhe && make symlink_c_libs_without_fingerprint
RUSTFLAGS="-C target-cpu=native" cargo +nightly build --release --features=high-level-c-api -p tfhe && make symlink_c_libs_without_fingerprint
```

Locate files in the right path:
Expand Down
2 changes: 1 addition & 1 deletion tfhe/docs/guides/data_versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can load serialized data with the `unversionize` function, even in newer ver

[dependencies]
# ...
tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] }
tfhe = { version = "0.10.0", features = ["integer"] }
tfhe-versionable = "0.2.0"
bincode = "1.3.3"
```
Expand Down
19 changes: 6 additions & 13 deletions tfhe/docs/guides/run_on_gpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ This guide explains how to update your existing program to leverage GPU accelera

To use the **TFHE-rs** GPU backend in your project, add the following dependency in your `Cargo.toml`.

If you are using an `x86` machine:

```toml
tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "x86_64-unix", "gpu"] }
```

If you are using an `ARM` machine:

```toml
tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "aarch64-unix", "gpu"] }
tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "gpu"] }
```

{% hint style="success" %}
Expand All @@ -37,11 +30,11 @@ For optimal performance when using **TFHE-rs**, run your code in release mode wi

**TFHE-rs** GPU backend is supported on Linux (x86, aarch64).

| OS | x86 | aarch64 |
| ------- | ------------- | ---------------- |
| Linux | `x86_64-unix` | `aarch64-unix`\* |
| macOS | Unsupported | Unsupported\* |
| Windows | Unsupported | Unsupported |
| OS | x86 | aarch64 |
|---------|-------------|---------------|
| Linux | Supported | Supported\* |
| macOS | Unsupported | Unsupported\* |
| Windows | Unsupported | Unsupported |

## A first example

Expand Down
24 changes: 1 addition & 23 deletions tfhe/docs/references/core-crypto-api/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,7 @@ Welcome to this tutorial about `TFHE-rs` `core_crypto` module.
To use `TFHE-rs`, it first has to be added as a dependency in the `Cargo.toml`:

```toml
tfhe = { version = "0.10.0", features = ["x86_64-unix"] }
```

This enables the `x86_64-unix` feature to have efficient implementations of various algorithms for `x86_64` CPUs on a Unix-like system. The 'unix' suffix indicates that the `UnixSeeder`, which uses `/dev/random` to generate random numbers, is activated as a fallback if no hardware number generator is available (like `rdseed` on `x86_64` or if the [`Randomization Services`](https://developer.apple.com/documentation/security/1399291-secrandomcopybytes?language=objc) on Apple platforms are not available). To avoid having the `UnixSeeder` as a potential fallback or to run on non-Unix systems (e.g., Windows), the `x86_64` feature is sufficient.

For Apple Silicon, the `aarch64-unix` or `aarch64` feature should be enabled. `aarch64` is not supported on Windows as it's currently missing an entropy source required to seed the [CSPRNGs](https://en.wikipedia.org/wiki/Cryptographically\_secure\_pseudorandom\_number\_generator) used in `TFHE-rs`.

In short: For `x86_64`-based machines running Unix-like OSes:

```toml
tfhe = { version = "0.10.0", features = ["x86_64-unix"] }
```

For Apple Silicon or aarch64-based machines running Unix-like OSes:

```toml
tfhe = { version = "0.10.0", features = ["aarch64-unix"] }
```

For `x86_64`-based machines with the [`rdseed instruction`](https://en.wikipedia.org/wiki/RDRAND) running Windows:

```toml
tfhe = { version = "0.10.0", features = ["x86_64"] }
tfhe = { version = "0.10.0" }
```

### Commented code to double a 2-bit message in a leveled fashion and using a PBS with the `core_crypto` module.
Expand Down
2 changes: 1 addition & 1 deletion tfhe/docs/tutorials/ascii_fhe_string.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To use the `FheUint8` type, enable the `integer` feature:

[dependencies]
# Default configuration for x86 Unix machines:
tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] }
tfhe = { version = "0.10.0", features = ["integer"] }
```

Refer to the [installation guide](../getting\_started/installation.md) for other configurations.
Expand Down
5 changes: 1 addition & 4 deletions tfhe/docs/tutorials/parity_bit.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ This function returns a Boolean (`true` or `false`) so that the total count of `
```toml
# Cargo.toml

# Default configuration for x86 Unix machines:
tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] }
tfhe = { version = "0.10.0", features = ["integer"] }
```

Refer to the [installation](../getting\_started/installation.md) for other configurations.

First, define the verification function.

The function initializes the parity bit to `false`, then applies the `XOR` operation across all bits, adding negation based on the requested mode.
Expand Down
Loading

0 comments on commit 2cd7df1

Please sign in to comment.