65406cc462e3491b6ef6facc93a300da3a4702fa
[alexxy/gromacs.git] / src / gromacs / mdlib / nbnxn_cuda / nbnxn_cuda_kernels.cuh
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2016,2017,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.
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
36 #include "gromacs/gpu_utils/cuda_arch_utils.cuh"
37
38 /*! \internal \file
39  *  This header has the sole purpose of generating kernels for the combinations of
40  *  supported electrostatics types (cut-off, reaction-field, analytical and
41  *  tabulated Ewald) and VDW types (cut-off + V shift, LJ-Ewald with
42  *  geometric or Lorentz-Berthelot combination rule, F switch, V switch).
43  *
44  *  The Ewald kernels have twin-range cut-off versions with rcoul != rvdw which
45  *  require an extra distance check to enable  PP-PME load balancing
46  *  (otherwise, by default rcoul == rvdw).
47  *
48  *  NOTE: No include fence as it is meant to be included multiple times.
49  *
50  *  \author Szilárd Páll <pall.szilard@gmail.com>
51  *  \author Berk Hess <hess@kth.se>
52  *  \ingroup module_mdlib
53  */
54
55 /* Use the standard (non-Fermi) kernel in host pass too. */
56 #if GMX_PTX_ARCH >= 300 || GMX_PTX_ARCH == 0
57 #define FLAVOR_LEVEL_GENERATOR "gromacs/mdlib/nbnxn_cuda/nbnxn_cuda_kernel.cuh"
58 #else
59 #define FLAVOR_LEVEL_GENERATOR "gromacs/mdlib/nbnxn_cuda/nbnxn_cuda_kernel_fermi.cuh"
60 #endif
61
62 /* Analytical plain cut-off electrostatics kernels
63  */
64 #define EL_CUTOFF
65
66 /* cut-off + V shift LJ */
67 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecCut_VdwLJ ## __VA_ARGS__
68 #include FLAVOR_LEVEL_GENERATOR
69 #undef NB_KERNEL_FUNC_NAME
70 /* cut-off + V shift LJ w geometric combination rules */
71 #define LJ_COMB_GEOM
72 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecCut_VdwLJCombGeom ## __VA_ARGS__
73 #include FLAVOR_LEVEL_GENERATOR
74 #undef LJ_COMB_GEOM
75 #undef NB_KERNEL_FUNC_NAME
76 /* cut-off + V shift LJ w LB combination rules */
77 #define LJ_COMB_LB
78 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecCut_VdwLJCombLB ## __VA_ARGS__
79 #include FLAVOR_LEVEL_GENERATOR
80 #undef LJ_COMB_LB
81 #undef NB_KERNEL_FUNC_NAME
82 /* LJ-Ewald w geometric combination rules */
83 #define LJ_EWALD_COMB_GEOM
84 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecCut_VdwLJEwCombGeom ## __VA_ARGS__
85 #include FLAVOR_LEVEL_GENERATOR
86 #undef LJ_EWALD_COMB_GEOM
87 #undef NB_KERNEL_FUNC_NAME
88 /* LJ-Ewald w LB combination rules */
89 #define LJ_EWALD_COMB_LB
90 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecCut_VdwLJEwCombLB ## __VA_ARGS__
91 #include FLAVOR_LEVEL_GENERATOR
92 #undef LJ_EWALD_COMB_LB
93 #undef NB_KERNEL_FUNC_NAME
94 /* F switch LJ */
95 #define LJ_FORCE_SWITCH
96 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecCut_VdwLJFsw ## __VA_ARGS__
97 #include FLAVOR_LEVEL_GENERATOR
98 #undef LJ_FORCE_SWITCH
99 #undef NB_KERNEL_FUNC_NAME
100 /* V switch LJ */
101 #define LJ_POT_SWITCH
102 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecCut_VdwLJPsw ## __VA_ARGS__
103 #include FLAVOR_LEVEL_GENERATOR
104 #undef LJ_POT_SWITCH
105 #undef NB_KERNEL_FUNC_NAME
106
107 #undef EL_CUTOFF
108
109
110 /* Analytical reaction-field kernels
111  */
112 #define EL_RF
113
114 /* cut-off + V shift LJ */
115 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecRF_VdwLJ ## __VA_ARGS__
116 #include FLAVOR_LEVEL_GENERATOR
117 #undef NB_KERNEL_FUNC_NAME
118 /* cut-off + V shift LJ w geometric combination rules */
119 #define LJ_COMB_GEOM
120 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecRF_VdwLJCombGeom ## __VA_ARGS__
121 #include FLAVOR_LEVEL_GENERATOR
122 #undef LJ_COMB_GEOM
123 #undef NB_KERNEL_FUNC_NAME
124 /* cut-off + V shift LJ w LB combination rules */
125 #define LJ_COMB_LB
126 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecRF_VdwLJCombLB ## __VA_ARGS__
127 #include FLAVOR_LEVEL_GENERATOR
128 #undef LJ_COMB_LB
129 #undef NB_KERNEL_FUNC_NAME
130 /* LJ-Ewald w geometric combination rules */
131 #define LJ_EWALD_COMB_GEOM
132 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecRF_VdwLJEwCombGeom ## __VA_ARGS__
133 #include FLAVOR_LEVEL_GENERATOR
134 #undef LJ_EWALD_COMB_GEOM
135 #undef NB_KERNEL_FUNC_NAME
136 /* LJ-Ewald w LB combination rules */
137 #define LJ_EWALD_COMB_LB
138 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecRF_VdwLJEwCombLB ## __VA_ARGS__
139 #include FLAVOR_LEVEL_GENERATOR
140 #undef LJ_EWALD_COMB_LB
141 #undef NB_KERNEL_FUNC_NAME
142 /* F switch LJ */
143 #define LJ_FORCE_SWITCH
144 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecRF_VdwLJFsw ## __VA_ARGS__
145 #include FLAVOR_LEVEL_GENERATOR
146 #undef LJ_FORCE_SWITCH
147 #undef NB_KERNEL_FUNC_NAME
148 /* V switch LJ */
149 #define LJ_POT_SWITCH
150 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecRF_VdwLJPsw ## __VA_ARGS__
151 #include FLAVOR_LEVEL_GENERATOR
152 #undef LJ_POT_SWITCH
153 #undef NB_KERNEL_FUNC_NAME
154
155 #undef EL_RF
156
157
158 /* Analytical Ewald interaction kernels
159  */
160 #define EL_EWALD_ANA
161
162 /* cut-off + V shift LJ */
163 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEw_VdwLJ ## __VA_ARGS__
164 #include FLAVOR_LEVEL_GENERATOR
165 #undef NB_KERNEL_FUNC_NAME
166 /* cut-off + V shift LJ w geometric combination rules */
167 #define LJ_COMB_GEOM
168 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEw_VdwLJCombGeom ## __VA_ARGS__
169 #include FLAVOR_LEVEL_GENERATOR
170 #undef LJ_COMB_GEOM
171 #undef NB_KERNEL_FUNC_NAME
172 /* cut-off + V shift LJ w LB combination rules */
173 #define LJ_COMB_LB
174 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEw_VdwLJCombLB ## __VA_ARGS__
175 #include FLAVOR_LEVEL_GENERATOR
176 #undef LJ_COMB_LB
177 #undef NB_KERNEL_FUNC_NAME
178 /* LJ-Ewald w geometric combination rules */
179 #define LJ_EWALD_COMB_GEOM
180 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEw_VdwLJEwCombGeom ## __VA_ARGS__
181 #include FLAVOR_LEVEL_GENERATOR
182 #undef LJ_EWALD_COMB_GEOM
183 #undef NB_KERNEL_FUNC_NAME
184 /* LJ-Ewald w LB combination rules */
185 #define LJ_EWALD_COMB_LB
186 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEw_VdwLJEwCombLB ## __VA_ARGS__
187 #include FLAVOR_LEVEL_GENERATOR
188 #undef LJ_EWALD_COMB_LB
189 #undef NB_KERNEL_FUNC_NAME
190 /* F switch LJ */
191 #define LJ_FORCE_SWITCH
192 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEw_VdwLJFsw ## __VA_ARGS__
193 #include FLAVOR_LEVEL_GENERATOR
194 #undef LJ_FORCE_SWITCH
195 #undef NB_KERNEL_FUNC_NAME
196 /* V switch LJ */
197 #define LJ_POT_SWITCH
198 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEw_VdwLJPsw ## __VA_ARGS__
199 #include FLAVOR_LEVEL_GENERATOR
200 #undef LJ_POT_SWITCH
201 #undef NB_KERNEL_FUNC_NAME
202
203 #undef EL_EWALD_ANA
204
205
206 /* Analytical Ewald interaction kernels with twin-range cut-off
207  */
208 #define EL_EWALD_ANA
209 #define VDW_CUTOFF_CHECK
210
211 /* cut-off + V shift LJ */
212 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwTwinCut_VdwLJ ## __VA_ARGS__
213 #include FLAVOR_LEVEL_GENERATOR
214 #undef NB_KERNEL_FUNC_NAME
215 /* cut-off + V shift LJ w geometric combination rules */
216 #define LJ_COMB_GEOM
217 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwTwinCut_VdwLJCombGeom ## __VA_ARGS__
218 #include FLAVOR_LEVEL_GENERATOR
219 #undef LJ_COMB_GEOM
220 #undef NB_KERNEL_FUNC_NAME
221 /* cut-off + V shift LJ w LB combination rules */
222 #define LJ_COMB_LB
223 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwTwinCut_VdwLJCombLB ## __VA_ARGS__
224 #include FLAVOR_LEVEL_GENERATOR
225 #undef LJ_COMB_LB
226 #undef NB_KERNEL_FUNC_NAME
227 /* LJ-Ewald w geometric combination rules */
228 #define LJ_EWALD_COMB_GEOM
229 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwTwinCut_VdwLJEwCombGeom ## __VA_ARGS__
230 #include FLAVOR_LEVEL_GENERATOR
231 #undef LJ_EWALD_COMB_GEOM
232 #undef NB_KERNEL_FUNC_NAME
233 /* LJ-Ewald w LB combination rules */
234 #define LJ_EWALD_COMB_LB
235 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwTwinCut_VdwLJEwCombLB ## __VA_ARGS__
236 #include FLAVOR_LEVEL_GENERATOR
237 #undef LJ_EWALD_COMB_LB
238 #undef NB_KERNEL_FUNC_NAME
239 /* F switch LJ */
240 #define LJ_FORCE_SWITCH
241 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwTwinCut_VdwLJFsw ## __VA_ARGS__
242 #include FLAVOR_LEVEL_GENERATOR
243 #undef LJ_FORCE_SWITCH
244 #undef NB_KERNEL_FUNC_NAME
245 /* V switch LJ */
246 #define LJ_POT_SWITCH
247 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwTwinCut_VdwLJPsw ## __VA_ARGS__
248 #include FLAVOR_LEVEL_GENERATOR
249 #undef LJ_POT_SWITCH
250 #undef NB_KERNEL_FUNC_NAME
251
252 #undef EL_EWALD_ANA
253 #undef VDW_CUTOFF_CHECK
254
255
256 /* Tabulated Ewald interaction kernels */
257 #define EL_EWALD_TAB
258
259 /* cut-off + V shift LJ */
260 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTab_VdwLJ ## __VA_ARGS__
261 #include FLAVOR_LEVEL_GENERATOR
262 #undef NB_KERNEL_FUNC_NAME
263 /* cut-off + V shift LJ w geometric combination rules */
264 #define LJ_COMB_GEOM
265 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTab_VdwLJCombGeom ## __VA_ARGS__
266 #include FLAVOR_LEVEL_GENERATOR
267 #undef LJ_COMB_GEOM
268 #undef NB_KERNEL_FUNC_NAME
269 /* cut-off + V shift LJ w LB combination rules */
270 #define LJ_COMB_LB
271 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTab_VdwLJCombLB ## __VA_ARGS__
272 #include FLAVOR_LEVEL_GENERATOR
273 #undef LJ_COMB_LB
274 #undef NB_KERNEL_FUNC_NAME
275 /* LJ-Ewald w geometric combination rules */
276 #define LJ_EWALD_COMB_GEOM
277 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTab_VdwLJEwCombGeom ## __VA_ARGS__
278 #include FLAVOR_LEVEL_GENERATOR
279 #undef LJ_EWALD_COMB_GEOM
280 #undef NB_KERNEL_FUNC_NAME
281 /* LJ-Ewald w LB combination rules */
282 #define LJ_EWALD_COMB_LB
283 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTab_VdwLJEwCombLB ## __VA_ARGS__
284 #include FLAVOR_LEVEL_GENERATOR
285 #undef LJ_EWALD_COMB_LB
286 #undef NB_KERNEL_FUNC_NAME
287 /* F switch LJ */
288 #define LJ_FORCE_SWITCH
289 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTab_VdwLJFsw ## __VA_ARGS__
290 #include FLAVOR_LEVEL_GENERATOR
291 #undef LJ_FORCE_SWITCH
292 #undef NB_KERNEL_FUNC_NAME
293 /* V switch LJ */
294 #define LJ_POT_SWITCH
295 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTab_VdwLJPsw ## __VA_ARGS__
296 #include FLAVOR_LEVEL_GENERATOR
297 #undef LJ_POT_SWITCH
298 #undef NB_KERNEL_FUNC_NAME
299
300 #undef EL_EWALD_TAB
301
302
303 /* Tabulated Ewald interaction kernels with twin-range cut-off */
304 #define EL_EWALD_TAB
305 #define VDW_CUTOFF_CHECK
306
307 /* cut-off + V shift LJ */
308 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTabTwinCut_VdwLJ ## __VA_ARGS__
309 #include FLAVOR_LEVEL_GENERATOR
310 #undef NB_KERNEL_FUNC_NAME
311 /* cut-off + V shift LJ w geometric combination rules */
312 #define LJ_COMB_GEOM
313 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTabTwinCut_VdwLJCombGeom ## __VA_ARGS__
314 #include FLAVOR_LEVEL_GENERATOR
315 #undef LJ_COMB_GEOM
316 #undef NB_KERNEL_FUNC_NAME
317 /* cut-off + V shift LJ w LB combination rules */
318 #define LJ_COMB_LB
319 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTabTwinCut_VdwLJCombLB ## __VA_ARGS__
320 #include FLAVOR_LEVEL_GENERATOR
321 #undef LJ_COMB_LB
322 #undef NB_KERNEL_FUNC_NAME
323 /* LJ-Ewald w geometric combination rules */
324 #define LJ_EWALD_COMB_GEOM
325 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTabTwinCut_VdwLJEwCombGeom ## __VA_ARGS__
326 #include FLAVOR_LEVEL_GENERATOR
327 #undef LJ_EWALD_COMB_GEOM
328 #undef NB_KERNEL_FUNC_NAME
329 /* LJ-Ewald w LB combination rules */
330 #define LJ_EWALD_COMB_LB
331 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTabTwinCut_VdwLJEwCombLB ## __VA_ARGS__
332 #include FLAVOR_LEVEL_GENERATOR
333 #undef LJ_EWALD_COMB_LB
334 #undef NB_KERNEL_FUNC_NAME
335 /* F switch LJ */
336 #define LJ_FORCE_SWITCH
337 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTabTwinCut_VdwLJFsw ## __VA_ARGS__
338 #include FLAVOR_LEVEL_GENERATOR
339 #undef LJ_FORCE_SWITCH
340 #undef NB_KERNEL_FUNC_NAME
341 /* V switch LJ */
342 #define LJ_POT_SWITCH
343 #define NB_KERNEL_FUNC_NAME(x, ...) x ## _ElecEwQSTabTwinCut_VdwLJPsw ## __VA_ARGS__
344 #include FLAVOR_LEVEL_GENERATOR
345 #undef LJ_POT_SWITCH
346 #undef NB_KERNEL_FUNC_NAME
347
348 #undef EL_EWALD_TAB
349 #undef VDW_CUTOFF_CHECK