More const correctness
[gromacs.git] / src / gromacs / ewald / pme-gpu-types-host.h
blobf74f90e53396d8586b0197bee527ee2ad6cb199b
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 /*! \libinternal \file
37 * \brief Defines the host-side PME GPU data structures.
38 * \todo Some renaming/refactoring, which does not impair the performance:
39 * -- bringing the function names up to guidelines
40 * -- PmeGpuSettings -> PmeGpuTasks
41 * -- refining GPU notation application (#2053)
42 * -- renaming coefficients to charges (?)
44 * \author Aleksei Iupinov <a.yupinov@gmail.com>
45 * \ingroup module_ewald
48 #ifndef GMX_EWALD_PME_GPU_TYPES_HOST_H
49 #define GMX_EWALD_PME_GPU_TYPES_HOST_H
51 #include "config.h"
53 #include <memory>
54 #include <vector>
56 #include "gromacs/ewald/pme.h"
57 #include "gromacs/gpu_utils/gpu_utils.h" // for GpuApiCallBehavior
58 #include "gromacs/gpu_utils/hostallocator.h"
59 #include "gromacs/math/vectypes.h"
61 #if GMX_GPU == GMX_GPU_CUDA
63 struct PmeGpuCuda;
64 /*! \brief A typedef for including the GPU host data by pointer */
65 typedef PmeGpuCuda PmeGpuSpecific;
67 struct PmeGpuCudaKernelParams;
68 /*! \brief A typedef for including the GPU kernel arguments data by pointer */
69 typedef PmeGpuCudaKernelParams PmeGpuKernelParams;
71 #else
73 /*! \brief A dummy typedef for the GPU host data placeholder on non-GPU builds */
74 typedef int PmeGpuSpecific;
75 /*! \brief A dummy typedef for the GPU kernel arguments data placeholder on non-GPU builds */
76 typedef int PmeGpuKernelParams;
78 #endif
80 struct gmx_device_info_t;
82 /*! \internal \brief
83 * The PME GPU settings structure, included in the main PME GPU structure by value.
85 struct PmeGpuSettings
87 /* Permanent settings set on initialization */
88 /*! \brief A boolean which tells if the solving is performed on GPU. Currently always true */
89 bool performGPUSolve;
90 /*! \brief A boolean which tells if the gathering is performed on GPU. Currently always true */
91 bool performGPUGather;
92 /*! \brief A boolean which tells if the FFT is performed on GPU. Currently true for a single MPI rank. */
93 bool performGPUFFT;
94 /*! \brief A convenience boolean which tells if PME decomposition is used. */
95 bool useDecomposition;
96 /*! \brief A boolean which tells if any PME GPU stage should copy all of its outputs to the host.
97 * Only intended to be used by the test framework.
99 bool copyAllOutputs;
100 /*! \brief An enum which tells whether most PME GPU D2H/H2D data transfers should be synchronous. */
101 GpuApiCallBehavior transferKind;
102 /*! \brief Various flags for the current PME computation, corresponding to the GMX_PME_ flags in pme.h. */
103 int currentFlags;
106 /*! \internal \brief
107 * The PME GPU intermediate buffers structure, included in the main PME GPU structure by value.
108 * Buffers are managed by the PME GPU module.
110 struct PmeGpuStaging
112 //! Host-side force buffer
113 std::vector < gmx::RVec, gmx::HostAllocator < gmx::RVec>> h_forces;
115 /*! \brief Virial and energy intermediate host-side buffer. Size is PME_GPU_VIRIAL_AND_ENERGY_COUNT. */
116 float *h_virialAndEnergy;
117 /*! \brief B-spline values intermediate host-side buffer. */
118 float *h_splineModuli;
120 /*! \brief Pointer to the host memory with B-spline values. Only used for host-side gather, or unit tests */
121 float *h_theta;
122 /*! \brief Pointer to the host memory with B-spline derivative values. Only used for host-side gather, or unit tests */
123 float *h_dtheta;
124 /*! \brief Pointer to the host memory with ivec atom gridline indices. Only used for host-side gather, or unit tests */
125 int *h_gridlineIndices;
128 /*! \internal \brief
129 * The PME GPU structure for all the data copied directly from the CPU PME structure.
130 * The copying is done when the CPU PME structure is already (re-)initialized
131 * (pme_gpu_reinit is called at the end of gmx_pme_init).
132 * All the variables here are named almost the same way as in gmx_pme_t.
133 * The types are different: pointers are replaced by vectors.
134 * TODO: use the shared data with the PME CPU.
135 * Included in the main PME GPU structure by value.
137 struct PmeShared
139 /*! \brief Grid count - currently always 1 on GPU */
140 int ngrids;
141 /*! \brief Grid dimensions - nkx, nky, nkz */
142 int nk[DIM];
143 /*! \brief PME interpolation order */
144 int pme_order;
145 /*! \brief Ewald splitting coefficient for Coulomb */
146 real ewaldcoeff_q;
147 /*! \brief Electrostatics parameter */
148 real epsilon_r;
149 /*! \brief Gridline indices - nnx, nny, nnz */
150 std::vector<int> nn;
151 /*! \brief Fractional shifts - fshx, fshy, fshz */
152 std::vector<real> fsh;
153 /*! \brief Precomputed B-spline values */
154 std::vector<real> bsp_mod[DIM];
155 /*! \brief The PME codepath being taken */
156 PmeRunMode runMode;
157 /*! \brief The box scaler based on inputrec - created in pme_init and managed by CPU structure */
158 class EwaldBoxZScaler *boxScaler;
159 /*! \brief The previous computation box to know if we even need to update the current box params.
160 * \todo Manage this on higher level.
161 * \todo Alternatively, when this structure is used by CPU PME code, make use of this field there as well.
163 matrix previousBox;
166 /*! \internal \brief
167 * The main PME GPU host structure, included in the PME CPU structure by pointer.
169 struct PmeGpu
171 /*! \brief The information copied once per reinit from the CPU structure. */
172 std::shared_ptr<PmeShared> common; // TODO: make the CPU structure use the same type
174 /*! \brief The settings. */
175 PmeGpuSettings settings;
177 /*! \brief The host-side buffers.
178 * The device-side buffers are buried in kernelParams, but that will have to change.
180 PmeGpuStaging staging;
182 /*! \brief Number of local atoms, padded to be divisible by PME_ATOM_DATA_ALIGNMENT.
183 * Used for kernel scheduling.
184 * kernelParams.atoms.nAtoms is the actual atom count to be used for data copying.
185 * TODO: this and the next member represent a memory allocation/padding properties -
186 * what a container type should do ideally.
188 int nAtomsPadded;
189 /*! \brief Number of local atoms, padded to be divisible by PME_ATOM_DATA_ALIGNMENT
190 * if c_usePadding is true.
191 * Used only as a basic size for almost all the atom data allocations
192 * (spline parameter data is also aligned by PME_SPREADGATHER_PARTICLES_PER_WARP).
193 * This should be the same as (c_usePadding ? nAtomsPadded : kernelParams.atoms.nAtoms).
194 * kernelParams.atoms.nAtoms is the actual atom count to be used for most data copying.
196 int nAtomsAlloc;
198 /*! \brief A pointer to the device used during the execution. */
199 gmx_device_info_t *deviceInfo;
201 /*! \brief Kernel scheduling grid width limit in X - derived from deviceinfo compute capability in CUDA.
202 * Declared as very large int to make it useful in computations with type promotion, to avoid overflows.
204 std::intmax_t maxGridWidthX;
206 /*! \brief A single structure encompassing all the PME data used on GPU.
207 * Its value is the only argument to all the PME GPU kernels.
208 * \todo Test whether this should be copied to the constant GPU memory once for each computation
209 * (or even less often with no box updates) instead of being an argument.
211 std::shared_ptr<PmeGpuKernelParams> kernelParams;
213 /*! \brief The pointer to GPU-framework specific host-side data, such as CUDA streams and events. */
214 std::shared_ptr<PmeGpuSpecific> archSpecific; /* FIXME: make it an unique_ptr */
217 #endif