Simplified uniform GPU selection in CMake
[alexxy/gromacs.git] / src / gromacs / nbnxm / gpu_types_common.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 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 /*! \internal \file
36  * \brief Implements common internal types for different NBNXN GPU implementations
37  *
38  * \author Szilárd Páll <pall.szilard@gmail.com>
39  * \ingroup module_nbnxm
40  */
41
42 #ifndef GMX_MDLIB_NBNXN_GPU_COMMON_TYPES_H
43 #define GMX_MDLIB_NBNXN_GPU_COMMON_TYPES_H
44
45 #include "config.h"
46
47 #include "gromacs/mdtypes/locality.h"
48 #include "gromacs/utility/enumerationhelpers.h"
49
50 #include "pairlist.h"
51
52 #if GMX_GPU_OPENCL
53 #    include "gromacs/gpu_utils/gpuregiontimer_ocl.h"
54 #endif
55
56 #if GMX_GPU_CUDA
57 #    include "gromacs/gpu_utils/gpuregiontimer.cuh"
58 #endif
59
60 /** \internal
61  * \brief Parameters required for the GPU nonbonded calculations.
62  */
63 struct NBParamGpu
64 {
65
66     //! type of electrostatics, takes values from #eelType
67     int eeltype;
68     //! type of VdW impl., takes values from #evdwType
69     int vdwtype;
70
71     //! charge multiplication factor
72     float epsfac;
73     //! Reaction-field/plain cutoff electrostatics const.
74     float c_rf;
75     //! Reaction-field electrostatics constant
76     float two_k_rf;
77     //! Ewald/PME parameter
78     float ewald_beta;
79     //! Ewald/PME correction term substracted from the direct-space potential
80     float sh_ewald;
81     //! LJ-Ewald/PME correction term added to the correction potential
82     float sh_lj_ewald;
83     //! LJ-Ewald/PME coefficient
84     float ewaldcoeff_lj;
85
86     //! Coulomb cut-off squared
87     float rcoulomb_sq;
88
89     //! VdW cut-off squared
90     float rvdw_sq;
91     //! VdW switched cut-off
92     float rvdw_switch;
93     //! Full, outer pair-list cut-off squared
94     float rlistOuter_sq;
95     //! Inner, dynamic pruned pair-list cut-off squared
96     float rlistInner_sq;
97     //! True if we use dynamic pair-list pruning
98     bool useDynamicPruning;
99
100     //! VdW shift dispersion constants
101     shift_consts_t dispersion_shift;
102     //! VdW shift repulsion constants
103     shift_consts_t repulsion_shift;
104     //! VdW switch constants
105     switch_consts_t vdw_switch;
106
107     /* LJ non-bonded parameters - accessed through texture memory */
108     //! nonbonded parameter table with C6/C12 pairs per atom type-pair, 2*ntype^2 elements
109     DeviceBuffer<float> nbfp;
110     //! texture object bound to nbfp
111     DeviceTexture nbfp_texobj;
112     //! nonbonded parameter table per atom type, 2*ntype elements
113     DeviceBuffer<float> nbfp_comb;
114     //! texture object bound to nbfp_comb
115     DeviceTexture nbfp_comb_texobj;
116
117     /* Ewald Coulomb force table data - accessed through texture memory */
118     //! table scale/spacing
119     float coulomb_tab_scale;
120     //! pointer to the table in the device memory
121     DeviceBuffer<float> coulomb_tab;
122     //! texture object bound to coulomb_tab
123     DeviceTexture coulomb_tab_texobj;
124 };
125
126 namespace Nbnxm
127 {
128
129 using gmx::AtomLocality;
130 using gmx::InteractionLocality;
131
132 /*! \internal
133  * \brief GPU region timers used for timing GPU kernels and H2D/D2H transfers.
134  *
135  * The two-sized arrays hold the local and non-local values and should always
136  * be indexed with eintLocal/eintNonlocal.
137  */
138 struct gpu_timers_t
139 {
140     /*! \internal
141      * \brief Timers for local or non-local coordinate/force transfers
142      */
143     struct XFTransfers
144     {
145         //! timer for x/q H2D transfers (l/nl, every step)
146         GpuRegionTimer nb_h2d;
147         //! timer for f D2H transfer (l/nl, every step)
148         GpuRegionTimer nb_d2h;
149     };
150
151     /*! \internal
152      * \brief Timers for local or non-local interaction related operations
153      */
154     struct Interaction
155     {
156         //! timer for pair-list H2D transfers (l/nl, every PS step)
157         GpuRegionTimer pl_h2d;
158         //! true when a pair-list transfer has been done at this step
159         bool didPairlistH2D = false;
160         //! timer for non-bonded kernels (l/nl, every step)
161         GpuRegionTimer nb_k;
162         //! timer for the 1st pass list pruning kernel (l/nl, every PS step)
163         GpuRegionTimer prune_k;
164         //! true when we timed pruning and the timings need to be accounted for
165         bool didPrune = false;
166         //! timer for rolling pruning kernels (l/nl, frequency depends on chunk size)
167         GpuRegionTimer rollingPrune_k;
168         //! true when we timed rolling pruning (at the previous step) and the timings need to be accounted for
169         bool didRollingPrune = false;
170     };
171
172     //! timer for atom data transfer (every PS step)
173     GpuRegionTimer atdat;
174     //! timers for coordinate/force transfers (every step)
175     gmx::EnumerationArray<AtomLocality, XFTransfers> xf;
176     //! timers for interaction related transfers
177     gmx::EnumerationArray<InteractionLocality, Nbnxm::gpu_timers_t::Interaction> interaction;
178 };
179
180 /*! \internal
181  * \brief GPU pair list structure */
182 struct gpu_plist
183 {
184     //! number of atoms per cluster
185     int na_c;
186
187     //! size of sci, # of i clusters in the list
188     int nsci;
189     //! allocation size of sci
190     int sci_nalloc;
191     //! list of i-cluster ("super-clusters")
192     DeviceBuffer<nbnxn_sci_t> sci;
193
194     //! total # of 4*j clusters
195     int ncj4;
196     //! allocation size of cj4
197     int cj4_nalloc;
198     //! 4*j cluster list, contains j cluster number and index into the i cluster list
199     DeviceBuffer<nbnxn_cj4_t> cj4;
200     //! # of 4*j clusters * # of warps
201     int nimask;
202     //! allocation size of imask
203     int imask_nalloc;
204     //! imask for 2 warps for each 4*j cluster group
205     DeviceBuffer<unsigned int> imask;
206     //! atom interaction bits
207     DeviceBuffer<nbnxn_excl_t> excl;
208     //! count for excl
209     int nexcl;
210     //! allocation size of excl
211     int excl_nalloc;
212
213     /* parameter+variables for normal and rolling pruning */
214     //! true after search, indictes that initial pruning with outer prunning is needed
215     bool haveFreshList;
216     //! the number of parts/steps over which one cyle of roling pruning takes places
217     int rollingPruningNumParts;
218     //! the next part to which the roling pruning needs to be applied
219     int rollingPruningPart;
220 };
221
222 } // namespace Nbnxm
223
224 #endif