Move initiation of local CPU force H2D transfer to producer
[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  * 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \libinternal \file
36  *  \brief Declare interface for GPU data transfer for NBNXN module
37  *
38  *  \author Szilard Pall <pall.szilard@gmail.com>
39  *  \author Mark Abraham <mark.j.abraham@gmail.com>
40  *  \ingroup module_nbnxm
41  *  \inlibraryapi
42  */
43
44 #ifndef GMX_NBNXN_GPU_DATA_MGMT_H
45 #define GMX_NBNXN_GPU_DATA_MGMT_H
46
47 #include <memory>
48
49 #include "gromacs/gpu_utils/devicebuffer_datatype.h"
50 #include "gromacs/gpu_utils/gpu_macros.h"
51 #include "gromacs/mdtypes/locality.h"
52
53 #include "nbnxm.h"
54
55 struct NbnxmGpu;
56 struct DeviceInformation;
57 struct gmx_wallclock_gpu_nbnxn_t;
58 struct nbnxn_atomdata_t;
59 struct NbnxnPairlistGpu;
60 struct PairlistParams;
61 struct interaction_const_t;
62
63 class DeviceStream;
64
65 namespace gmx
66 {
67 class DeviceStreamManager;
68 }
69
70 namespace Nbnxm
71 {
72
73 /** Initializes the data structures related to GPU nonbonded calculations. */
74 GPU_FUNC_QUALIFIER
75 NbnxmGpu* gpu_init(const gmx::DeviceStreamManager gmx_unused& deviceStreamManager,
76                    const interaction_const_t gmx_unused* ic,
77                    const PairlistParams gmx_unused& listParams,
78                    const nbnxn_atomdata_t gmx_unused* nbat,
79                    /* true if both local and non-local are done on GPU */
80                    bool gmx_unused bLocalAndNonlocal) GPU_FUNC_TERM_WITH_RETURN(nullptr);
81
82 /** Initializes pair-list data for GPU, called at every pair search step. */
83 GPU_FUNC_QUALIFIER
84 void gpu_init_pairlist(NbnxmGpu gmx_unused*          nb,
85                        const struct NbnxnPairlistGpu gmx_unused* h_nblist,
86                        gmx::InteractionLocality gmx_unused iloc) GPU_FUNC_TERM;
87
88 /** Initializes atom-data on the GPU, called at every pair search step. */
89 GPU_FUNC_QUALIFIER
90 void gpu_init_atomdata(NbnxmGpu gmx_unused* nb, const nbnxn_atomdata_t gmx_unused* nbat) GPU_FUNC_TERM;
91
92 /*! \brief Re-generate the GPU Ewald force table, resets rlist, and update the
93  *  electrostatic type switching to twin cut-off (or back) if needed.
94  */
95 GPU_FUNC_QUALIFIER
96 void gpu_pme_loadbal_update_param(const struct nonbonded_verlet_t gmx_unused* nbv,
97                                   const interaction_const_t gmx_unused* ic) GPU_FUNC_TERM;
98
99 /** Uploads shift vector to the GPU if the box is dynamic (otherwise just returns). */
100 GPU_FUNC_QUALIFIER
101 void gpu_upload_shiftvec(NbnxmGpu gmx_unused* nb, const nbnxn_atomdata_t gmx_unused* nbatom) GPU_FUNC_TERM;
102
103 /** Clears GPU outputs: nonbonded force, shift force and energy. */
104 GPU_FUNC_QUALIFIER
105 void gpu_clear_outputs(NbnxmGpu gmx_unused* nb, bool gmx_unused computeVirial) GPU_FUNC_TERM;
106
107 /** Frees all GPU resources used for the nonbonded calculations. */
108 GPU_FUNC_QUALIFIER
109 void gpu_free(NbnxmGpu gmx_unused* nb) GPU_FUNC_TERM;
110
111 /** Returns the GPU timings structure or NULL if GPU is not used or timing is off. */
112 GPU_FUNC_QUALIFIER
113 struct gmx_wallclock_gpu_nbnxn_t* gpu_get_timings(NbnxmGpu gmx_unused* nb)
114         GPU_FUNC_TERM_WITH_RETURN(nullptr);
115
116 /** Resets nonbonded GPU timings. */
117 GPU_FUNC_QUALIFIER
118 void gpu_reset_timings(struct nonbonded_verlet_t gmx_unused* nbv) GPU_FUNC_TERM;
119
120 /** Calculates the minimum size of proximity lists to improve SM load balance
121  *  with GPU non-bonded kernels. */
122 GPU_FUNC_QUALIFIER
123 int gpu_min_ci_balanced(NbnxmGpu gmx_unused* nb) GPU_FUNC_TERM_WITH_RETURN(-1);
124
125 /** Returns if analytical Ewald GPU kernels are used. */
126 GPU_FUNC_QUALIFIER
127 bool gpu_is_kernel_ewald_analytical(const NbnxmGpu gmx_unused* nb) GPU_FUNC_TERM_WITH_RETURN(FALSE);
128
129 /** Return the enum value of electrostatics kernel type for given interaction parameters \p ic. */
130 GPU_FUNC_QUALIFIER
131 enum ElecType nbnxmGpuPickElectrostaticsKernelType(const interaction_const_t gmx_unused* ic)
132         GPU_FUNC_TERM_WITH_RETURN(ElecType::Count);
133
134 /** Return the enum value of VdW kernel type for given \p ic and \p combRule. */
135 GPU_FUNC_QUALIFIER
136 enum VdwType nbnxmGpuPickVdwKernelType(const interaction_const_t gmx_unused* ic, int gmx_unused combRule)
137         GPU_FUNC_TERM_WITH_RETURN(VdwType::Count);
138
139 /** Returns an opaque pointer to the GPU command stream
140  *  Note: CUDA only.
141  */
142 CUDA_FUNC_QUALIFIER
143 const DeviceStream* gpu_get_command_stream(NbnxmGpu gmx_unused* nb, gmx::InteractionLocality gmx_unused iloc)
144         CUDA_FUNC_TERM_WITH_RETURN(nullptr);
145
146 /** Returns an opaque pointer to the GPU coordinate+charge array
147  *  Note: CUDA only.
148  */
149 CUDA_FUNC_QUALIFIER
150 void* gpu_get_xq(NbnxmGpu gmx_unused* nb) CUDA_FUNC_TERM_WITH_RETURN(nullptr);
151
152 /** Returns an opaque pointer to the GPU force array
153  *  Note: CUDA only.
154  */
155 CUDA_FUNC_QUALIFIER
156 DeviceBuffer<gmx::RVec> gpu_get_f(NbnxmGpu gmx_unused* nb)
157         CUDA_FUNC_TERM_WITH_RETURN(DeviceBuffer<gmx::RVec>{});
158
159 /** Returns an opaque pointer to the GPU shift force array
160  *  Note: CUDA only.
161  */
162 CUDA_FUNC_QUALIFIER
163 DeviceBuffer<gmx::RVec> gpu_get_fshift(NbnxmGpu gmx_unused* nb)
164         CUDA_FUNC_TERM_WITH_RETURN(DeviceBuffer<gmx::RVec>{});
165
166 } // namespace Nbnxm
167
168 #endif