Two sets of coefficients for Coulomb FEP PME on GPU
[alexxy/gromacs.git] / src / gromacs / ewald / pme_program.cl
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 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
36 /*! \internal \file
37  *  \brief Top-level file for generating PME OpenCL kernels.
38  * This file includes all the PME OpenCL kernel files multiple times, with additional defines.
39  * Plenty of common constants/macros are also expected to be already defined by the compiler
40  * (such as "order" which is PME interpolation order).
41  * For details, please see how pme_program.cl is compiled in pme_gpu_program_impl_ocl.cpp.
42  *
43  * This file specifically expects the following work size definitions:
44  *
45  * - c_spreadWorkGroupSize is a spline/spread kernels work group size.
46  * - c_solveMaxWorkGroupSize is a solve kernels maximum work group size.
47  * - c_gatherWorkGroupSize is a gather kernels work group size.
48  *
49  *  \author Aleksei Iupinov <a.yupinov@gmail.com>
50  */
51
52 // Assert placeholders, to not rip them out from OpenCL implementation - hopefully they come in handy some day with OpenCL 2
53 #define assert(a)
54
55 #define PmeOpenCLKernelParams PmeGpuKernelParamsBase
56
57 /* SPREAD/SPLINE */
58
59 #define atomsPerBlock (c_spreadWorkGroupSize / threadsPerAtom)
60 #define atomsPerWarp (warp_size / threadsPerAtom)
61
62 // spline/spread fused single grid (without FEP or FEP without energy and virial calculation at this step)
63 #define computeSplines 1
64 #define spreadCharges 1
65 #define numGrids 1 /* Using define to avoid a conditional inside the function. */
66 #define CUSTOMIZED_KERNEL_NAME(x) pmeSplineAndSpreadKernelSingle
67 #include "pme_spread.clh"
68 #undef computeSplines
69 #undef spreadCharges
70 #undef numGrids
71 #undef CUSTOMIZED_KERNEL_NAME
72
73 // spline on single grid (without FEP or FEP without energy and virial calculation at this step)
74 #define computeSplines 1
75 #define spreadCharges 0
76 #define numGrids 1 /* Using define to avoid a conditional inside the function. */
77 #define CUSTOMIZED_KERNEL_NAME(x) pmeSplineKernelSingle
78 #include "pme_spread.clh"
79 #undef computeSplines
80 #undef spreadCharges
81 #undef numGrids
82 #undef CUSTOMIZED_KERNEL_NAME
83
84 // spread on single grid (without FEP or FEP without energy and virial calculation at this step)
85 #define computeSplines 0
86 #define spreadCharges 1
87 #define numGrids 1 /* Using define to avoid a conditional inside the function. */
88 #define CUSTOMIZED_KERNEL_NAME(x) pmeSpreadKernelSingle
89 #include "pme_spread.clh"
90 #undef computeSplines
91 #undef spreadCharges
92 #undef numGrids
93 #undef CUSTOMIZED_KERNEL_NAME
94
95 // spline/spread fused on two grids (FEP with energy and virial calculation at this step)
96 #define computeSplines 1
97 #define spreadCharges 1
98 #define numGrids 2 /* Using define to avoid a conditional inside the function. */
99 #define CUSTOMIZED_KERNEL_NAME(x) pmeSplineAndSpreadKernelDual
100 #include "pme_spread.clh"
101 #undef computeSplines
102 #undef spreadCharges
103 #undef numGrids
104 #undef CUSTOMIZED_KERNEL_NAME
105
106 // spline on two grids (FEP with energy and virial calculation at this step)
107 #define computeSplines 1
108 #define spreadCharges 0
109 #define numGrids 2 /* Using define to avoid a conditional inside the function. */
110 #define CUSTOMIZED_KERNEL_NAME(x) pmeSplineKernelDual
111 #include "pme_spread.clh"
112 #undef computeSplines
113 #undef spreadCharges
114 #undef numGrids
115 #undef CUSTOMIZED_KERNEL_NAME
116
117 // spread on two grids (FEP with energy and virial calculation at this step)
118 #define computeSplines 0
119 #define spreadCharges 1
120 #define numGrids 2 /* Using define to avoid a conditional inside the function. */
121 #define CUSTOMIZED_KERNEL_NAME(x) pmeSpreadKernelDual
122 #include "pme_spread.clh"
123 #undef computeSplines
124 #undef spreadCharges
125 #undef numGrids
126 #undef CUSTOMIZED_KERNEL_NAME
127
128
129 #undef atomsPerBlock
130
131
132 /* GATHER */
133
134 #define atomsPerBlock (c_gatherWorkGroupSize / threadsPerAtom)
135
136 // gather using single grid
137 #define numGrids 1 /* Using define to avoid a conditional inside the function. */
138 #define CUSTOMIZED_KERNEL_NAME(x) pmeGatherKernelSingle
139 #include "pme_gather.clh"
140 #undef numGrids
141 #undef CUSTOMIZED_KERNEL_NAME
142
143 // gather using two grids
144 #define numGrids 2 /* Using define to avoid a conditional inside the function. */
145 #define CUSTOMIZED_KERNEL_NAME(x) pmeGatherKernelDual
146 #include "pme_gather.clh"
147 #undef numGrids
148 #undef CUSTOMIZED_KERNEL_NAME
149
150 #undef atomsPerBlock
151
152 /* SOLVE */
153
154 // GridOrdering enum replacement
155 #define YZX 1
156 #define XYZ 2
157
158 // solve, YZX dimension order state A
159 #define gridOrdering YZX
160 #define computeEnergyAndVirial 0
161 #define CUSTOMIZED_KERNEL_NAME(x) pmeSolveYZXKernelA
162 #include "pme_solve.clh"
163 #undef gridOrdering
164 #undef computeEnergyAndVirial
165 #undef CUSTOMIZED_KERNEL_NAME
166
167 // solve with reduction, YZX dimension order state A
168 #define gridOrdering YZX
169 #define computeEnergyAndVirial 1
170 #define CUSTOMIZED_KERNEL_NAME(x) pmeSolveYZXEnergyKernelA
171 #include "pme_solve.clh"
172 #undef gridOrdering
173 #undef computeEnergyAndVirial
174 #undef CUSTOMIZED_KERNEL_NAME
175
176 // solve, XYZ dimension order state A
177 #define gridOrdering XYZ
178 #define computeEnergyAndVirial 0
179 #define CUSTOMIZED_KERNEL_NAME(x) pmeSolveXYZKernelA
180 #include "pme_solve.clh"
181 #undef gridOrdering
182 #undef computeEnergyAndVirial
183 #undef CUSTOMIZED_KERNEL_NAME
184
185 // solve with reduction, XYZ dimension order state A
186 #define gridOrdering XYZ
187 #define computeEnergyAndVirial 1
188 #define CUSTOMIZED_KERNEL_NAME(x) pmeSolveXYZEnergyKernelA
189 #include "pme_solve.clh"
190 #undef gridOrdering
191 #undef computeEnergyAndVirial
192 #undef CUSTOMIZED_KERNEL_NAME
193
194 // solve, YZX dimension order state B
195 #define gridOrdering YZX
196 #define computeEnergyAndVirial 0
197 #define CUSTOMIZED_KERNEL_NAME(x) pmeSolveYZXKernelB
198 #include "pme_solve.clh"
199 #undef gridOrdering
200 #undef computeEnergyAndVirial
201 #undef CUSTOMIZED_KERNEL_NAME
202
203 // solve with reduction, YZX dimension order state B
204 #define gridOrdering YZX
205 #define computeEnergyAndVirial 1
206 #define CUSTOMIZED_KERNEL_NAME(x) pmeSolveYZXEnergyKernelB
207 #include "pme_solve.clh"
208 #undef gridOrdering
209 #undef computeEnergyAndVirial
210 #undef CUSTOMIZED_KERNEL_NAME
211
212 // solve, XYZ dimension order state B
213 #define gridOrdering XYZ
214 #define computeEnergyAndVirial 0
215 #define CUSTOMIZED_KERNEL_NAME(x) pmeSolveXYZKernelB
216 #include "pme_solve.clh"
217 #undef gridOrdering
218 #undef computeEnergyAndVirial
219 #undef CUSTOMIZED_KERNEL_NAME
220
221 // solve with reduction, XYZ dimension order state B
222 #define gridOrdering XYZ
223 #define computeEnergyAndVirial 1
224 #define CUSTOMIZED_KERNEL_NAME(x) pmeSolveXYZEnergyKernelB
225 #include "pme_solve.clh"
226 #undef gridOrdering
227 #undef computeEnergyAndVirial
228 #undef CUSTOMIZED_KERNEL_NAME