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 4e94b00
Show file tree
Hide file tree
Showing 11 changed files with 3,641 additions and 233 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
7 changes: 1 addition & 6 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ materials provided with the distribution.
3. Neither the name of ZAMA nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written permission.

NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE*.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
THIS SOFTWARE IS PROVIDED BY THE ZAMA AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
Expand All @@ -26,8 +26,3 @@ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CA
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*In addition to the rights carried by this license, ZAMA grants to the user a non-exclusive,
free and non-commercial license on all patents filed in its name relating to the open-source
code (the "Patents") for the sole purpose of evaluation, development, research, prototyping
and experimentation.
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 4e94b00

Please sign in to comment.