Quick startΒΆ
The following code is a simplified version of 1d_c2c_single_example.cpp
available from NVPLSamples, showing how to use NVPL FFT.
#include <iostream>
#include <vector>
#include <complex>
#include <nvpl_fftw.h>
int main(int argc, char *argv[]) {
const int n = 4;
const int howmany = 2;
std::vector<std::complex<float>> in(howmany * n);
std::vector<std::complex<float>> out(howmany * n);
fftwf_complex *in_data = reinterpret_cast<fftwf_complex*>(in.data() );
fftwf_complex *out_data = reinterpret_cast<fftwf_complex*>(out.data());
fftwf_plan plan = fftwf_plan_dft_1d(n, in_data, out_data, FFTW_FORWARD, FFTW_ESTIMATE);
int i = 0;
for (auto& v: in) {
v = {(float)i, -(float)i};
i++;
}
for(int b = 0; b < howmany; b++) {
fftwf_execute_dft(plan, in_data+b*n, out_data+b*n);
}
for (const auto& v: out) {
std::cout << v << "\n";
}
fftwf_destroy_plan(plan);
fftwf_cleanup();
return 0;
}
This example computes howmany
batches of a one-dimensional forward FFT with size n
. It does the following:
Allocates the input and output data
Creates a 1D FFTW plan with specified size
n
and transform directionFFTW_FORWARD
Initializes the input data.
Executes the plan. One batch at a time.
Outputs the results.
Destroys the plan.
The example can then be compiled and run as follows:
$ g++ app.cpp -I/path/to/nvpl_fft/include -L/path/to/nvpl_fft/lib -lnvpl_fftw -o app
$ ./app
(6,-6)
(0,4)
(-2,2)
(-4,0)
(22,-22)
(0,4)
(-2,2)
(-4,0)
Tip
For an application that dynamically links to the FFTW3 libraries, one could test NVPL FFT by running the application with
LD_PRELOAD=/path/to/nvpl_fft/lib/libnvpl_fftw.so
.