poulpy/poulpy-cpu-avx/benches/fft.rs
poulpy-cpu-avx/benches/fft.rsRaw
1use criterion::{Criterion, criterion_group, criterion_main};
2
3#[cfg(not(all(feature = "enable-avx", target_arch = "x86_64", target_feature = "avx2", target_feature = "fma")))]
4fn bench_ifft_avx2_fma(_c: &mut Criterion) {
5 eprintln!("Skipping: AVX IFft benchmark requires x86_64 + AVX2 + FMA");
6}
7
8#[cfg(all(feature = "enable-avx", target_arch = "x86_64", target_feature = "avx2", target_feature = "fma"))]
9pub fn bench_ifft_avx2_fma(c: &mut Criterion) {
10 use criterion::BenchmarkId;
11 use poulpy_cpu_avx::ReimIFFTAvx;
12 use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimIFFTTable};
13 use std::hint::black_box;
14
15 let group_name: String = "ifft_avx2_fma".to_string();
16
17 let mut group = c.benchmark_group(group_name);
18
19 if std::is_x86_feature_detected!("avx2") {
20 fn runner(m: usize) -> impl FnMut() {
21 let mut values: Vec<f64> = vec![0f64; m << 1];
22
23 let scale = 1.0f64 / (2 * m) as f64;
24 values
25 .iter_mut()
26 .enumerate()
27 .for_each(|(i, x)| *x = (i + 1) as f64 * scale);
28
29 let table: ReimIFFTTable<f64> = ReimIFFTTable::<f64>::new(m);
30 move || {
31 ReimIFFTAvx::reim_dft_execute(&table, &mut values);
32 black_box(());
33 }
34 }
35
36 for log_m in [9, 10, 11, 12, 13, 14, 15] {
37 let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
38
39 let mut runner = runner(1 << log_m);
40 group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
41 }
42 } else {
43 eprintln!("skipping: CPU lacks avx2");
44 return;
45 }
46
47 group.finish();
48}
49
50#[cfg(not(all(feature = "enable-avx", target_arch = "x86_64", target_feature = "avx2", target_feature = "fma")))]
51fn bench_fft_avx2_fma(_c: &mut Criterion) {
52 eprintln!("Skipping: AVX FFT benchmark requires x86_64 + AVX2 + FMA");
53}
54
55#[cfg(all(feature = "enable-avx", target_arch = "x86_64", target_feature = "avx2", target_feature = "fma"))]
56pub fn bench_fft_avx2_fma(c: &mut Criterion) {
57 use criterion::BenchmarkId;
58 use poulpy_cpu_avx::ReimFFTAvx;
59 use poulpy_hal::reference::fft64::reim::{ReimDFTExecute, ReimFFTTable};
60 use std::hint::black_box;
61
62 let group_name: String = "fft_avx2_fma".to_string();
63
64 let mut group = c.benchmark_group(group_name);
65
66 if std::is_x86_feature_detected!("avx2") {
67 fn runner(m: usize) -> impl FnMut() {
68 let mut values: Vec<f64> = vec![0f64; m << 1];
69
70 let scale = 1.0f64 / (2 * m) as f64;
71 values
72 .iter_mut()
73 .enumerate()
74 .for_each(|(i, x)| *x = (i + 1) as f64 * scale);
75
76 let table: ReimFFTTable<f64> = ReimFFTTable::<f64>::new(m);
77 move || {
78 ReimFFTAvx::reim_dft_execute(&table, &mut values);
79 black_box(());
80 }
81 }
82
83 for log_m in [9, 10, 11, 12, 13, 14, 15] {
84 let id: BenchmarkId = BenchmarkId::from_parameter(format!("n: {}", 2 << log_m));
85
86 let mut runner = runner(1 << log_m);
87 group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
88 }
89 } else {
90 eprintln!("skipping: CPU lacks avx2");
91 return;
92 }
93
94 group.finish();
95}
96
97criterion_group!(benches_x86, bench_fft_avx2_fma, bench_ifft_avx2_fma,);
98criterion_main!(benches_x86);