HipFFT3D.h 4.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef __OPENMM_HIPFFT3D_H__
#define __OPENMM_HIPFFT3D_H__

/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2009-2015 Stanford University and the Authors.      *
13
14
 * Portions copyright (c) 2021 Advanced Micro Devices, Inc.                   *
 * Authors:                                                                   *
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * Contributors:                                                              *
 *                                                                            *
 * This program is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU Lesser General Public License as published   *
 * by the Free Software Foundation, either version 3 of the License, or       *
 * (at your option) any later version.                                        *
 *                                                                            *
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU Lesser General Public License for more details.                        *
 *                                                                            *
 * You should have received a copy of the GNU Lesser General Public License   *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
 * -------------------------------------------------------------------------- */

#include "HipArray.h"

33
34
35
#define VKFFT_BACKEND 2 // HIP
#include "vkFFT.h"

36
37
namespace OpenMM {

38
39
class HipContext;

40
/**
41
42
 * This class performs three dimensional Fast Fourier Transforms using VkFFT by
 * Dmitrii Tolmachev (https://github.com/DTolm/VkFFT).
43
44
45
46
47
48
49
50
51
52
 * <p>
 * Note that this class performs an unnormalized transform.  That means that if you perform
 * a forward transform followed immediately by an inverse transform, the effect is to
 * multiply every value of the original data set by the total number of data points.
 */

class OPENMM_EXPORT_COMMON HipFFT3D {
public:
    /**
     * Create an HipFFT3D object for performing transforms of a particular size.
53
54
55
56
57
58
59
60
     * <p>
     * The transform cannot be done in-place: the input and output
     * arrays must be different.  Also, the input array is used as workspace, so its contents
     * are destroyed.  This also means that both arrays must be large enough to hold complex values,
     * even when performing a real-to-complex transform.
     * <p>
     * When performing a real-to-complex transform, the output data is of size xsize*ysize*(zsize/2+1)
     * and contains only the non-redundant elements.
61
62
63
64
65
66
     *
     * @param context the context in which to perform calculations
     * @param xsize   the first dimension of the data sets on which FFTs will be performed
     * @param ysize   the second dimension of the data sets on which FFTs will be performed
     * @param zsize   the third dimension of the data sets on which FFTs will be performed
     * @param realToComplex  if true, a real-to-complex transform will be done.  Otherwise, it is complex-to-complex.
67
68
69
     * @param stream  HIP stream
     * @param in      the data to transform, ordered such that in[x*ysize*zsize + y*zsize + z] contains element (x, y, z)
     * @param out     on exit, this contains the transformed data
70
     */
71
72
    HipFFT3D(HipContext& context, int xsize, int ysize, int zsize, bool realToComplex, hipStream_t stream, HipArray& in, HipArray& out);
    ~HipFFT3D();
73
    /**
74
     * Perform a Fourier transform.
75
76
77
     *
     * @param forward  true to perform a forward transform, false to perform an inverse transform
     */
78
    void execFFT(bool forward);
79
80
    /**
     * Get the smallest legal size for a dimension of the grid (that is, a size with no prime
81
82
     * factors other than 2, 3, 5, 7, 11, 13).  VkFFT supports arbitrary sizes but they may work
     * slower.
83
84
85
86
87
     *
     * @param minimum   the minimum size the return value must be greater than or equal to
     */
    static int findLegalDimension(int minimum);
private:
88
    hipStream_t stream;
89
    HipContext& context;
90
91
92
93
94
95
    int deviceIndex;
    void* inputBuffer;
    void* outputBuffer;
    uint64_t inputBufferSize;
    uint64_t outputBufferSize;
    VkFFTApplication* app;
96
97
98
99
100
};

} // namespace OpenMM

#endif // __OPENMM_HIPFFT3D_H__