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