LCOV - code coverage report
Current view: top level - src/fft - fft_lib.c (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 95.8 % 190 182
Test Date: 2026-11-24 01:22:08 Functions: 100.0 % 30 30

            Line data    Source code
       1              : /*----------------------------------------------------------------------------*/
       2              : /*  CP2K: A general program to perform molecular dynamics simulations         */
       3              : /*  Copyright 2000-2026 CP2K developers group <https://cp2k.org>              */
       4              : /*                                                                            */
       5              : /*  SPDX-License-Identifier: BSD-3-Clause                                     */
       6              : /*----------------------------------------------------------------------------*/
       7              : 
       8              : #include "fft_lib.h"
       9              : #include "../offload/offload_runtime.h"
      10              : #include "fft_lib_fftw.h"
      11              : #include "fft_timer.h"
      12              : #include "fft_utils.h"
      13              : #include "gpu/fft_gpu.h"
      14              : 
      15              : #include "../base/cp_assert.h"
      16              : #include <math.h>
      17              : #include <stdarg.h>
      18              : #include <stdbool.h>
      19              : #include <stddef.h>
      20              : #include <stdio.h>
      21              : #include <string.h>
      22              : 
      23              : #if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
      24              : const int fft_lib_default = FFT_LIB_GPU;
      25              : #elif defined(__FFTW3)
      26              : const int fft_lib_default = FFT_LIB_FFTW;
      27              : #else
      28              : #error "The FFT backend needs at least the FFTW3 backend."
      29              : const int fft_lib_default = -1; // No backend available
      30              : #endif
      31              : fft_lib fft_lib_choice = fft_lib_default;
      32              : bool fft_lib_initialized = false;
      33              : 
      34              : /*******************************************************************************
      35              :  * \brief Start an FFT timer from a printf-style label.
      36              :  ******************************************************************************/
      37     38487760 : static int fft_timer_start(const char *format, ...) {
      38     38487760 :   char routine_name[FFT_MAX_STRING_LENGTH + 1];
      39     38487760 :   va_list arguments;
      40     38487760 :   va_start(arguments, format);
      41     38487760 :   vsnprintf(routine_name, sizeof(routine_name), format, arguments);
      42     38487760 :   va_end(arguments);
      43     38487760 :   return fft_start_timer(routine_name);
      44              : }
      45              : 
      46              : /*******************************************************************************
      47              :  * \brief Forward a void FFT call to the selected backend.
      48              :  ******************************************************************************/
      49              : #define FFT_DISPATCH_VOID(gpu_call, fftw_call)                                 \
      50              :   do {                                                                         \
      51              :     switch (fft_lib_choice) {                                                  \
      52              :     case FFT_LIB_GPU:                                                          \
      53              :       gpu_call;                                                                \
      54              :       break;                                                                   \
      55              :     case FFT_LIB_FFTW:                                                         \
      56              :       fftw_call;                                                               \
      57              :       break;                                                                   \
      58              :     default:                                                                   \
      59              :       cp_assert(0 && "Unknown FFT library.");                                  \
      60              :     }                                                                          \
      61              :   } while (0)
      62              : 
      63              : /*******************************************************************************
      64              :  * \brief Initialize the accelerated FFT library.
      65              :  * \author Frederick Stein
      66              :  ******************************************************************************/
      67            4 : int fft_init_acc_lib() {
      68              : #if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
      69              :   fft_gpu_init();
      70              :   return 0;
      71              : #else
      72            4 :   return 1;
      73              : #endif
      74              : }
      75              : 
      76              : /*******************************************************************************
      77              :  * \brief Initialize the FFT library (if not done externally).
      78              :  * \param lib FFT backend to use.
      79              :  * \param fftw_planning_flag FFTW planning mode.
      80              :  * \param use_guru_interface Whether the FFTW Guru interface may be used.
      81              :  * \param wisdom_file Path to the FFTW wisdom file.
      82              :  * \author Frederick Stein
      83              :  ******************************************************************************/
      84        11947 : int fft_init_lib(const fft_lib lib, const int fftw_planning_flag,
      85              :                  const bool use_guru_interface, const char *wisdom_file) {
      86        11947 :   if (fft_lib_initialized) {
      87              :     return 0;
      88              :   }
      89        11500 :   fft_lib_initialized = true;
      90        11500 :   if (lib != FFT_LIB_DEFAULT)
      91           64 :     fft_lib_choice = lib;
      92        11500 :   int status = 1;
      93        11500 :   switch (fft_lib_choice) {
      94        11496 :   case FFT_LIB_FFTW:
      95        11496 :     status =
      96        11496 :         fft_fftw_init_lib(fftw_planning_flag, use_guru_interface, wisdom_file);
      97              : #if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
      98              :     // Distributed FFTs always use the GPU backend, so it must be initialized
      99              :     // even when FFTW3 is selected for the local FFTs.
     100              :     if (status == 0) {
     101              :       status = fft_init_acc_lib();
     102              :     }
     103              : #endif
     104        11496 :     break;
     105            4 :   case FFT_LIB_GPU:
     106            4 :     status = fft_init_acc_lib();
     107            4 :     break;
     108              :   default:
     109            0 :     cp_assert(0 && "Unknown FFT library.");
     110              :   }
     111        11500 :   if (status != 0) {
     112            4 :     fft_finalize_lib(NULL);
     113            4 :     return status;
     114              :   }
     115        11496 :   fft_init_timer();
     116        11496 :   return status;
     117              : }
     118              : 
     119              : /*******************************************************************************
     120              :  * \brief Finalize the accelerated FFT library.
     121              :  * \author Frederick Stein
     122              :  ******************************************************************************/
     123        11729 : void fft_finalize_acc_lib() {
     124              : #if defined(__OFFLOAD) && !defined(__NO_OFFLOAD_FFT)
     125              :   fft_gpu_finalize();
     126              : #endif
     127        11729 : }
     128              : 
     129              : /*******************************************************************************
     130              :  * \brief Finalize the FFT library (if not done externally).
     131              :  * \param wisdom_file Path to the FFTW wisdom file.
     132              :  * \author Frederick Stein
     133              :  ******************************************************************************/
     134        11747 : void fft_finalize_lib(const char *wisdom_file) {
     135        11747 :   fft_fftw_finalize_lib(wisdom_file);
     136        11747 :   fft_finalize_acc_lib();
     137        11747 :   fft_lib_initialized = false;
     138        11747 : }
     139              : 
     140              : /*******************************************************************************
     141              :  * \brief Get the default library (GPU if offloading was enabled, else FFTW3).
     142              :  * \author Frederick Stein
     143              :  ******************************************************************************/
     144            2 : int fft_lib_default_library() { return fft_lib_default; }
     145              : 
     146              : /*******************************************************************************
     147              :  * \brief Whether a compound MPI implementation is available.
     148              :  * \author Frederick Stein
     149              :  ******************************************************************************/
     150        11915 : int fft_lib_backend_in_use() { return fft_lib_choice; }
     151              : 
     152              : /*******************************************************************************
     153              :  * \brief Whether a compound MPI implementation is available.
     154              :  * \author Frederick Stein
     155              :  ******************************************************************************/
     156        11919 : bool fft_lib_has_guru_interface() {
     157        11919 :   switch (fft_lib_choice) {
     158        11919 :   case FFT_LIB_FFTW:
     159        11919 :     return fft_fftw_lib_has_guru_interface();
     160              :   case FFT_LIB_GPU:
     161              :     return false;
     162              :   default:
     163            0 :     cp_assert(0 && "Unknown FFT library.");
     164              :     return false;
     165              :   }
     166              : }
     167              : 
     168              : /*******************************************************************************
     169              :  * \brief Allocate buffer of type double.
     170              :  * \param length Number of elements.
     171              :  * \param buffer Buffer pointer.
     172              :  * \author Frederick Stein
     173              :  ******************************************************************************/
     174          176 : void fft_allocate_double(const int length, double **buffer) {
     175          176 :   FFT_DISPATCH_VOID((fft_gpu_allocate_double(length, buffer)),
     176              :                     (fft_fftw_allocate_double(length, buffer)));
     177          176 : }
     178              : 
     179              : /*******************************************************************************
     180              :  * \brief Allocate buffer of type double complex.
     181              :  * \param length Number of elements.
     182              :  * \param buffer Buffer pointer.
     183              :  * \author Frederick Stein
     184              :  ******************************************************************************/
     185       228114 : void fft_allocate_complex(const int length, double complex **buffer) {
     186       228114 :   FFT_DISPATCH_VOID((fft_gpu_allocate_complex(imax(1, length), buffer)),
     187              :                     (fft_fftw_allocate_complex(imax(1, length), buffer)));
     188       228114 : }
     189              : 
     190              : /*******************************************************************************
     191              :  * \brief Allocate buffer of type double.
     192              :  * \param buffer Buffer pointer.
     193              :  * \author Frederick Stein
     194              :  ******************************************************************************/
     195          176 : void fft_free_double(double *buffer) {
     196          176 :   if (fft_lib_choice == FFT_LIB_FFTW) {
     197          176 :     fft_fftw_free_double(buffer);
     198            0 :   } else if (fft_lib_choice == FFT_LIB_GPU) {
     199            0 :     fft_gpu_free_double(buffer);
     200              :   } else {
     201            0 :     cp_assert(0 && "Unknown FFT library.");
     202              :   }
     203          176 : }
     204              : 
     205              : /*******************************************************************************
     206              :  * \brief Allocate buffer of type double complex.
     207              :  * \param buffer Buffer pointer.
     208              :  * \author Frederick Stein
     209              :  ******************************************************************************/
     210       228114 : void fft_free_complex(double complex *buffer) {
     211       228114 :   if (fft_lib_choice == FFT_LIB_FFTW) {
     212       228114 :     fft_fftw_free_complex(buffer);
     213            0 :   } else if (fft_lib_choice == FFT_LIB_GPU) {
     214            0 :     fft_gpu_free_complex(buffer);
     215              :   } else {
     216            0 :     cp_assert(0 && "Unknown FFT library.");
     217              :   }
     218       228114 : }
     219              : 
     220              : /*******************************************************************************
     221              :  * \brief Register a local 1D C2C FFT.
     222              :  * \param dir FFT direction (forward or backward).
     223              :  * \param fft_size Size of the transform in each dimension.
     224              :  * \param number_of_ffts Number of independent (batched) transforms.
     225              :  * \param transpose_in Whether the input array uses the transposed layout.
     226              :  * \param transpose_out Whether the output array uses the transposed layout.
     227              :  * \param leading_dimension_in Leading dimension of the input array.
     228              :  * \param leading_dimension_out Leading dimension of the output array.
     229              :  * \param grid_in Input grid buffer.
     230              :  * \param grid_out Output grid buffer.
     231              :  * \author Frederick Stein
     232              :  ******************************************************************************/
     233       343704 : void fft_register_1d_local(const bool dir, const int fft_size,
     234              :                            const int number_of_ffts, const bool transpose_in,
     235              :                            const bool transpose_out,
     236              :                            const int leading_dimension_in,
     237              :                            const int leading_dimension_out,
     238              :                            double complex *grid_in, double complex *grid_out) {
     239       343704 :   const int handle = fft_timer_start("register_1d_local");
     240       860905 :   const int handle2 = fft_timer_start(
     241              :       "register_1d_l_%s_%s_%i_%i", dir ? "fw" : "bw",
     242              :       grid_in == grid_out ? "i" : "o", fft_size, number_of_ffts);
     243       343704 :   FFT_DISPATCH_VOID(
     244              :       (fft_gpu_register_1d_local(dir, fft_size, number_of_ffts, transpose_in,
     245              :                                  transpose_out, leading_dimension_in,
     246              :                                  leading_dimension_out, grid_in == grid_out)),
     247              :       (fft_fftw_register_1d_local(dir, fft_size, number_of_ffts, transpose_in,
     248              :                                   transpose_out, leading_dimension_in,
     249              :                                   leading_dimension_out, grid_in, grid_out)));
     250       343704 :   fft_stop_timer(handle2);
     251       343704 :   fft_stop_timer(handle);
     252       343704 : }
     253              : 
     254              : /*******************************************************************************
     255              :  * \brief Register a local 1D R2C FFT.
     256              :  * \param fft_size Size of the transform in each dimension.
     257              :  * \param number_of_ffts Number of independent (batched) transforms.
     258              :  * \param transpose_in Whether the input array uses the transposed layout.
     259              :  * \param transpose_out Whether the output array uses the transposed layout.
     260              :  * \param leading_dimension_in Leading dimension of the input array.
     261              :  * \param leading_dimension_out Leading dimension of the output array.
     262              :  * \param grid_in Input grid buffer.
     263              :  * \param grid_out Output grid buffer.
     264              :  * \author Frederick Stein
     265              :  ******************************************************************************/
     266           56 : void fft_register_1d_r2c_local(const int fft_size, const int number_of_ffts,
     267              :                                const bool transpose_in,
     268              :                                const bool transpose_out,
     269              :                                const int leading_dimension_in,
     270              :                                const int leading_dimension_out, double *grid_in,
     271              :                                double complex *grid_out) {
     272           56 :   const int handle = fft_timer_start("register_1d_r2c_local");
     273           96 :   const int handle2 = fft_timer_start("register_1d_r2c_l_%s_%i_%i",
     274              :                                       grid_in == (double *)grid_out ? "i" : "o",
     275              :                                       fft_size, number_of_ffts);
     276           56 :   FFT_DISPATCH_VOID(
     277              :       (fft_gpu_register_1d_r2c_local(
     278              :           true, fft_size, number_of_ffts, transpose_in, transpose_out,
     279              :           leading_dimension_in, leading_dimension_out,
     280              :           grid_in == (double *)grid_out)),
     281              :       (fft_fftw_register_1d_r2c_local(
     282              :           fft_size, number_of_ffts, transpose_in, transpose_out,
     283              :           leading_dimension_in, leading_dimension_out, grid_in, grid_out)));
     284           56 :   fft_stop_timer(handle2);
     285           56 :   fft_stop_timer(handle);
     286           56 : }
     287              : 
     288              : /*******************************************************************************
     289              :  * \brief Register a local 1D C2R FFT.
     290              :  * \param fft_size Size of the transform in each dimension.
     291              :  * \param number_of_ffts Number of independent (batched) transforms.
     292              :  * \param transpose_in Whether the input array uses the transposed layout.
     293              :  * \param transpose_out Whether the output array uses the transposed layout.
     294              :  * \param leading_dimension_in Leading dimension of the input array.
     295              :  * \param leading_dimension_out Leading dimension of the output array.
     296              :  * \param grid_in Input grid buffer.
     297              :  * \param grid_out Output grid buffer.
     298              :  * \author Frederick Stein
     299              :  ******************************************************************************/
     300           56 : void fft_register_1d_c2r_local(const int fft_size, const int number_of_ffts,
     301              :                                const bool transpose_in,
     302              :                                const bool transpose_out,
     303              :                                const int leading_dimension_in,
     304              :                                const int leading_dimension_out,
     305              :                                double complex *grid_in, double *grid_out) {
     306           56 :   const int handle = fft_timer_start("register_1d_c2r_local");
     307           96 :   const int handle2 = fft_timer_start("register_1d_c2r_l_%s_%i_%i",
     308              :                                       (double *)grid_in == grid_out ? "i" : "o",
     309              :                                       fft_size, number_of_ffts);
     310           56 :   FFT_DISPATCH_VOID(
     311              :       (fft_gpu_register_1d_r2c_local(
     312              :           false, fft_size, number_of_ffts, transpose_in, transpose_out,
     313              :           leading_dimension_in, leading_dimension_out,
     314              :           grid_in == (double complex *)grid_out)),
     315              :       (fft_fftw_register_1d_c2r_local(
     316              :           fft_size, number_of_ffts, transpose_in, transpose_out,
     317              :           leading_dimension_in, leading_dimension_out, grid_in, grid_out)));
     318           56 :   fft_stop_timer(handle2);
     319           56 :   fft_stop_timer(handle);
     320           56 : }
     321              : 
     322              : /*******************************************************************************
     323              :  * \brief Register a local 2D FFT.
     324              :  * \param dir FFT direction (forward or backward).
     325              :  * \param fft_size Size of the transform in each dimension.
     326              :  * \param number_of_ffts Number of independent (batched) transforms.
     327              :  * \param transpose_in Whether the input array uses the transposed layout.
     328              :  * \param transpose_out Whether the output array uses the transposed layout.
     329              :  * \param grid_in Input grid buffer.
     330              :  * \param grid_out Output grid buffer.
     331              :  * \author Frederick Stein
     332              :  ******************************************************************************/
     333        72080 : void fft_register_2d_local(const bool dir, const int fft_size[2],
     334              :                            const int number_of_ffts, const bool transpose_in,
     335              :                            const bool transpose_out, double complex *grid_in,
     336              :                            double complex *grid_out) {
     337        72080 :   const int handle = fft_timer_start("register_2d_local");
     338        72080 :   const int handle2 =
     339       180160 :       fft_timer_start("register_2d_l_%s_%s_%i_%i_%i", dir ? "fw" : "bw",
     340              :                       grid_in == grid_out ? "i" : "o", fft_size[0], fft_size[1],
     341              :                       number_of_ffts);
     342        72080 :   FFT_DISPATCH_VOID(
     343              :       (fft_gpu_register_2d_local(dir, fft_size, number_of_ffts, transpose_in,
     344              :                                  transpose_out, grid_in == grid_out)),
     345              :       (fft_fftw_register_2d_local(dir, fft_size, number_of_ffts, transpose_in,
     346              :                                   transpose_out, grid_in, grid_out)));
     347        72080 :   fft_stop_timer(handle2);
     348        72080 :   fft_stop_timer(handle);
     349        72080 : }
     350              : 
     351              : /*******************************************************************************
     352              :  * \brief Register a local 2D R2C FFT.
     353              :  * \param fft_size Size of the transform in each dimension.
     354              :  * \param number_of_ffts Number of independent (batched) transforms.
     355              :  * \param transpose_in Whether the input array uses the transposed layout.
     356              :  * \param transpose_out Whether the output array uses the transposed layout.
     357              :  * \param grid_in Input grid buffer.
     358              :  * \param grid_out Output grid buffer.
     359              :  * \author Frederick Stein
     360              :  ******************************************************************************/
     361           56 : void fft_register_2d_r2c_local(const int fft_size[2], const int number_of_ffts,
     362              :                                const bool transpose_in,
     363              :                                const bool transpose_out, double *grid_in,
     364              :                                double complex *grid_out) {
     365           56 :   const int handle = fft_timer_start("register_2d_r2c_local");
     366           96 :   const int handle2 = fft_timer_start("register_2d_r2c_l_%s_%i_%i_%i",
     367              :                                       grid_in == (double *)grid_out ? "i" : "o",
     368              :                                       fft_size[0], fft_size[1], number_of_ffts);
     369           56 :   FFT_DISPATCH_VOID(
     370              :       (fft_gpu_register_2d_r2c_local(true, fft_size, number_of_ffts,
     371              :                                      transpose_in, transpose_out,
     372              :                                      grid_in == (double *)grid_out)),
     373              :       (fft_fftw_register_2d_r2c_local(fft_size, number_of_ffts, transpose_in,
     374              :                                       transpose_out, grid_in, grid_out)));
     375           56 :   fft_stop_timer(handle2);
     376           56 :   fft_stop_timer(handle);
     377           56 : }
     378              : 
     379              : /*******************************************************************************
     380              :  * \brief Register a local 2D C2R FFT.
     381              :  * \param fft_size Size of the transform in each dimension.
     382              :  * \param number_of_ffts Number of independent (batched) transforms.
     383              :  * \param transpose_in Whether the input array uses the transposed layout.
     384              :  * \param transpose_out Whether the output array uses the transposed layout.
     385              :  * \param grid_in Input grid buffer.
     386              :  * \param grid_out Output grid buffer.
     387              :  * \author Frederick Stein
     388              :  ******************************************************************************/
     389           56 : void fft_register_2d_c2r_local(const int fft_size[2], const int number_of_ffts,
     390              :                                const bool transpose_in,
     391              :                                const bool transpose_out,
     392              :                                double complex *grid_in, double *grid_out) {
     393           56 :   const int handle = fft_timer_start("register_2d_c2r_local");
     394           96 :   const int handle2 = fft_timer_start("register_2d_c2r_l_%s_%i_%i_%i",
     395              :                                       (double *)grid_in == grid_out ? "i" : "o",
     396              :                                       fft_size[0], fft_size[1], number_of_ffts);
     397           56 :   FFT_DISPATCH_VOID(
     398              :       (fft_gpu_register_2d_r2c_local(false, fft_size, number_of_ffts,
     399              :                                      transpose_in, transpose_out,
     400              :                                      grid_in == (double complex *)grid_out)),
     401              :       (fft_fftw_register_2d_c2r_local(fft_size, number_of_ffts, transpose_in,
     402              :                                       transpose_out, grid_in, grid_out)));
     403           56 :   fft_stop_timer(handle2);
     404           56 :   fft_stop_timer(handle);
     405           56 : }
     406              : 
     407              : /*******************************************************************************
     408              :  * \brief Register a local 3D FFT.
     409              :  * \note fft_3d_bw_local(grid_gs, grid_rs, n) is the reverse to
     410              :  * fft_3d_rw_local(grid_rs, grid_gs, n) (ignoring normalization).
     411              :  * \param dir FFT direction (forward or backward).
     412              :  * \param fft_size Size of the transform in each dimension.
     413              :  * \param number_of_ffts Number of independent (batched) transforms.
     414              :  * \param transpose_in Whether the input array uses the transposed layout.
     415              :  * \param transpose_out Whether the output array uses the transposed layout.
     416              :  * \param grid_in Input grid buffer.
     417              :  * \param grid_out Output grid buffer.
     418              :  * \author Frederick Stein
     419              :  ******************************************************************************/
     420        17116 : void fft_register_3d_local(const bool dir, const int fft_size[3],
     421              :                            const int number_of_ffts, const bool transpose_in,
     422              :                            const bool transpose_out, double complex *grid_in,
     423              :                            double complex *grid_out) {
     424        17116 :   const int handle = fft_timer_start("register_3d_local");
     425        34240 :   const int handle2 = fft_timer_start(
     426              :       "register_3d_l_%s_%s_%i_%i_%i", dir ? "fw" : "bw",
     427              :       grid_in == grid_out ? "i" : "o", fft_size[0], fft_size[1], fft_size[2]);
     428        17116 :   FFT_DISPATCH_VOID(
     429              :       (fft_gpu_register_3d_local(dir, fft_size, grid_in == grid_out,
     430              :                                  number_of_ffts, transpose_in, transpose_out)),
     431              :       (fft_fftw_register_3d_local(dir, fft_size, number_of_ffts, transpose_in,
     432              :                                   transpose_out, grid_in, grid_out)));
     433        17116 :   fft_stop_timer(handle2);
     434        17116 :   fft_stop_timer(handle);
     435        17116 : }
     436              : 
     437              : /*******************************************************************************
     438              :  * \brief Register a local 3D R2C FFT.
     439              :  * \param fft_size Size of the transform in each dimension.
     440              :  * \param number_of_ffts Number of independent (batched) transforms.
     441              :  * \param transpose_in Whether the input array uses the transposed layout.
     442              :  * \param transpose_out Whether the output array uses the transposed layout.
     443              :  * \param grid_in Input grid buffer.
     444              :  * \param grid_out Output grid buffer.
     445              :  * \author Frederick Stein
     446              :  ******************************************************************************/
     447           40 : void fft_register_3d_r2c_local(const int fft_size[3], const int number_of_ffts,
     448              :                                const bool transpose_in,
     449              :                                const bool transpose_out, double *grid_in,
     450              :                                double complex *grid_out) {
     451           40 :   const int handle = fft_timer_start("register_3d_r2c_local");
     452           64 :   const int handle2 = fft_timer_start("register_3d_r2c_l_%s_%i_%i_%i",
     453              :                                       grid_in == (double *)grid_out ? "i" : "o",
     454              :                                       fft_size[0], fft_size[1], fft_size[2]);
     455           40 :   FFT_DISPATCH_VOID(
     456              :       (fft_gpu_register_3d_r2c_local(
     457              :           true, fft_size, grid_in == (double *)grid_out, number_of_ffts,
     458              :           transpose_in, transpose_out)),
     459              :       (fft_fftw_register_3d_r2c_local(fft_size, number_of_ffts, transpose_in,
     460              :                                       transpose_out, grid_in, grid_out)));
     461           40 :   fft_stop_timer(handle2);
     462           40 :   fft_stop_timer(handle);
     463           40 : }
     464              : 
     465              : /*******************************************************************************
     466              :  * \brief Register a local 3D C2R FFT.
     467              :  * \param fft_size Size of the transform in each dimension.
     468              :  * \param number_of_ffts Number of independent (batched) transforms.
     469              :  * \param transpose_in Whether the input array uses the transposed layout.
     470              :  * \param transpose_out Whether the output array uses the transposed layout.
     471              :  * \param grid_in Input grid buffer.
     472              :  * \param grid_out Output grid buffer.
     473              :  * \author Frederick Stein
     474              :  ******************************************************************************/
     475           40 : void fft_register_3d_c2r_local(const int fft_size[3], const int number_of_ffts,
     476              :                                const bool transpose_in,
     477              :                                const bool transpose_out,
     478              :                                double complex *grid_in, double *grid_out) {
     479           40 :   const int handle = fft_timer_start("register_3d_c2r_local");
     480           64 :   const int handle2 = fft_timer_start("register_3d_c2r_l_%s_%i_%i_%i",
     481              :                                       (double *)grid_in == grid_out ? "i" : "o",
     482              :                                       fft_size[0], fft_size[1], fft_size[2]);
     483           40 :   FFT_DISPATCH_VOID(
     484              :       (fft_gpu_register_3d_r2c_local(
     485              :           false, fft_size, grid_in == (double complex *)grid_out,
     486              :           number_of_ffts, transpose_in, transpose_out)),
     487              :       (fft_fftw_register_3d_c2r_local(fft_size, number_of_ffts, transpose_in,
     488              :                                       transpose_out, grid_in, grid_out)));
     489           40 :   fft_stop_timer(handle2);
     490           40 :   fft_stop_timer(handle);
     491           40 : }
     492              : 
     493              : /*******************************************************************************
     494              :  * \brief Perform a local 1D FFT.
     495              :  * \param dir FFT direction (forward or backward).
     496              :  * \param fft_size Size of the transform in each dimension.
     497              :  * \param number_of_ffts Number of independent (batched) transforms.
     498              :  * \param transpose_in Whether the input array uses the transposed layout.
     499              :  * \param transpose_out Whether the output array uses the transposed layout.
     500              :  * \param leading_dimension_in Leading dimension of the input array.
     501              :  * \param leading_dimension_out Leading dimension of the output array.
     502              :  * \param grid_in Input grid buffer.
     503              :  * \param grid_out Output grid buffer.
     504              :  * \author Frederick Stein
     505              :  ******************************************************************************/
     506     14403159 : void fft_1d_local(const bool dir, const int fft_size, const int number_of_ffts,
     507              :                   const bool transpose_in, const bool transpose_out,
     508              :                   const int leading_dimension_in,
     509              :                   const int leading_dimension_out, double complex *grid_in,
     510              :                   double complex *grid_out) {
     511     14403159 :   const int handle = fft_timer_start("1d_local");
     512     36156100 :   const int handle2 = fft_timer_start("1d_l_%s_%s_%i_%i", dir ? "fw" : "bw",
     513              :                                       grid_in == grid_out ? "i" : "o", fft_size,
     514              :                                       number_of_ffts);
     515     14403159 :   FFT_DISPATCH_VOID(
     516              :       (fft_gpu_1d_local((const double *)grid_in, (double *)grid_out, dir,
     517              :                         fft_size, number_of_ffts, transpose_in, transpose_out,
     518              :                         leading_dimension_in, leading_dimension_out)),
     519              :       (fft_fftw_1d_local(dir, fft_size, number_of_ffts, transpose_in,
     520              :                          transpose_out, leading_dimension_in,
     521              :                          leading_dimension_out, grid_in, grid_out)));
     522     14403159 :   fft_stop_timer(handle2);
     523     14403159 :   fft_stop_timer(handle);
     524     14403159 : }
     525              : 
     526              : /*******************************************************************************
     527              :  * \brief Perform a local 1D R2C FFT.
     528              :  * \param fft_size Size of the transform in each dimension.
     529              :  * \param number_of_ffts Number of independent (batched) transforms.
     530              :  * \param transpose_in Whether the input array uses the transposed layout.
     531              :  * \param transpose_out Whether the output array uses the transposed layout.
     532              :  * \param leading_dimension_in Leading dimension of the input array.
     533              :  * \param leading_dimension_out Leading dimension of the output array.
     534              :  * \param grid_in Input grid buffer.
     535              :  * \param grid_out Output grid buffer.
     536              :  * \author Frederick Stein
     537              :  ******************************************************************************/
     538           56 : void fft_1d_r2c_local(const int fft_size, const int number_of_ffts,
     539              :                       const bool transpose_in, const bool transpose_out,
     540              :                       const int leading_dimension_in,
     541              :                       const int leading_dimension_out, double *grid_in,
     542              :                       double complex *grid_out) {
     543           56 :   const int handle = fft_timer_start("1d_r2c_local");
     544           96 :   const int handle2 = fft_timer_start("1d_r2c_l_%s_%i_%i",
     545              :                                       grid_in == (double *)grid_out ? "i" : "o",
     546              :                                       fft_size, number_of_ffts);
     547           56 :   FFT_DISPATCH_VOID(
     548              :       (fft_gpu_1d_r2c_local((const double *)grid_in, (double *)grid_out, true,
     549              :                             fft_size, number_of_ffts, transpose_in,
     550              :                             transpose_out, leading_dimension_in,
     551              :                             leading_dimension_out)),
     552              :       (fft_fftw_1d_r2c_local(fft_size, number_of_ffts, transpose_in,
     553              :                              transpose_out, leading_dimension_in,
     554              :                              leading_dimension_out, grid_in, grid_out)));
     555           56 :   fft_stop_timer(handle2);
     556           56 :   fft_stop_timer(handle);
     557           56 : }
     558              : 
     559              : /*******************************************************************************
     560              :  * \brief Perform a local 1D C2R FFT.
     561              :  * \param fft_size Size of the transform in each dimension.
     562              :  * \param number_of_ffts Number of independent (batched) transforms.
     563              :  * \param transpose_in Whether the input array uses the transposed layout.
     564              :  * \param transpose_out Whether the output array uses the transposed layout.
     565              :  * \param leading_dimension_in Leading dimension of the input array.
     566              :  * \param leading_dimension_out Leading dimension of the output array.
     567              :  * \param grid_in Input grid buffer.
     568              :  * \param grid_out Output grid buffer.
     569              :  * \author Frederick Stein
     570              :  ******************************************************************************/
     571           56 : void fft_1d_c2r_local(const int fft_size, const int number_of_ffts,
     572              :                       const bool transpose_in, const bool transpose_out,
     573              :                       const int leading_dimension_in,
     574              :                       const int leading_dimension_out, double complex *grid_in,
     575              :                       double *grid_out) {
     576           56 :   const int handle = fft_timer_start("1d_c2r_local");
     577           96 :   const int handle2 = fft_timer_start("1d_c2r_l_%s_%i_%i",
     578              :                                       (double *)grid_in == grid_out ? "i" : "o",
     579              :                                       fft_size, number_of_ffts);
     580           56 :   FFT_DISPATCH_VOID(
     581              :       (fft_gpu_1d_r2c_local((const double *)grid_in, (double *)grid_out, false,
     582              :                             fft_size, number_of_ffts, transpose_in,
     583              :                             transpose_out, leading_dimension_in,
     584              :                             leading_dimension_out)),
     585              :       (fft_fftw_1d_c2r_local(fft_size, number_of_ffts, transpose_in,
     586              :                              transpose_out, leading_dimension_in,
     587              :                              leading_dimension_out, grid_in, grid_out)));
     588           56 :   fft_stop_timer(handle2);
     589           56 :   fft_stop_timer(handle);
     590           56 : }
     591              : 
     592              : /*******************************************************************************
     593              :  * \brief Perform a local 2D FFT.
     594              :  * \param dir FFT direction (forward or backward).
     595              :  * \param fft_size Size of the transform in each dimension.
     596              :  * \param number_of_ffts Number of independent (batched) transforms.
     597              :  * \param transpose_in Whether the input array uses the transposed layout.
     598              :  * \param transpose_out Whether the output array uses the transposed layout.
     599              :  * \param grid_in Input grid buffer.
     600              :  * \param grid_out Output grid buffer.
     601              :  * \author Frederick Stein
     602              :  ******************************************************************************/
     603      3746414 : void fft_2d_local(const bool dir, const int fft_size[2],
     604              :                   const int number_of_ffts, const bool transpose_in,
     605              :                   const bool transpose_out, double complex *grid_in,
     606              :                   double complex *grid_out) {
     607      3746414 :   const int handle = fft_timer_start("2d_local");
     608      9367882 :   const int handle2 = fft_timer_start("2d_l_%s_%s_%i_%i_%i", dir ? "fw" : "bw",
     609              :                                       grid_in == grid_out ? "i" : "o",
     610              :                                       fft_size[0], fft_size[1], number_of_ffts);
     611      3746414 :   FFT_DISPATCH_VOID(
     612              :       (fft_gpu_2d_local((const double *)grid_in, (double *)grid_out, dir,
     613              :                         fft_size, number_of_ffts, transpose_in, transpose_out)),
     614              :       (fft_fftw_2d_local(dir, fft_size, number_of_ffts, transpose_in,
     615              :                          transpose_out, grid_in, grid_out)));
     616      3746414 :   fft_stop_timer(handle2);
     617      3746414 :   fft_stop_timer(handle);
     618      3746414 : }
     619              : 
     620              : /*******************************************************************************
     621              :  * \brief Perform a local 2D R2C FFT.
     622              :  * \param fft_size Size of the transform in each dimension.
     623              :  * \param number_of_ffts Number of independent (batched) transforms.
     624              :  * \param transpose_in Whether the input array uses the transposed layout.
     625              :  * \param transpose_out Whether the output array uses the transposed layout.
     626              :  * \param grid_in Input grid buffer.
     627              :  * \param grid_out Output grid buffer.
     628              :  * \author Frederick Stein
     629              :  ******************************************************************************/
     630           56 : void fft_2d_r2c_local(const int fft_size[2], const int number_of_ffts,
     631              :                       const bool transpose_in, const bool transpose_out,
     632              :                       double *grid_in, double complex *grid_out) {
     633           56 :   const int handle = fft_timer_start("2d_r2c_local");
     634           96 :   const int handle2 = fft_timer_start("2d_r2c_l_%s_%i_%i_%i",
     635              :                                       grid_in == (double *)grid_out ? "i" : "o",
     636              :                                       fft_size[0], fft_size[1], number_of_ffts);
     637           56 :   FFT_DISPATCH_VOID(
     638              :       (fft_gpu_2d_r2c_local((const double *)grid_in, (double *)grid_out, true,
     639              :                             fft_size, number_of_ffts, transpose_in,
     640              :                             transpose_out)),
     641              :       (fft_fftw_2d_r2c_local(fft_size, number_of_ffts, transpose_in,
     642              :                              transpose_out, grid_in, grid_out)));
     643           56 :   fft_stop_timer(handle2);
     644           56 :   fft_stop_timer(handle);
     645           56 : }
     646              : 
     647              : /*******************************************************************************
     648              :  * \brief Perform a local 2D C2R FFT.
     649              :  * \param fft_size Size of the transform in each dimension.
     650              :  * \param number_of_ffts Number of independent (batched) transforms.
     651              :  * \param transpose_in Whether the input array uses the transposed layout.
     652              :  * \param transpose_out Whether the output array uses the transposed layout.
     653              :  * \param grid_in Input grid buffer.
     654              :  * \param grid_out Output grid buffer.
     655              :  * \author Frederick Stein
     656              :  ******************************************************************************/
     657           56 : void fft_2d_c2r_local(const int fft_size[2], const int number_of_ffts,
     658              :                       const bool transpose_in, const bool transpose_out,
     659              :                       double complex *grid_in, double *grid_out) {
     660           56 :   const int handle = fft_timer_start("2d_c2r_local");
     661           96 :   const int handle2 = fft_timer_start("2d_c2r_l_%s_%i_%i_%i",
     662              :                                       (double *)grid_in == grid_out ? "i" : "o",
     663              :                                       fft_size[0], fft_size[1], number_of_ffts);
     664           56 :   FFT_DISPATCH_VOID(
     665              :       (fft_gpu_2d_r2c_local((const double *)grid_in, (double *)grid_out, false,
     666              :                             fft_size, number_of_ffts, transpose_in,
     667              :                             transpose_out)),
     668              :       (fft_fftw_2d_c2r_local(fft_size, number_of_ffts, transpose_in,
     669              :                              transpose_out, grid_in, grid_out)));
     670           56 :   fft_stop_timer(handle2);
     671           56 :   fft_stop_timer(handle);
     672           56 : }
     673              : 
     674              : /*******************************************************************************
     675              :  * \brief Perform a local 3D FFT.
     676              :  * \param dir FFT direction (forward or backward).
     677              :  * \param fft_size Size of the transform in each dimension.
     678              :  * \param number_of_ffts Number of independent (batched) transforms.
     679              :  * \param transpose_in Whether the input array uses the transposed layout.
     680              :  * \param transpose_out Whether the output array uses the transposed layout.
     681              :  * \param grid_in Input grid buffer.
     682              :  * \param grid_out Output grid buffer.
     683              :  * \author Frederick Stein
     684              :  ******************************************************************************/
     685       660799 : void fft_3d_local(const bool dir, const int fft_size[3],
     686              :                   const int number_of_ffts, const bool transpose_in,
     687              :                   const bool transpose_out, double complex *grid_in,
     688              :                   double complex *grid_out) {
     689       660799 :   const int handle = fft_timer_start("3d_local");
     690      1020643 :   const int handle2 = fft_timer_start("3d_l_%s_%s_%i_%i_%i", dir ? "fw" : "bw",
     691              :                                       grid_in == grid_out ? "i" : "o",
     692              :                                       fft_size[0], fft_size[1], fft_size[2]);
     693       660799 :   FFT_DISPATCH_VOID(
     694              :       (fft_gpu_3d_local((const double *)grid_in, (double *)grid_out, dir,
     695              :                         fft_size, number_of_ffts, transpose_in, transpose_out)),
     696              :       (fft_fftw_3d_local(dir, fft_size, number_of_ffts, transpose_in,
     697              :                          transpose_out, grid_in, grid_out)));
     698       660799 :   fft_stop_timer(handle2);
     699       660799 :   fft_stop_timer(handle);
     700       660799 : }
     701              : 
     702              : /*******************************************************************************
     703              :  * \brief Perform a local 3D R2C FFT.
     704              :  * \param fft_size Size of the transform in each dimension.
     705              :  * \param number_of_ffts Number of independent (batched) transforms.
     706              :  * \param transpose_in Whether the input array uses the transposed layout.
     707              :  * \param transpose_out Whether the output array uses the transposed layout.
     708              :  * \param grid_in Input grid buffer.
     709              :  * \param grid_out Output grid buffer.
     710              :  * \author Frederick Stein
     711              :  ******************************************************************************/
     712           40 : void fft_3d_r2c_local(const int fft_size[3], const int number_of_ffts,
     713              :                       const bool transpose_in, const bool transpose_out,
     714              :                       double *grid_in, double complex *grid_out) {
     715           40 :   const int handle = fft_timer_start("3d_r2c_local");
     716           64 :   const int handle2 = fft_timer_start("3d_r2c_l_%s_%i_%i_%i",
     717              :                                       grid_in == (double *)grid_out ? "i" : "o",
     718              :                                       fft_size[0], fft_size[1], fft_size[2]);
     719           40 :   FFT_DISPATCH_VOID(
     720              :       (fft_gpu_3d_r2c_local((const double *)grid_in, (double *)grid_out, true,
     721              :                             fft_size, number_of_ffts, transpose_in,
     722              :                             transpose_out)),
     723              :       (fft_fftw_3d_r2c_local(fft_size, number_of_ffts, transpose_in,
     724              :                              transpose_out, grid_in, grid_out)));
     725           40 :   fft_stop_timer(handle2);
     726           40 :   fft_stop_timer(handle);
     727           40 : }
     728              : 
     729              : /*******************************************************************************
     730              :  * \brief Perform a local 3D C2R FFT.
     731              :  * \param fft_size Size of the transform in each dimension.
     732              :  * \param number_of_ffts Number of independent (batched) transforms.
     733              :  * \param transpose_in Whether the input array uses the transposed layout.
     734              :  * \param transpose_out Whether the output array uses the transposed layout.
     735              :  * \param grid_in Input grid buffer.
     736              :  * \param grid_out Output grid buffer.
     737              :  * \author Frederick Stein
     738              :  ******************************************************************************/
     739           40 : void fft_3d_c2r_local(const int fft_size[3], const int number_of_ffts,
     740              :                       const bool transpose_in, const bool transpose_out,
     741              :                       double complex *grid_in, double *grid_out) {
     742           40 :   const int handle = fft_timer_start("3d_c2r_local");
     743           64 :   const int handle2 = fft_timer_start("3d_c2r_l_%s_%i_%i_%i",
     744              :                                       (double *)grid_in == grid_out ? "i" : "o",
     745              :                                       fft_size[0], fft_size[1], fft_size[2]);
     746           40 :   FFT_DISPATCH_VOID(
     747              :       (fft_gpu_3d_r2c_local((const double *)grid_in, (double *)grid_out, false,
     748              :                             fft_size, number_of_ffts, transpose_in,
     749              :                             transpose_out)),
     750              :       (fft_fftw_3d_c2r_local(fft_size, number_of_ffts, transpose_in,
     751              :                              transpose_out, grid_in, grid_out)));
     752           40 :   fft_stop_timer(handle2);
     753           40 :   fft_stop_timer(handle);
     754           40 : }
     755              : 
     756              : // EOF
        

Generated by: LCOV version 2.0-1