Skip to content

Commit 08eedcb

Browse files
authored
Merge pull request #27 from QuState/feature/interleaved-complex-nums
Add functions to support interleaved complex num
2 parents 20fafba + 713b3a6 commit 08eedcb

File tree

13 files changed

+443
-63
lines changed

13 files changed

+443
-63
lines changed

.github/workflows/rust.yml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
uses: actions-rs/cargo@v1
6464
with:
6565
command: test
66+
args: --all-features
6667

6768
coverage:
6869
runs-on: ubuntu-latest

Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ exclude = ["assets", "scripts", "benches"]
1313
[dependencies]
1414
num-traits = "0.2.18"
1515
multiversion = "0.7"
16+
num-complex = { version = "0.4.6", features = ["bytemuck"], optional = true }
17+
bytemuck = { version = "1.16.0", optional = true }
18+
19+
[features]
20+
default = []
21+
complex-nums = ["dep:num-complex", "dep:bytemuck"]
1622

1723
[dev-dependencies]
1824
criterion = "0.5.1"
@@ -33,3 +39,5 @@ panic = "abort"
3339
inherits = "release"
3440
debug = true
3541

42+
[package.metadata.docs.rs]
43+
all-features = true

benches/README.md

+5-21
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,26 @@
44

55
### Setup Environment
66

7-
1. Install [FFTW3](http://www.fftw.org/download.html)[^1]
7+
1. Clone the `PhastFT` git repository [^2].
88

9-
It may be possible to install `fftw3` using a package manager.
10-
11-
##### debian
12-
```bash
13-
sudo apt install libfftw3-dev
14-
```
15-
16-
2. Clone the `PhastFT` git repository [^2].
17-
18-
3. Create virtual env
9+
2. Create virtual env
1910

2011
```bash
2112
cd ~/PhastFT/benches && python3 -m venv .env && source .env/bin/activate
2213
```
2314

24-
4. Install python dependencies[^1]
15+
3. Install python dependencies[^1]
2516

2617
```bash
2718
pip install -r requirements.txt
2819
cd ~/PhastFT/pyphastft
2920
pip install .
3021
```
3122

32-
5. Run the `FFTW3` vs. `RustFFT` vs. `PhastFT` benchmark for all inputs of size `2^n`, where `n \in [4, 30].`
23+
5. Run the `FFTW3-RB` vs. `RustFFT` vs. `PhastFT` benchmarks`
3324

3425
```bash
35-
./benchmark.sh 4 29
26+
python run_benches.py
3627
```
3728

3829
6. Plot the results
@@ -101,13 +92,6 @@ On linux, open access to performance monitoring, and observability operations fo
10192
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
10293
```
10394

104-
Add debug to `Cargo.toml` under `profile.release`:
105-
106-
```bash
107-
[profile.release]
108-
debug = true
109-
```
110-
11195
Finally, run:
11296

11397
```bash

benches/bench.rs

+37-16
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use utilities::rustfft::num_complex::Complex;
1313
use utilities::rustfft::FftPlanner;
1414

1515
const LENGTHS: &[usize] = &[
16-
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
16+
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1717
];
1818

1919
fn generate_numbers<T: Float>(n: usize) -> (Vec<T>, Vec<T>)
@@ -69,7 +69,7 @@ fn benchmark_forward_f32(c: &mut Criterion) {
6969
let planner = Planner32::new(len, Direction::Forward);
7070
let (mut reals, mut imags) = generate_numbers(len);
7171

72-
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &len| {
72+
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &_len| {
7373
b.iter(|| {
7474
fft_32_with_opts_and_plan(
7575
black_box(&mut reals),
@@ -85,7 +85,7 @@ fn benchmark_forward_f32(c: &mut Criterion) {
8585
let fft = planner.plan_fft_forward(len);
8686
let mut signal = generate_complex_numbers(len);
8787

88-
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &len| {
88+
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &_len| {
8989
b.iter(|| fft.process(black_box(&mut signal)));
9090
});
9191
}
@@ -103,31 +103,49 @@ fn benchmark_inverse_f32(c: &mut Criterion) {
103103
c.bench_function(&id, |b| {
104104
let (mut reals, mut imags) = generate_numbers(len);
105105
b.iter(|| {
106-
black_box(fft_32_with_opts_and_plan(
107-
&mut reals, &mut imags, &options, &planner,
108-
));
106+
fft_32_with_opts_and_plan(
107+
black_box(&mut reals),
108+
black_box(&mut imags),
109+
black_box(&options),
110+
black_box(&planner),
111+
);
109112
});
110113
});
111114
}
112115
}
113116

114117
fn benchmark_forward_f64(c: &mut Criterion) {
115-
let options = Options::default();
118+
let mut group = c.benchmark_group("Forward f64");
116119

117120
for n in LENGTHS.iter() {
118121
let len = 1 << n;
119-
let id = format!("FFT Forward f64 {} elements", len);
122+
let id = "PhastFT FFT Forward";
123+
let options = Options::guess_options(len);
120124
let planner = Planner64::new(len, Direction::Forward);
125+
let (mut reals, mut imags) = generate_numbers(len);
126+
group.throughput(Throughput::Elements(len as u64));
121127

122-
c.bench_function(&id, |b| {
123-
let (mut reals, mut imags) = generate_numbers(len);
128+
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &_len| {
124129
b.iter(|| {
125-
black_box(fft_64_with_opts_and_plan(
126-
&mut reals, &mut imags, &options, &planner,
127-
));
130+
fft_64_with_opts_and_plan(
131+
black_box(&mut reals),
132+
black_box(&mut imags),
133+
black_box(&options),
134+
black_box(&planner),
135+
);
128136
});
129137
});
138+
139+
let id = "RustFFT FFT Forward";
140+
let mut planner = FftPlanner::<f64>::new();
141+
let fft = planner.plan_fft_forward(len);
142+
let mut signal = generate_complex_numbers(len);
143+
144+
group.bench_with_input(BenchmarkId::new(id, len), &len, |b, &_len| {
145+
b.iter(|| fft.process(black_box(&mut signal)));
146+
});
130147
}
148+
group.finish();
131149
}
132150

133151
fn benchmark_inverse_f64(c: &mut Criterion) {
@@ -141,9 +159,12 @@ fn benchmark_inverse_f64(c: &mut Criterion) {
141159
c.bench_function(&id, |b| {
142160
let (mut reals, mut imags) = generate_numbers(len);
143161
b.iter(|| {
144-
black_box(fft_64_with_opts_and_plan(
145-
&mut reals, &mut imags, &options, &planner,
146-
));
162+
fft_64_with_opts_and_plan(
163+
black_box(&mut reals),
164+
black_box(&mut imags),
165+
black_box(&options),
166+
black_box(&planner),
167+
);
147168
});
148169
});
149170
}

0 commit comments

Comments
 (0)