(git:e70887f)
Loading...
Searching...
No Matches
fft_lib.c File Reference
#include "fft_lib.h"
#include "../offload/offload_runtime.h"
#include "fft_lib_fftw.h"
#include "fft_timer.h"
#include "fft_utils.h"
#include "gpu/fft_gpu.h"
#include "../base/cp_assert.h"
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Macros

#define FFT_DISPATCH_VOID(gpu_call, fftw_call)
 Forward a void FFT call to the selected backend.

Functions

static int fft_timer_start (const char *format,...)
 Start an FFT timer from a printf-style label.
int fft_init_acc_lib ()
 Initialize the accelerated FFT library.
int fft_init_lib (const fft_lib lib, const int fftw_planning_flag, const bool use_guru_interface, const char *wisdom_file)
 Initialize the FFT library (if not done externally).
void fft_finalize_acc_lib ()
 Finalize the accelerated FFT library.
void fft_finalize_lib (const char *wisdom_file)
 Finalize the FFT library (if not done externally).
int fft_lib_default_library ()
 Get the default library (GPU if offloading was enabled, else FFTW3).
int fft_lib_backend_in_use ()
 Whether a compound MPI implementation is available.
bool fft_lib_has_guru_interface ()
 Whether a compound MPI implementation is available.
void fft_allocate_double (const int length, double **buffer)
 Allocate buffer of type double.
void fft_allocate_complex (const int length, double complex **buffer)
 Allocate buffer of type double complex.
void fft_free_double (double *buffer)
 Allocate buffer of type double.
void fft_free_complex (double complex *buffer)
 Allocate buffer of type double complex.
void fft_register_1d_local (const bool dir, const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double complex *grid_in, double complex *grid_out)
 Register a local 1D C2C FFT.
void fft_register_1d_r2c_local (const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double *grid_in, double complex *grid_out)
 Register a local 1D R2C FFT.
void fft_register_1d_c2r_local (const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double complex *grid_in, double *grid_out)
 Register a local 1D C2R FFT.
void fft_register_2d_local (const bool dir, const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double complex *grid_out)
 Register a local 2D FFT.
void fft_register_2d_r2c_local (const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double *grid_in, double complex *grid_out)
 Register a local 2D R2C FFT.
void fft_register_2d_c2r_local (const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double *grid_out)
 Register a local 2D C2R FFT.
void fft_register_3d_local (const bool dir, const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double complex *grid_out)
 Register a local 3D FFT.
void fft_register_3d_r2c_local (const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double *grid_in, double complex *grid_out)
 Register a local 3D R2C FFT.
void fft_register_3d_c2r_local (const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double *grid_out)
 Register a local 3D C2R FFT.
void fft_1d_local (const bool dir, const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double complex *grid_in, double complex *grid_out)
 Perform a local 1D FFT.
void fft_1d_r2c_local (const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double *grid_in, double complex *grid_out)
 Perform a local 1D R2C FFT.
void fft_1d_c2r_local (const int fft_size, const int number_of_ffts, const bool transpose_in, const bool transpose_out, const int leading_dimension_in, const int leading_dimension_out, double complex *grid_in, double *grid_out)
 Perform a local 1D C2R FFT.
void fft_2d_local (const bool dir, const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double complex *grid_out)
 Perform a local 2D FFT.
void fft_2d_r2c_local (const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double *grid_in, double complex *grid_out)
 Perform a local 2D R2C FFT.
void fft_2d_c2r_local (const int fft_size[2], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double *grid_out)
 Perform a local 2D C2R FFT.
void fft_3d_local (const bool dir, const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double complex *grid_out)
 Perform a local 3D FFT.
void fft_3d_r2c_local (const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double *grid_in, double complex *grid_out)
 Perform a local 3D R2C FFT.
void fft_3d_c2r_local (const int fft_size[3], const int number_of_ffts, const bool transpose_in, const bool transpose_out, double complex *grid_in, double *grid_out)
 Perform a local 3D C2R FFT.

Variables

const int fft_lib_default = -1
fft_lib fft_lib_choice = fft_lib_default
bool fft_lib_initialized = false

Macro Definition Documentation

◆ FFT_DISPATCH_VOID

#define FFT_DISPATCH_VOID ( gpu_call,
fftw_call )
Value:
do { \
switch (fft_lib_choice) { \
case FFT_LIB_GPU: \
gpu_call; \
break; \
case FFT_LIB_FFTW: \
fftw_call; \
break; \
default: \
cp_assert(0 && "Unknown FFT library."); \
} \
} while (0)
fft_lib fft_lib_choice
Definition fft_lib.c:31
@ FFT_LIB_FFTW
Definition fft_lib.h:16
@ FFT_LIB_GPU
Definition fft_lib.h:16

Forward a void FFT call to the selected backend.

Definition at line 49 of file fft_lib.c.

Function Documentation

◆ fft_timer_start()

int fft_timer_start ( const char * format,
... )
static

Start an FFT timer from a printf-style label.

Definition at line 37 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_init_acc_lib()

int fft_init_acc_lib ( )

Initialize the accelerated FFT library.

Author
Frederick Stein

Definition at line 67 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_init_lib()

int fft_init_lib ( const fft_lib lib,
const int fftw_planning_flag,
const bool use_guru_interface,
const char * wisdom_file )

Initialize the FFT library (if not done externally).

Parameters
libFFT backend to use.
fftw_planning_flagFFTW planning mode.
use_guru_interfaceWhether the FFTW Guru interface may be used.
wisdom_filePath to the FFTW wisdom file.
Author
Frederick Stein

Definition at line 84 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_finalize_acc_lib()

void fft_finalize_acc_lib ( )

Finalize the accelerated FFT library.

Author
Frederick Stein

Definition at line 123 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_finalize_lib()

void fft_finalize_lib ( const char * wisdom_file)

Finalize the FFT library (if not done externally).

Parameters
wisdom_filePath to the FFTW wisdom file.
Author
Frederick Stein

Definition at line 134 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_lib_default_library()

int fft_lib_default_library ( )

Get the default library (GPU if offloading was enabled, else FFTW3).

Author
Frederick Stein

Definition at line 144 of file fft_lib.c.

Here is the caller graph for this function:

◆ fft_lib_backend_in_use()

int fft_lib_backend_in_use ( )

Whether a compound MPI implementation is available.

Inquire the library backend in use.

Author
Frederick Stein

Definition at line 150 of file fft_lib.c.

Here is the caller graph for this function:

◆ fft_lib_has_guru_interface()

bool fft_lib_has_guru_interface ( )

Whether a compound MPI implementation is available.

Whether compound MPI implementations are available.

Author
Frederick Stein

Definition at line 156 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_allocate_double()

void fft_allocate_double ( const int length,
double ** buffer )

Allocate buffer of type double.

Parameters
lengthNumber of elements.
bufferBuffer pointer.
Author
Frederick Stein

Definition at line 174 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_allocate_complex()

void fft_allocate_complex ( const int length,
double complex ** buffer )

Allocate buffer of type double complex.

Parameters
lengthNumber of elements.
bufferBuffer pointer.
Author
Frederick Stein

Definition at line 185 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_free_double()

void fft_free_double ( double * buffer)

Allocate buffer of type double.

Parameters
bufferBuffer pointer.
Author
Frederick Stein

Definition at line 195 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_free_complex()

void fft_free_complex ( double complex * buffer)

Allocate buffer of type double complex.

Parameters
bufferBuffer pointer.
Author
Frederick Stein

Definition at line 210 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_1d_local()

void fft_register_1d_local ( const bool dir,
const int fft_size,
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
const int leading_dimension_in,
const int leading_dimension_out,
double complex * grid_in,
double complex * grid_out )

Register a local 1D C2C FFT.

Parameters
dirFFT direction (forward or backward).
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
leading_dimension_inLeading dimension of the input array.
leading_dimension_outLeading dimension of the output array.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 233 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_1d_r2c_local()

void fft_register_1d_r2c_local ( const int fft_size,
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
const int leading_dimension_in,
const int leading_dimension_out,
double * grid_in,
double complex * grid_out )

Register a local 1D R2C FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
leading_dimension_inLeading dimension of the input array.
leading_dimension_outLeading dimension of the output array.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 266 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_1d_c2r_local()

void fft_register_1d_c2r_local ( const int fft_size,
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
const int leading_dimension_in,
const int leading_dimension_out,
double complex * grid_in,
double * grid_out )

Register a local 1D C2R FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
leading_dimension_inLeading dimension of the input array.
leading_dimension_outLeading dimension of the output array.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 300 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_2d_local()

void fft_register_2d_local ( const bool dir,
const int fft_size[2],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double complex * grid_in,
double complex * grid_out )

Register a local 2D FFT.

Parameters
dirFFT direction (forward or backward).
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 333 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_2d_r2c_local()

void fft_register_2d_r2c_local ( const int fft_size[2],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double * grid_in,
double complex * grid_out )

Register a local 2D R2C FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 361 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_2d_c2r_local()

void fft_register_2d_c2r_local ( const int fft_size[2],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double complex * grid_in,
double * grid_out )

Register a local 2D C2R FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 389 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_3d_local()

void fft_register_3d_local ( const bool dir,
const int fft_size[3],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double complex * grid_in,
double complex * grid_out )

Register a local 3D FFT.

Note
fft_3d_bw_local(grid_gs, grid_rs, n) is the reverse to fft_3d_rw_local(grid_rs, grid_gs, n) (ignoring normalization).
Parameters
dirFFT direction (forward or backward).
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 420 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_3d_r2c_local()

void fft_register_3d_r2c_local ( const int fft_size[3],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double * grid_in,
double complex * grid_out )

Register a local 3D R2C FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 447 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_register_3d_c2r_local()

void fft_register_3d_c2r_local ( const int fft_size[3],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double complex * grid_in,
double * grid_out )

Register a local 3D C2R FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 475 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_1d_local()

void fft_1d_local ( const bool dir,
const int fft_size,
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
const int leading_dimension_in,
const int leading_dimension_out,
double complex * grid_in,
double complex * grid_out )

Perform a local 1D FFT.

Parameters
dirFFT direction (forward or backward).
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
leading_dimension_inLeading dimension of the input array.
leading_dimension_outLeading dimension of the output array.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 506 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_1d_r2c_local()

void fft_1d_r2c_local ( const int fft_size,
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
const int leading_dimension_in,
const int leading_dimension_out,
double * grid_in,
double complex * grid_out )

Perform a local 1D R2C FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
leading_dimension_inLeading dimension of the input array.
leading_dimension_outLeading dimension of the output array.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 538 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_1d_c2r_local()

void fft_1d_c2r_local ( const int fft_size,
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
const int leading_dimension_in,
const int leading_dimension_out,
double complex * grid_in,
double * grid_out )

Perform a local 1D C2R FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
leading_dimension_inLeading dimension of the input array.
leading_dimension_outLeading dimension of the output array.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 571 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_2d_local()

void fft_2d_local ( const bool dir,
const int fft_size[2],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double complex * grid_in,
double complex * grid_out )

Perform a local 2D FFT.

Parameters
dirFFT direction (forward or backward).
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 603 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_2d_r2c_local()

void fft_2d_r2c_local ( const int fft_size[2],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double * grid_in,
double complex * grid_out )

Perform a local 2D R2C FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 630 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_2d_c2r_local()

void fft_2d_c2r_local ( const int fft_size[2],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double complex * grid_in,
double * grid_out )

Perform a local 2D C2R FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 657 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_3d_local()

void fft_3d_local ( const bool dir,
const int fft_size[3],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double complex * grid_in,
double complex * grid_out )

Perform a local 3D FFT.

Parameters
dirFFT direction (forward or backward).
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 685 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_3d_r2c_local()

void fft_3d_r2c_local ( const int fft_size[3],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double * grid_in,
double complex * grid_out )

Perform a local 3D R2C FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 712 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_3d_c2r_local()

void fft_3d_c2r_local ( const int fft_size[3],
const int number_of_ffts,
const bool transpose_in,
const bool transpose_out,
double complex * grid_in,
double * grid_out )

Perform a local 3D C2R FFT.

Parameters
fft_sizeSize of the transform in each dimension.
number_of_fftsNumber of independent (batched) transforms.
transpose_inWhether the input array uses the transposed layout.
transpose_outWhether the output array uses the transposed layout.
grid_inInput grid buffer.
grid_outOutput grid buffer.
Author
Frederick Stein

Definition at line 739 of file fft_lib.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ fft_lib_default

const int fft_lib_default = -1

Definition at line 29 of file fft_lib.c.

◆ fft_lib_choice

fft_lib fft_lib_choice = fft_lib_default

Definition at line 31 of file fft_lib.c.

◆ fft_lib_initialized

bool fft_lib_initialized = false

Definition at line 32 of file fft_lib.c.