Skip to content

Commit

Permalink
feat: implement 128bit fft
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah el kazdadi committed Feb 14, 2023
1 parent d110fa0 commit 89f2e8d
Show file tree
Hide file tree
Showing 10 changed files with 3,640 additions and 227 deletions.
13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ keywords = ["fft"]
[dependencies]
num-complex = "0.4"
dyn-stack = { version = "0.8", default-features = false }
pulp = "0.10"
bytemuck = "1.13"
aligned-vec = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, default-features = false }

[features]
default = ["std"]
nightly = []
default = ["std", "fft128"]
nightly = ["pulp/nightly", "bytemuck/nightly_stdsimd"]
std = []
fft128 = []
serde = ["dep:serde", "num-complex/serde"]

[dev-dependencies]
Expand All @@ -28,9 +31,13 @@ rustfft = "6.0"
fftw-sys = { version = "0.6", default-features = false, features = ["system"] }
rand = "0.8"
bincode = "1.3"
more-asserts = "0.3.1"

[target.'cfg(target_os = "linux")'.dev-dependencies]
rug = "1.19.0"

[[bench]]
name = "fft"
name = "bench"
harness = false

[package.metadata.docs.rs]
Expand Down
57 changes: 31 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,38 @@ that processes vectors of sizes that are powers of two. It was made to be used
as a backend in Zama's `concrete` library.

This library provides two FFT modules:
- The ordered module FFT applies a forward/inverse FFT that takes its input in standard
order, and outputs the result in standard order. For more detail on what the FFT
computes, check the ordered module-level documentation.
- The unordered module FFT applies a forward FFT that takes its input in standard order,
and outputs the result in a certain permuted order that may depend on the FFT plan. On the
other hand, the inverse FFT takes its input in that same permuted order and outputs its result
in standard order. This is useful for cases where the order of the coefficients in the
Fourier domain is not important. An example is using the Fourier transform for vector
convolution. The only operations that are performed in the Fourier domain are elementwise, and
so the order of the coefficients does not affect the results.

- The ordered module FFT applies a forward/inverse FFT that takes its input in standard
order, and outputs the result in standard order. For more detail on what the FFT
computes, check the ordered module-level documentation.
- The unordered module FFT applies a forward FFT that takes its input in standard order,
and outputs the result in a certain permuted order that may depend on the FFT plan. On the
other hand, the inverse FFT takes its input in that same permuted order and outputs its result
in standard order. This is useful for cases where the order of the coefficients in the
Fourier domain is not important. An example is using the Fourier transform for vector
convolution. The only operations that are performed in the Fourier domain are elementwise, and
so the order of the coefficients does not affect the results.

Additionally, an optional 128-bit negacyclic FFT module is provided.

## Features

- `std` (default): This enables runtime arch detection for accelerated SIMD
instructions, and an FFT plan that measures the various implementations to
choose the fastest one at runtime.
- `nightly`: This enables unstable Rust features to further speed up the FFT,
by enabling AVX512F instructions on CPUs that support them. This feature
requires a nightly Rust
toolchain.
- `serde`: This enables serialization and deserialization functions for the
unordered plan. These allow for data in the Fourier domain to be serialized
from the permuted order to the standard order, and deserialized from the
standard order to the permuted order. This is needed since the inverse
transform must be used with the same plan that computed/deserialized the
forward transform (or more specifically, a plan with the same internal base
FFT size).
- `std` (default): This enables runtime arch detection for accelerated SIMD
instructions, and an FFT plan that measures the various implementations to
choose the fastest one at runtime.
- `fft128` (default): This flag provides access to the 128-bit FFT, which is accessible in the
`concrete_fft::fft128` module.
- `nightly`: This enables unstable Rust features to further speed up the FFT,
by enabling AVX512F instructions on CPUs that support them. This feature
requires a nightly Rust
toolchain.
- `serde`: This enables serialization and deserialization functions for the
unordered plan. These allow for data in the Fourier domain to be serialized
from the permuted order to the standard order, and deserialized from the
standard order to the permuted order. This is needed since the inverse
transform must be used with the same plan that computed/deserialized the
forward transform (or more specifically, a plan with the same internal base
FFT size).

## Example

Expand Down Expand Up @@ -65,8 +70,8 @@ for (actual, expected) in transformed_inv.iter().map(|z| z / N as f64).zip(data)

## Links

- [Zama](https://www.zama.ai/)
- [Concrete](https://github.com/zama-ai/concrete)
- [Zama](https://www.zama.ai/)
- [Concrete](https://github.com/zama-ai/concrete)

## License

Expand Down
Loading

0 comments on commit 89f2e8d

Please sign in to comment.