Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor AnyFFT #1099

Merged
merged 12 commits into from
May 2, 2024
Merged

Conversation

AlexanderSinn
Copy link
Member

@AlexanderSinn AlexanderSinn commented Apr 17, 2024

In this PR, the functions that calculate a discrete sine transformation using an FFT are moved from AnyDST to the Poisson solvers.

This PR also fixes FFTDirichletExpanded for rocfft by setting the expanded position array (the FFT input) to zero after every FFT. Presumably, rocfft is using the array as work area. 

New AnyFFT interface:

struct VendorPlan;

enum struct FFTType {
    C2C_2D_fwd,
    C2C_2D_bkw,
    C2R_2D,
    R2C_2D,
    R2R_2D,
    C2R_1D_batched
};

struct AnyFFT {

    /** \brief Initialize an FFT plan for the requested transform type using a Vendor FFT library.
     * For 1D batched transforms, ny represents the number of batches to calculate at once.
     * This function returns the number of bytes of the work area needed for the FFT. The work area
     * has to be allocated by the function that uses the FFT and passed into SetBuffers.
     *
     * \param[in] type Type of FFT to perform
     * \param[in] nx Size of the contiguous dimension of the FFT
     * \param[in] ny Size of the second dimension of the FFT
     */
    std::size_t Initialize (FFTType type, int nx, int ny);

    /** \brief Set the pointers to the input, output and work area of the FFT.
     * This function has to be called after Initialize and before Execute.
     *
     * \param[in] in Pointer to the input of the FFT
     * \param[in] out Pointer to the output of the FFT
     * \param[in] work_area Pointer to the work area for the FFT
     */
    void SetBuffers (void* in, void* out, void* work_area);

    /** \brief Perform the initialized FFT */
    void Execute ();

    /** \brief Destructor to destroy the FFT plan */
    ~AnyFFT ();

    /** \brief Setup function that has to be called before any FFT plan is initialized. */
    static void setup ();

    /** \brief Cleanup function that has to be called at the end of the program. */
    static void cleanup ();

private:
    /** Vendor specific data for the FFT */
    VendorPlan* m_plan = nullptr;
};

Testing:

  • FFTW FFTDirichletDirect
  • FFTW FFTDirichletExpanded
  • FFTW FFTDirichletFast
  • FFTW FFTPeriodic
  • FFTW Laser FFT
  • cufft FFTDirichletExpanded
  • cufft FFTDirichletFast
  • cufft FFTPeriodic
  • cufft Laser FFT
  • rocfft FFTDirichletExpanded
  • rocfft FFTDirichletFast
  • rocfft FFTPeriodic
  • rocfft Laser FFT

@AlexanderSinn AlexanderSinn added component: fields About 3D fields and slices, field solvers etc. cleaning Code cleaning, avoid duplication, better naming, better style etc. labels Apr 17, 2024
@AlexanderSinn AlexanderSinn changed the title [WIP] Refactor AnyFFT Refactor AnyFFT Apr 22, 2024
Copy link
Member

@MaxThevenet MaxThevenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for this PR! This can be merged once the comments below are addressed.

Comment on lines +262 to +282
* ``FFTDirichletDirect`` Use the discrete sine transformation that is directly implemented
by FFTW to solve the Poisson equation with Dirichlet boundary conditions.
This option is only available when compiling for CPUs with FFTW.
Preferred resolution: :math:`2^N-1`.

* ``FFTDirichletExpanded`` Perform the discrete sine transformation by symmetrically
expanding the field to twice its size.
Preferred resolution: :math:`2^N-1`.

* ``FFTDirichletFast`` Perform the discrete sine transformation using a fast sine transform
algorithm that uses FFTs of the same size as the fields.
Preferred resolution: :math:`2^N-1`.

* ``MGDirichlet`` Use the HiPACE++ multigrid solver to solve the Poisson equation with
Dirichlet boundary conditions.
Preferred resolution: :math:`2^N` and :math:`2^N-1`.

* ``FFTPeriodic`` Use FFTs to solve the Poisson equation with Periodic boundary conditions.
Note that this does not work with features that change the boundary values,
like mesh refinement or open boundaries.
Preferred resolution: :math:`2^N`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice doc!

src/fields/fft_poisson_solver/fft/AnyFFT.H Outdated Show resolved Hide resolved
src/fields/fft_poisson_solver/fft/WrapCuFFT.cpp Outdated Show resolved Hide resolved
src/fields/fft_poisson_solver/fft/WrapRocFFT.cpp Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice improvement here too!

@AlexanderSinn AlexanderSinn requested a review from MaxThevenet May 2, 2024 19:03
@MaxThevenet MaxThevenet merged commit 34711d3 into Hi-PACE:development May 2, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleaning Code cleaning, avoid duplication, better naming, better style etc. component: fields About 3D fields and slices, field solvers etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants