-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_dispatch_caller.cpp
More file actions
109 lines (98 loc) · 4.05 KB
/
Copy pathdynamic_dispatch_caller.cpp
File metadata and controls
109 lines (98 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <array>
#include <complex>
#include <cstddef>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "dynamic_dispatch_wrapper.hpp"
template <typename F>
void run_cfft(zldsp_fft_example::CFFT<F>& cfft, const std::size_t order) {
const std::size_t fft_size = std::size_t{1} << order;
using Complex = std::complex<F>;
using SoA = std::array<F*, 2>;
std::vector<Complex> complex_input(fft_size, Complex{F{1}, F{0}});
std::vector<Complex> complex_output(fft_size);
std::vector<F> complex_input_real(fft_size, F{1});
std::vector<F> complex_input_imag(fft_size, F{0});
std::vector<F> complex_output_real(fft_size);
std::vector<F> complex_output_imag(fft_size);
SoA complex_input_soa{complex_input_real.data(), complex_input_imag.data()};
SoA complex_output_soa{complex_output_real.data(), complex_output_imag.data()};
// CFFT forward AoS to AoS
cfft.forward(complex_input.data(), complex_output.data());
// CFFT forward AoS to SoA
cfft.forward(complex_input.data(), complex_output_soa);
// CFFT forward SoA to AoS
cfft.forward(complex_input_soa, complex_output.data());
// CFFT forward SoA to SoA
cfft.forward(complex_input_soa, complex_output_soa);
// CFFT backward AoS to AoS
cfft.backward(complex_output.data(), complex_input.data());
// CFFT backward AoS to SoA
cfft.backward(complex_output.data(), complex_input_soa);
// CFFT backward SoA to AoS
cfft.backward(complex_output_soa, complex_input.data());
// CFFT backward SoA to SoA
cfft.backward(complex_output_soa, complex_input_soa);
}
template <typename F>
void run_rfft(zldsp_fft_example::RFFT<F>& rfft, const std::size_t order) {
const std::size_t fft_size = std::size_t{1} << order;
using Complex = std::complex<F>;
using SoA = std::array<F*, 2>;
std::vector<F> real_input(fft_size, F{1});
std::vector<Complex> real_output(fft_size / 2 + 1);
std::vector<F> real_output_real(fft_size / 2 + 1);
std::vector<F> real_output_imag(fft_size / 2 + 1);
SoA real_output_soa{real_output_real.data(), real_output_imag.data()};
// RFFT forward AoS
rfft.forward(real_input.data(), real_output.data());
// RFFT forward SoA
rfft.forward(real_input.data(), real_output_soa);
// RFFT backward AoS
rfft.backward(real_output.data(), real_input.data());
// RFFT backward SoA
rfft.backward(real_output_soa, real_input.data());
// RFFT forward squared magnitude
rfft.forward_sqr_mag(real_input.data(), real_output_real.data());
}
int main(const int argc, char** argv) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << " <start-order> <end-order>" << std::endl;
return 2;
}
try {
const std::size_t start_order = std::stoul(argv[1]);
const std::size_t end_order = std::stoul(argv[2]);
// CFFT float
for (std::size_t order = start_order; order <= end_order; ++order) {
std::unique_ptr<zldsp_fft_example::CFFT<float>> cfft =
zldsp_fft_example::prepare_cfft<float>(order);
run_cfft(*cfft, order);
}
// CFFT double
for (std::size_t order = start_order; order <= end_order; ++order) {
std::unique_ptr<zldsp_fft_example::CFFT<double>> cfft =
zldsp_fft_example::prepare_cfft<double>(order);
run_cfft(*cfft, order);
}
// RFFT float
for (std::size_t order = start_order; order <= end_order; ++order) {
std::unique_ptr<zldsp_fft_example::RFFT<float>> rfft =
zldsp_fft_example::prepare_rfft<float>(order);
run_rfft(*rfft, order);
}
// RFFT double
for (std::size_t order = start_order; order <= end_order; ++order) {
std::unique_ptr<zldsp_fft_example::RFFT<double>> rfft =
zldsp_fft_example::prepare_rfft<double>(order);
run_rfft(*rfft, order);
}
}
catch (...) {
std::cerr << "Invalid order range: " << argv[1] << " " << argv[2] << std::endl;
return 2;
}
return 0;
}