Make LJ combination rule enum into an enum class
[alexxy/gromacs.git] / src / gromacs / nbnxm / gpu_data_mgmt.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2014,2015,2017,2018,2019,2020, by the GROMACS development team, led by
5  * Copyright (c) 2021, by the GROMACS development team, led by
6  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7  * and including many others, as listed in the AUTHORS file in the
8  * top-level source directory and at http://www.gromacs.org.
9  *
10  * GROMACS is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public License
12  * as published by the Free Software Foundation; either version 2.1
13  * of the License, or (at your option) any later version.
14  *
15  * GROMACS is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with GROMACS; if not, see
22  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24  *
25  * If you want to redistribute modifications to GROMACS, please
26  * consider that scientific software is very special. Version
27  * control is crucial - bugs must be traceable. We will be happy to
28  * consider code for inclusion in the official distribution, but
29  * derived work must not be called official GROMACS. Details are found
30  * in the README & COPYING files - if they are missing, get the
31  * official version at http://www.gromacs.org.
32  *
33  * To help us fund GROMACS development, we humbly ask that you cite
34  * the research papers on the package. Check out http://www.gromacs.org.
35  */
36 /*! \libinternal \file
37  *  \brief Declare interface for GPU data transfer for NBNXN module
38  *
39  *  \author Szilard Pall <pall.szilard@gmail.com>
40  *  \author Mark Abraham <mark.j.abraham@gmail.com>
41  *  \ingroup module_nbnxm
42  *  \inlibraryapi
43  */
44
45 #ifndef GMX_NBNXN_GPU_DATA_MGMT_H
46 #define GMX_NBNXN_GPU_DATA_MGMT_H
47
48 #include <memory>
49
50 #include "gromacs/gpu_utils/devicebuffer_datatype.h"
51 #include "gromacs/gpu_utils/gpu_macros.h"
52 #include "gromacs/mdtypes/locality.h"
53
54 #include "nbnxm.h"
55
56 struct NbnxmGpu;
57 struct DeviceInformation;
58 struct gmx_wallclock_gpu_nbnxn_t;
59 struct nbnxn_atomdata_t;
60 struct NbnxnPairlistGpu;
61 struct PairlistParams;
62 struct interaction_const_t;
63
64 class DeviceStream;
65
66 namespace gmx
67 {
68 class DeviceStreamManager;
69 }
70
71 namespace Nbnxm
72 {
73
74 /** Initializes the data structures related to GPU nonbonded calculations. */
75 GPU_FUNC_QUALIFIER
76 NbnxmGpu* gpu_init(const gmx::DeviceStreamManager gmx_unused& deviceStreamManager,
77                    const interaction_const_t gmx_unused* ic,
78                    const PairlistParams gmx_unused& listParams,
79                    const nbnxn_atomdata_t gmx_unused* nbat,
80                    /* true if both local and non-local are done on GPU */
81                    bool gmx_unused bLocalAndNonlocal) GPU_FUNC_TERM_WITH_RETURN(nullptr);
82
83 /** Initializes pair-list data for GPU, called at every pair search step. */
84 GPU_FUNC_QUALIFIER
85 void gpu_init_pairlist(NbnxmGpu gmx_unused*          nb,
86                        const struct NbnxnPairlistGpu gmx_unused* h_nblist,
87                        gmx::InteractionLocality gmx_unused iloc) GPU_FUNC_TERM;
88
89 /** Initializes atom-data on the GPU, called at every pair search step. */
90 GPU_FUNC_QUALIFIER
91 void gpu_init_atomdata(NbnxmGpu gmx_unused* nb, const nbnxn_atomdata_t gmx_unused* nbat) GPU_FUNC_TERM;
92
93 /*! \brief Re-generate the GPU Ewald force table, resets rlist, and update the
94  *  electrostatic type switching to twin cut-off (or back) if needed.
95  */
96 GPU_FUNC_QUALIFIER
97 void gpu_pme_loadbal_update_param(const struct nonbonded_verlet_t gmx_unused* nbv,
98                                   const interaction_const_t gmx_unused* ic) GPU_FUNC_TERM;
99
100 /** Uploads shift vector to the GPU if the box is dynamic (otherwise just returns). */
101 GPU_FUNC_QUALIFIER
102 void gpu_upload_shiftvec(NbnxmGpu gmx_unused* nb, const nbnxn_atomdata_t gmx_unused* nbatom) GPU_FUNC_TERM;
103
104 /** Clears GPU outputs: nonbonded force, shift force and energy. */
105 GPU_FUNC_QUALIFIER
106 void gpu_clear_outputs(NbnxmGpu gmx_unused* nb, bool gmx_unused computeVirial) GPU_FUNC_TERM;
107
108 /** Frees all GPU resources used for the nonbonded calculations. */
109 GPU_FUNC_QUALIFIER
110 void gpu_free(NbnxmGpu gmx_unused* nb) GPU_FUNC_TERM;
111
112 /** Returns the GPU timings structure or NULL if GPU is not used or timing is off. */
113 GPU_FUNC_QUALIFIER
114 struct gmx_wallclock_gpu_nbnxn_t* gpu_get_timings(NbnxmGpu gmx_unused* nb)
115         GPU_FUNC_TERM_WITH_RETURN(nullptr);
116
117 /** Resets nonbonded GPU timings. */
118 GPU_FUNC_QUALIFIER
119 void gpu_reset_timings(struct nonbonded_verlet_t gmx_unused* nbv) GPU_FUNC_TERM;
120
121 /** Calculates the minimum size of proximity lists to improve SM load balance
122  *  with GPU non-bonded kernels. */
123 GPU_FUNC_QUALIFIER
124 int gpu_min_ci_balanced(NbnxmGpu gmx_unused* nb) GPU_FUNC_TERM_WITH_RETURN(-1);
125
126 /** Returns if analytical Ewald GPU kernels are used. */
127 GPU_FUNC_QUALIFIER
128 bool gpu_is_kernel_ewald_analytical(const NbnxmGpu gmx_unused* nb) GPU_FUNC_TERM_WITH_RETURN(FALSE);
129
130 /** Return the enum value of electrostatics kernel type for given interaction parameters \p ic. */
131 GPU_FUNC_QUALIFIER
132 enum ElecType nbnxmGpuPickElectrostaticsKernelType(const interaction_const_t gmx_unused* ic,
133                                                    const DeviceInformation gmx_unused& deviceInfo)
134         GPU_FUNC_TERM_WITH_RETURN(ElecType::Count);
135
136 /** Return the enum value of VdW kernel type for given \p ic and \p combRule. */
137 GPU_FUNC_QUALIFIER
138 enum VdwType nbnxmGpuPickVdwKernelType(const interaction_const_t gmx_unused* ic,
139                                        LJCombinationRule gmx_unused ljCombinationRule)
140         GPU_FUNC_TERM_WITH_RETURN(VdwType::Count);
141
142 /** Returns an opaque pointer to the GPU command stream
143  *  Note: CUDA only.
144  */
145 CUDA_FUNC_QUALIFIER
146 const DeviceStream* gpu_get_command_stream(NbnxmGpu gmx_unused* nb, gmx::InteractionLocality gmx_unused iloc)
147         CUDA_FUNC_TERM_WITH_RETURN(nullptr);
148
149 /** Returns an opaque pointer to the GPU coordinate+charge array
150  *  Note: CUDA only.
151  */
152 CUDA_FUNC_QUALIFIER
153 void* gpu_get_xq(NbnxmGpu gmx_unused* nb) CUDA_FUNC_TERM_WITH_RETURN(nullptr);
154
155 /** Returns an opaque pointer to the GPU force array
156  *  Note: CUDA only.
157  */
158 CUDA_FUNC_QUALIFIER
159 DeviceBuffer<gmx::RVec> gpu_get_f(NbnxmGpu gmx_unused* nb)
160         CUDA_FUNC_TERM_WITH_RETURN(DeviceBuffer<gmx::RVec>{});
161
162 /** Returns an opaque pointer to the GPU shift force array
163  *  Note: CUDA only.
164  */
165 CUDA_FUNC_QUALIFIER
166 DeviceBuffer<gmx::RVec> gpu_get_fshift(NbnxmGpu gmx_unused* nb)
167         CUDA_FUNC_TERM_WITH_RETURN(DeviceBuffer<gmx::RVec>{});
168
169 } // namespace Nbnxm
170
171 #endif