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

Ns/remove arch features #1858

Merged
merged 8 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = { workspace = true }

[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
20 changes: 2 additions & 18 deletions tfhe-csprng/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tfhe-csprng"
version = "0.4.1"
version = "0.5.0"
edition = "2021"
license = "BSD-3-Clause-Clear"
description = "Cryptographically Secure PRNG used in the TFHE-rs library."
Expand All @@ -25,29 +25,13 @@ clap = "=4.4.4"

[features]
parallel = ["rayon"]
seeder_x86_64_rdseed = []
seeder_unix = []
generator_x86_64_aesni = []
generator_fallback = []
generator_aarch64_aes = []

x86_64 = [
"parallel",
"seeder_x86_64_rdseed",
"generator_x86_64_aesni",
"generator_fallback",
]
x86_64-unix = ["x86_64", "seeder_unix"]
aarch64 = ["parallel", "generator_aarch64_aes", "generator_fallback"]
aarch64-unix = ["aarch64", "seeder_unix"]
software-prng = []

[[bench]]
name = "benchmark"
path = "benches/benchmark.rs"
harness = false
required-features = ["seeder_x86_64_rdseed", "generator_x86_64_aesni"]

[[example]]
name = "generate"
path = "examples/generate.rs"
required-features = ["seeder_unix", "generator_fallback"]
4 changes: 2 additions & 2 deletions tfhe-csprng/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ The implementation is based on the AES blockcipher used in CTR mode, as describe

Two implementations are available, an accelerated one on x86_64 CPUs with the `aes` feature and the `sse2` feature, and a pure software one that can be used on other platforms.

The crate also makes two seeders available, one needing the x86_64 feature `rdseed` and another one based on the Unix random device `/dev/random` the latter requires the user to provide a secret.
The crate also makes two seeders available, one needing the x86_64 instruction `rdseed` and another one based on the Unix random device `/dev/random` the latter requires the user to provide a secret.

## Running the benchmarks

To execute the benchmarks on an x86_64 platform:
```shell
RUSTFLAGS="-Ctarget-cpu=native" cargo bench --features=seeder_x86_64_rdseed,generator_x86_64_aesni
RUSTFLAGS="-Ctarget-cpu=native" cargo bench
```

## License
Expand Down
54 changes: 46 additions & 8 deletions tfhe-csprng/benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tfhe_csprng::generators::{
AesniRandomGenerator, BytesPerChild, ChildrenCount, RandomGenerator,
BytesPerChild, ChildrenCount, DefaultRandomGenerator, RandomGenerator,
};
use tfhe_csprng::seeders::{RdseedSeeder, Seeder};
#[cfg(target_os = "macos")]
use tfhe_csprng::seeders::AppleSecureEnclaveSeeder as ActivatedSeeder;
#[cfg(all(
not(target_os = "macos"),
target_arch = "x86_64",
target_feature = "rdseed"
))]
use tfhe_csprng::seeders::RdseedSeeder as ActivatedSeeder;
#[cfg(all(
not(target_os = "macos"),
not(all(target_arch = "x86_64", target_feature = "rdseed")),
target_family = "unix"
))]
use tfhe_csprng::seeders::UnixSeeder as ActivatedSeeder;

use tfhe_csprng::seeders::Seeder;

// The number of bytes to generate during one benchmark iteration.
const N_GEN: usize = 1_000_000;

fn new_seeder() -> ActivatedSeeder {
#[cfg(target_os = "macos")]
{
ActivatedSeeder
}
#[cfg(all(
not(target_os = "macos"),
target_arch = "x86_64",
target_feature = "rdseed"
))]
{
ActivatedSeeder::new()
}
#[cfg(all(
not(target_os = "macos"),
not(all(target_arch = "x86_64", target_feature = "rdseed")),
target_family = "unix"
))]
{
ActivatedSeeder::new(0)
}
}

fn parent_generate(c: &mut Criterion) {
let mut seeder = RdseedSeeder;
let mut generator = AesniRandomGenerator::new(seeder.seed());
let mut seeder = new_seeder();
let mut generator = DefaultRandomGenerator::new(seeder.seed());
c.bench_function("parent_generate", |b| {
b.iter(|| {
(0..N_GEN).for_each(|_| {
Expand All @@ -20,8 +58,8 @@ fn parent_generate(c: &mut Criterion) {
}

fn child_generate(c: &mut Criterion) {
let mut seeder = RdseedSeeder;
let mut generator = AesniRandomGenerator::new(seeder.seed());
let mut seeder = new_seeder();
let mut generator = DefaultRandomGenerator::new(seeder.seed());
let mut generator = generator
.try_fork(ChildrenCount(1), BytesPerChild(N_GEN * 10_000))
.unwrap()
Expand All @@ -37,8 +75,8 @@ fn child_generate(c: &mut Criterion) {
}

fn fork(c: &mut Criterion) {
let mut seeder = RdseedSeeder;
let mut generator = AesniRandomGenerator::new(seeder.seed());
let mut seeder = new_seeder();
let mut generator = DefaultRandomGenerator::new(seeder.seed());
c.bench_function("fork", |b| {
b.iter(|| {
black_box(
Expand Down
115 changes: 0 additions & 115 deletions tfhe-csprng/build.rs

This file was deleted.

Loading
Loading