arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-cpu-avx/README.md
poulpy-cpu-avx/README.mdRaw
 1# 🐙 Poulpy-CPU-AVX
 2
 3**Poulpy-CPU-AVX** is a Rust crate that provides an **AVX2 + FMA accelerated CPU backend for Poulpy**.
 4
 5This backend implements the Poulpy HAL extension traits and can be used by:
 6
 7- [`poulpy-hal`](https://github.com/phantomzone-org/poulpy/tree/main/poulpy-hal)
 8- [`poulpy-core`](https://github.com/phantomzone-org/poulpy/tree/main/poulpy-core)
 9- [`poulpy-schemes`](https://github.com/phantomzone-org/poulpy/tree/main/poulpy-schemes)
10
11## 🚩 Safety and Requirements
12
13To avoid illegal hardware instructions (SIGILL) on unsupported CPUs, this backend is **opt-in** and **only builds when explicitly requested**.
14
15| Requirement | Status |
16|------------|--------|
17| Cargo feature flag | `--features enable-avx` **must be enabled** |
18| CPU architecture | `x86_64` |
19| CPU target features | `AVX2` + `FMA` |
20
21If `enable-avx` is enabled but the target does not provide these capabilities, the build **fails immediately with a clear error message**, rather than generating invalid binaries.
22
23When `enable-avx` is **not** enabled, this crate is simply skipped and Poulpy automatically falls back to the portable `poulpy-cpu-ref` backend. This ensure that Poulpy's workspace remains portable (e.g. for macOS ARM).
24
25## ⚙️ Building with the AVX backend enabled
26
27Because the compiler must generate AVX2 + FMA instructions, both the Cargo feature and CPU target flags must be specified:
28
29```bash
30RUSTFLAGS="-C target-feature=+avx2,+fma" \
31cargo build --features enable-avx
32````
33
34### Running an example
35
36```bash
37RUSTFLAGS="-C target-feature=+avx2,+fma" \
38cargo run --example <name> --features enable-avx
39```
40
41### Running benchmarks
42
43```bash
44RUSTFLAGS="-C target-feature=+avx2,+fma" \
45cargo bench --features enable-avx
46```
47
48## Basic Usage
49
50```rust
51use poulpy_backend_cpu_avx::FFT64Avx;
52use poulpy_hal::{api::ModuleNew, layouts::Module};
53
54let log_n: usize = 10;
55let module = Module<FFT64Avx> = Module<FFT64Avx>::new(1<<log_n);
56```
57
58Once compiled with `enable-avx`, the backend is usable transparently anywhere Poulpy expects a backend type (`poulpy-hal`, `poulpy-core`, `poulpy-schemes`).
59
60## 🤝 Contributors
61
62To implement your own Poulpy backend (SIMD or accelerator):
63
641. Define a backend struct
652. Implement the open extension traits from `poulpy-hal/oep`
663. Implement the `Backend` trait
67
68Your backend will automatically integrate with:
69
70* `poulpy-hal`
71* `poulpy-core`
72* `poulpy-schemes`
73
74No modifications to those crates are required — the HAL provides the extension points.
75
76---
77
78For questions or guidance, feel free to open an issue or discussion in the repository.