2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019, 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.
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.
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.
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.
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.
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.
37 * \brief Implements CUDA bonded functionality
39 * \author Jon Vincent <jvincent@nvidia.com>
40 * \author Magnus Lundborg <lundborg.magnus@gmail.com>
41 * \author Berk Hess <hess@kth.se>
42 * \author Szilárd Páll <pall.szilard@gmail.com>
43 * \author Alan Gray <alang@nvidia.com>
44 * \author Mark Abraham <mark.j.abraham@gmail.com>
46 * \ingroup module_listed_forces
53 #include <math_constants.h>
55 #include "gromacs/gpu_utils/cudautils.cuh"
56 #include "gromacs/gpu_utils/gpu_vec.cuh"
57 #include "gromacs/listed_forces/gpubonded.h"
58 #include "gromacs/math/units.h"
59 #include "gromacs/mdlib/force_flags.h"
60 #include "gromacs/mdtypes/forcerec.h"
61 #include "gromacs/pbcutil/pbc.h"
62 #include "gromacs/pbcutil/pbc_aiuc_cuda.cuh"
63 #include "gromacs/utility/gmxassert.h"
65 #include "gpubonded_impl.h"
71 //CUDA threads per block
72 #define TPB_BONDED 256
74 /*-------------------------------- CUDA kernels-------------------------------- */
75 /*------------------------------------------------------------------------------*/
78 /*---------------- BONDED CUDA kernels--------------*/
81 __device__ __forceinline__
82 static void harmonic_gpu(const float kA, const float xA, const float x, float *V, float *F)
84 constexpr float half = 0.5f;
94 template <bool calcVir, bool calcEner>
96 void bonds_gpu(const int i, float *vtot_loc, const int numBonds,
97 const t_iatom d_forceatoms[], const t_iparams d_forceparams[],
98 const float4 gm_xq[], fvec gm_f[], fvec sm_fShiftLoc[],
99 const PbcAiuc pbcAiuc)
103 int3 bondData = *(int3 *)(d_forceatoms + 3 * i);
104 int type = bondData.x;
108 /* dx = xi - xj, corrected for periodic boundary conditions. */
110 int ki = pbcDxAiuc<calcVir>(pbcAiuc, gm_xq[ai], gm_xq[aj], dx);
112 float dr2 = iprod_gpu(dx, dx);
113 float dr = sqrt(dr2);
117 harmonic_gpu(d_forceparams[type].harmonic.krA,
118 d_forceparams[type].harmonic.rA,
128 fbond *= rsqrtf(dr2);
131 for (int m = 0; m < DIM; m++)
133 float fij = fbond*dx[m];
134 atomicAdd(&gm_f[ai][m], fij);
135 atomicAdd(&gm_f[aj][m], -fij);
136 if (calcVir && ki != CENTRAL)
138 atomicAdd(&sm_fShiftLoc[ki][m], fij);
139 atomicAdd(&sm_fShiftLoc[CENTRAL][m], -fij);
146 template <bool returnShift>
147 __device__ __forceinline__
148 static float bond_angle_gpu(const float4 xi, const float4 xj, const float4 xk,
149 const PbcAiuc &pbcAiuc,
150 fvec r_ij, fvec r_kj, float *costh,
152 /* Return value is the angle between the bonds i-j and j-k */
154 *t1 = pbcDxAiuc<returnShift>(pbcAiuc, xi, xj, r_ij);
155 *t2 = pbcDxAiuc<returnShift>(pbcAiuc, xk, xj, r_kj);
157 *costh = cos_angle_gpu(r_ij, r_kj);
158 float th = acosf(*costh);
163 template <bool calcVir, bool calcEner>
165 void angles_gpu(const int i, float *vtot_loc, const int numBonds,
166 const t_iatom d_forceatoms[], const t_iparams d_forceparams[],
167 const float4 gm_xq[], fvec gm_f[], fvec sm_fShiftLoc[],
168 const PbcAiuc pbcAiuc)
172 int4 angleData = *(int4 *)(d_forceatoms + 4 * i);
173 int type = angleData.x;
174 int ai = angleData.y;
175 int aj = angleData.z;
176 int ak = angleData.w;
184 bond_angle_gpu<calcVir>(gm_xq[ai], gm_xq[aj], gm_xq[ak], pbcAiuc,
185 r_ij, r_kj, &cos_theta, &t1, &t2);
189 harmonic_gpu(d_forceparams[type].harmonic.krA,
190 d_forceparams[type].harmonic.rA*DEG2RAD,
198 float cos_theta2 = cos_theta*cos_theta;
199 if (cos_theta2 < 1.0f)
201 float st = dVdt*rsqrtf(1.0f - cos_theta2);
202 float sth = st*cos_theta;
203 float nrij2 = iprod_gpu(r_ij, r_ij);
204 float nrkj2 = iprod_gpu(r_kj, r_kj);
206 float nrij_1 = rsqrtf(nrij2);
207 float nrkj_1 = rsqrtf(nrkj2);
209 float cik = st*nrij_1*nrkj_1;
210 float cii = sth*nrij_1*nrij_1;
211 float ckk = sth*nrkj_1*nrkj_1;
217 for (int m = 0; m < DIM; m++)
219 f_i[m] = -(cik*r_kj[m] - cii*r_ij[m]);
220 f_k[m] = -(cik*r_ij[m] - ckk*r_kj[m]);
221 f_j[m] = -f_i[m] - f_k[m];
222 atomicAdd(&gm_f[ai][m], f_i[m]);
223 atomicAdd(&gm_f[aj][m], f_j[m]);
224 atomicAdd(&gm_f[ak][m], f_k[m]);
227 atomicAdd(&sm_fShiftLoc[t1][m], f_i[m]);
228 atomicAdd(&sm_fShiftLoc[CENTRAL][m], f_j[m]);
229 atomicAdd(&sm_fShiftLoc[t2][m], f_k[m]);
237 template <bool calcVir, bool calcEner>
239 void urey_bradley_gpu(const int i, float *vtot_loc, const int numBonds,
240 const t_iatom d_forceatoms[], const t_iparams d_forceparams[],
241 const float4 gm_xq[], fvec gm_f[], fvec sm_fShiftLoc[],
242 const PbcAiuc pbcAiuc)
246 int4 ubData = *(int4 *)(d_forceatoms + 4 * i);
252 float th0A = d_forceparams[type].u_b.thetaA*DEG2RAD;
253 float kthA = d_forceparams[type].u_b.kthetaA;
254 float r13A = d_forceparams[type].u_b.r13A;
255 float kUBA = d_forceparams[type].u_b.kUBA;
262 float theta = bond_angle_gpu<calcVir>(gm_xq[ai], gm_xq[aj], gm_xq[ak], pbcAiuc,
263 r_ij, r_kj, &cos_theta, &t1, &t2);
267 harmonic_gpu(kthA, th0A, theta, &va, &dVdt);
275 int ki = pbcDxAiuc<calcVir>(pbcAiuc, gm_xq[ai], gm_xq[ak], r_ik);
277 float dr2 = iprod_gpu(r_ik, r_ik);
278 float dr = dr2*rsqrtf(dr2);
282 harmonic_gpu(kUBA, r13A, dr, &vbond, &fbond);
284 float cos_theta2 = cos_theta*cos_theta;
285 if (cos_theta2 < 1.0f)
287 float st = dVdt*rsqrtf(1.0f - cos_theta2);
288 float sth = st*cos_theta;
290 float nrkj2 = iprod_gpu(r_kj, r_kj);
291 float nrij2 = iprod_gpu(r_ij, r_ij);
293 float cik = st*rsqrtf(nrkj2*nrij2);
294 float cii = sth/nrij2;
295 float ckk = sth/nrkj2;
301 for (int m = 0; m < DIM; m++)
303 f_i[m] = -(cik*r_kj[m]-cii*r_ij[m]);
304 f_k[m] = -(cik*r_ij[m]-ckk*r_kj[m]);
305 f_j[m] = -f_i[m]-f_k[m];
306 atomicAdd(&gm_f[ai][m], f_i[m]);
307 atomicAdd(&gm_f[aj][m], f_j[m]);
308 atomicAdd(&gm_f[ak][m], f_k[m]);
311 atomicAdd(&sm_fShiftLoc[t1][m], f_i[m]);
312 atomicAdd(&sm_fShiftLoc[CENTRAL][m], f_j[m]);
313 atomicAdd(&sm_fShiftLoc[t2][m], f_k[m]);
318 /* Time for the bond calculations */
326 fbond *= rsqrtf(dr2);
329 for (int m = 0; m < DIM; m++)
331 float fik = fbond*r_ik[m];
332 atomicAdd(&gm_f[ai][m], fik);
333 atomicAdd(&gm_f[ak][m], -fik);
335 if (calcVir && ki != CENTRAL)
337 atomicAdd(&sm_fShiftLoc[ki][m], fik);
338 atomicAdd(&sm_fShiftLoc[CENTRAL][m], -fik);
345 template <bool returnShift, typename T>
346 __device__ __forceinline__
347 static float dih_angle_gpu(const T xi, const T xj, const T xk, const T xl,
348 const PbcAiuc &pbcAiuc,
349 fvec r_ij, fvec r_kj, fvec r_kl, fvec m, fvec n,
350 int *t1, int *t2, int *t3)
352 *t1 = pbcDxAiuc<returnShift>(pbcAiuc, xi, xj, r_ij);
353 *t2 = pbcDxAiuc<returnShift>(pbcAiuc, xk, xj, r_kj);
354 *t3 = pbcDxAiuc<returnShift>(pbcAiuc, xk, xl, r_kl);
356 cprod_gpu(r_ij, r_kj, m);
357 cprod_gpu(r_kj, r_kl, n);
358 float phi = gmx_angle_gpu(m, n);
359 float ipr = iprod_gpu(r_ij, n);
360 float sign = (ipr < 0.0f) ? -1.0f : 1.0f;
367 __device__ __forceinline__
368 static void dopdihs_gpu(const float cpA, const float phiA, const int mult,
369 const float phi, float *v, float *f)
373 mdphi = mult*phi - phiA*DEG2RAD;
375 *v = cpA * (1.0f + cosf(mdphi));
376 *f = -cpA*mult*sdphi;
379 template <bool calcVir>
381 static void do_dih_fup_gpu(const int i, const int j, const int k, const int l,
382 const float ddphi, const fvec r_ij, const fvec r_kj, const fvec r_kl,
383 const fvec m, const fvec n, fvec gm_f[], fvec sm_fShiftLoc[],
384 const PbcAiuc &pbcAiuc,
385 const float4 gm_xq[], const int t1, const int t2, const int gmx_unused t3)
387 float iprm = iprod_gpu(m, m);
388 float iprn = iprod_gpu(n, n);
389 float nrkj2 = iprod_gpu(r_kj, r_kj);
390 float toler = nrkj2*GMX_REAL_EPS;
391 if ((iprm > toler) && (iprn > toler))
393 float nrkj_1 = rsqrtf(nrkj2); // replacing std::invsqrt call
394 float nrkj_2 = nrkj_1*nrkj_1;
395 float nrkj = nrkj2*nrkj_1;
396 float a = -ddphi*nrkj/iprm;
398 svmul_gpu(a, m, f_i);
399 float b = ddphi*nrkj/iprn;
401 svmul_gpu(b, n, f_l);
402 float p = iprod_gpu(r_ij, r_kj);
404 float q = iprod_gpu(r_kl, r_kj);
407 svmul_gpu(p, f_i, uvec);
409 svmul_gpu(q, f_l, vvec);
411 fvec_sub_gpu(uvec, vvec, svec);
413 fvec_sub_gpu(f_i, svec, f_j);
415 fvec_add_gpu(f_l, svec, f_k);
417 for (int m = 0; (m < DIM); m++)
419 atomicAdd(&gm_f[i][m], f_i[m]);
420 atomicAdd(&gm_f[j][m], -f_j[m]);
421 atomicAdd(&gm_f[k][m], -f_k[m]);
422 atomicAdd(&gm_f[l][m], f_l[m]);
428 int t3 = pbcDxAiuc<calcVir>(pbcAiuc, gm_xq[l], gm_xq[j], dx_jl);
431 for (int m = 0; (m < DIM); m++)
433 atomicAdd(&sm_fShiftLoc[t1][m], f_i[m]);
434 atomicAdd(&sm_fShiftLoc[CENTRAL][m], -f_j[m]);
435 atomicAdd(&sm_fShiftLoc[t2][m], -f_k[m]);
436 atomicAdd(&sm_fShiftLoc[t3][m], f_l[m]);
442 template <bool calcVir, bool calcEner>
444 void pdihs_gpu(const int i, float *vtot_loc, const int numBonds,
445 const t_iatom d_forceatoms[], const t_iparams d_forceparams[],
446 const float4 gm_xq[], fvec gm_f[], fvec sm_fShiftLoc[],
447 const PbcAiuc pbcAiuc)
451 int type = d_forceatoms[5*i];
452 int ai = d_forceatoms[5*i + 1];
453 int aj = d_forceatoms[5*i + 2];
454 int ak = d_forceatoms[5*i + 3];
455 int al = d_forceatoms[5*i + 4];
466 dih_angle_gpu<calcVir>(gm_xq[ai], gm_xq[aj], gm_xq[ak], gm_xq[al], pbcAiuc,
467 r_ij, r_kj, r_kl, m, n, &t1, &t2, &t3);
471 dopdihs_gpu(d_forceparams[type].pdihs.cpA,
472 d_forceparams[type].pdihs.phiA,
473 d_forceparams[type].pdihs.mult,
481 do_dih_fup_gpu<calcVir>(ai, aj, ak, al,
482 ddphi, r_ij, r_kj, r_kl, m, n,
483 gm_f, sm_fShiftLoc, pbcAiuc,
489 template <bool calcVir, bool calcEner>
491 void rbdihs_gpu(const int i, float *vtot_loc, const int numBonds,
492 const t_iatom d_forceatoms[], const t_iparams d_forceparams[],
493 const float4 gm_xq[], fvec gm_f[], fvec sm_fShiftLoc[],
494 const PbcAiuc pbcAiuc)
496 constexpr float c0 = 0.0f, c1 = 1.0f, c2 = 2.0f, c3 = 3.0f, c4 = 4.0f, c5 = 5.0f;
500 int type = d_forceatoms[5*i];
501 int ai = d_forceatoms[5*i+1];
502 int aj = d_forceatoms[5*i+2];
503 int ak = d_forceatoms[5*i+3];
504 int al = d_forceatoms[5*i+4];
515 dih_angle_gpu<calcVir>(gm_xq[ai], gm_xq[aj], gm_xq[ak], gm_xq[al], pbcAiuc,
516 r_ij, r_kj, r_kl, m, n, &t1, &t2, &t3);
518 /* Change to polymer convention */
528 float cos_phi = cosf(phi);
529 /* Beware of accuracy loss, cannot use 1-sqrt(cos^2) ! */
530 float sin_phi = sinf(phi);
532 float parm[NR_RBDIHS];
533 for (int j = 0; j < NR_RBDIHS; j++)
535 parm[j] = d_forceparams[type].rbdihs.rbcA[j];
537 /* Calculate cosine powers */
538 /* Calculate the energy */
539 /* Calculate the derivative */
552 ddphi += c2*rbp*cosfac;
559 ddphi += c3*rbp*cosfac;
566 ddphi += c4*rbp*cosfac;
573 ddphi += c5*rbp*cosfac;
580 ddphi = -ddphi*sin_phi;
582 do_dih_fup_gpu<calcVir>(ai, aj, ak, al,
583 ddphi, r_ij, r_kj, r_kl, m, n,
584 gm_f, sm_fShiftLoc, pbcAiuc,
593 __device__ __forceinline__
594 static void make_dp_periodic_gpu(float *dp)
596 /* dp cannot be outside (-pi,pi) */
597 if (*dp >= CUDART_PI_F)
599 *dp -= 2.0f*CUDART_PI_F;
601 else if (*dp < -CUDART_PI_F)
603 *dp += 2.0f*CUDART_PI_F;
607 template <bool calcVir, bool calcEner>
609 void idihs_gpu(const int i, float *vtot_loc, const int numBonds,
610 const t_iatom d_forceatoms[], const t_iparams d_forceparams[],
611 const float4 gm_xq[], fvec gm_f[], fvec sm_fShiftLoc[],
612 const PbcAiuc pbcAiuc)
616 int type = d_forceatoms[5*i];
617 int ai = d_forceatoms[5*i + 1];
618 int aj = d_forceatoms[5*i + 2];
619 int ak = d_forceatoms[5*i + 3];
620 int al = d_forceatoms[5*i + 4];
631 dih_angle_gpu<calcVir>(gm_xq[ai], gm_xq[aj], gm_xq[ak], gm_xq[al], pbcAiuc,
632 r_ij, r_kj, r_kl, m, n, &t1, &t2, &t3);
634 /* phi can jump if phi0 is close to Pi/-Pi, which will cause huge
635 * force changes if we just apply a normal harmonic.
636 * Instead, we first calculate phi-phi0 and take it modulo (-Pi,Pi).
637 * This means we will never have the periodicity problem, unless
638 * the dihedral is Pi away from phiO, which is very unlikely due to
641 float kA = d_forceparams[type].harmonic.krA;
642 float pA = d_forceparams[type].harmonic.rA;
644 float phi0 = pA*DEG2RAD;
646 float dp = phi - phi0;
648 make_dp_periodic_gpu(&dp);
650 float ddphi = -kA*dp;
652 do_dih_fup_gpu<calcVir>(ai, aj, ak, al,
653 -ddphi, r_ij, r_kj, r_kl, m, n,
654 gm_f, sm_fShiftLoc, pbcAiuc,
659 *vtot_loc += -0.5f*ddphi*dp;
664 template <bool calcVir, bool calcEner>
666 void pairs_gpu(const int i, const int numBonds,
667 const t_iatom d_forceatoms[], const t_iparams iparams[],
668 const float4 gm_xq[], fvec gm_f[], fvec sm_fShiftLoc[],
669 const PbcAiuc pbcAiuc,
670 const float scale_factor,
671 float *vtotVdw_loc, float *vtotElec_loc)
675 int3 pairData = *(int3 *)(d_forceatoms + 3 * i);
676 int type = pairData.x;
680 float qq = gm_xq[ai].w*gm_xq[aj].w;
681 float c6 = iparams[type].lj14.c6A;
682 float c12 = iparams[type].lj14.c12A;
684 /* Do we need to apply full periodic boundary conditions? */
686 int fshift_index = pbcDxAiuc<calcVir>(pbcAiuc, gm_xq[ai], gm_xq[aj], dr);
688 float r2 = norm2_gpu(dr);
689 float rinv = rsqrtf(r2);
690 float rinv2 = rinv*rinv;
691 float rinv6 = rinv2*rinv2*rinv2;
693 /* Calculate the Coulomb force * r */
694 float velec = scale_factor*qq*rinv;
696 /* Calculate the LJ force * r and add it to the Coulomb part */
697 float fr = (12.0f*c12*rinv6 - 6.0f*c6)*rinv6 + velec;
699 float finvr = fr * rinv2;
701 svmul_gpu(finvr, dr, f);
705 for (int m = 0; m < DIM; m++)
707 atomicAdd(&gm_f[ai][m], f[m]);
708 atomicAdd(&gm_f[aj][m], -f[m]);
709 if (calcVir && fshift_index != CENTRAL)
711 atomicAdd(&sm_fShiftLoc[fshift_index][m], f[m]);
712 atomicAdd(&sm_fShiftLoc[CENTRAL][m], -f[m]);
718 *vtotVdw_loc += (c12*rinv6 - c6)*rinv6;
719 *vtotElec_loc += velec;
727 template <bool calcVir, bool calcEner>
729 void exec_kernel_gpu(BondedCudaKernelParameters kernelParams)
731 assert(blockDim.y == 1 && blockDim.z == 1);
732 const int tid = blockIdx.x*blockDim.x+threadIdx.x;
734 float vtotVdw_loc = 0;
735 float vtotElec_loc = 0;
736 __shared__ fvec sm_fShiftLoc[SHIFTS];
740 if (threadIdx.x < SHIFTS)
742 sm_fShiftLoc[threadIdx.x][XX] = 0.0f;
743 sm_fShiftLoc[threadIdx.x][YY] = 0.0f;
744 sm_fShiftLoc[threadIdx.x][ZZ] = 0.0f;
750 bool threadComputedPotential = false;
752 for (int j = 0; j < numFTypesOnGpu; j++)
754 if (tid >= kernelParams.fTypeRangeStart[j] && tid <= kernelParams.fTypeRangeEnd[j])
756 const int numBonds = kernelParams.numFTypeBonds[j];
757 int fTypeTid = tid - kernelParams.fTypeRangeStart[j];
758 const t_iatom *iatoms = kernelParams.d_iatoms[j];
759 fType = kernelParams.fTypesOnGpu[j];
762 threadComputedPotential = true;
768 bonds_gpu<calcVir, calcEner>(fTypeTid, &vtot_loc, numBonds, iatoms, kernelParams.d_forceParams,
769 kernelParams.d_xq, kernelParams.d_f, sm_fShiftLoc, kernelParams.pbcAiuc);
772 angles_gpu<calcVir, calcEner>(fTypeTid, &vtot_loc, numBonds, iatoms, kernelParams.d_forceParams,
773 kernelParams.d_xq, kernelParams.d_f, sm_fShiftLoc, kernelParams.pbcAiuc);
776 urey_bradley_gpu<calcVir, calcEner>(fTypeTid, &vtot_loc, numBonds, iatoms, kernelParams.d_forceParams,
777 kernelParams.d_xq, kernelParams.d_f, sm_fShiftLoc, kernelParams.pbcAiuc);
781 pdihs_gpu<calcVir, calcEner>(fTypeTid, &vtot_loc, numBonds, iatoms, kernelParams.d_forceParams,
782 kernelParams.d_xq, kernelParams.d_f, sm_fShiftLoc, kernelParams.pbcAiuc);
785 rbdihs_gpu<calcVir, calcEner>(fTypeTid, &vtot_loc, numBonds, iatoms, kernelParams.d_forceParams,
786 kernelParams.d_xq, kernelParams.d_f, sm_fShiftLoc, kernelParams.pbcAiuc);
789 idihs_gpu<calcVir, calcEner>(fTypeTid, &vtot_loc, numBonds, iatoms, kernelParams.d_forceParams,
790 kernelParams.d_xq, kernelParams.d_f, sm_fShiftLoc, kernelParams.pbcAiuc);
793 pairs_gpu<calcVir, calcEner>(fTypeTid, numBonds, iatoms, kernelParams.d_forceParams,
794 kernelParams.d_xq, kernelParams.d_f, sm_fShiftLoc, kernelParams.pbcAiuc,
795 kernelParams.scaleFactor, &vtotVdw_loc, &vtotElec_loc);
802 if (threadComputedPotential)
804 float *vtotVdw = kernelParams.d_vTot + F_LJ14;
805 float *vtotElec = kernelParams.d_vTot + F_COUL14;
806 atomicAdd(kernelParams.d_vTot + fType, vtot_loc);
807 atomicAdd(vtotVdw, vtotVdw_loc);
808 atomicAdd(vtotElec, vtotElec_loc);
810 /* Accumulate shift vectors from shared memory to global memory on the first SHIFTS threads of the block. */
814 if (threadIdx.x < SHIFTS)
816 fvec_inc_atomic(kernelParams.d_fShift[threadIdx.x], sm_fShiftLoc[threadIdx.x]);
822 /*-------------------------------- End CUDA kernels-----------------------------*/
825 template <bool calcVir, bool calcEner>
827 GpuBonded::Impl::launchKernel(const t_forcerec *fr,
830 GMX_ASSERT(haveInteractions_,
831 "Cannot launch bonded GPU kernels unless bonded GPU work was scheduled");
832 static_assert(TPB_BONDED >= SHIFTS, "TPB_BONDED must be >= SHIFTS for the virial kernel (calcVir=true)");
835 setPbcAiuc(fr->bMolPBC ? ePBC2npbcdim(fr->ePBC) : 0, box, &pbcAiuc);
837 int fTypeRangeEnd = kernelParams_.fTypeRangeEnd[numFTypesOnGpu - 1];
839 if (fTypeRangeEnd < 0)
844 KernelLaunchConfig config;
845 config.blockSize[0] = TPB_BONDED;
846 config.blockSize[1] = 1;
847 config.blockSize[2] = 1;
848 config.gridSize[0] = (fTypeRangeEnd + TPB_BONDED)/TPB_BONDED;
849 config.gridSize[1] = 1;
850 config.gridSize[2] = 1;
851 config.stream = stream_;
853 auto kernelPtr = exec_kernel_gpu<calcVir, calcEner>;
854 kernelParams_.scaleFactor = fr->ic->epsfac*fr->fudgeQQ;
855 kernelParams_.pbcAiuc = pbcAiuc;
857 const auto kernelArgs = prepareGpuKernelArguments(kernelPtr, config, &kernelParams_);
859 launchGpuKernel(kernelPtr, config, nullptr, "exec_kernel_gpu<calcVir, calcEner>", kernelArgs);
863 GpuBonded::launchKernel(const t_forcerec *fr,
867 if (forceFlags & GMX_FORCE_ENERGY)
869 // When we need the energy, we also need the virial
870 impl_->launchKernel<true, true>
873 else if (forceFlags & GMX_FORCE_VIRIAL)
875 impl_->launchKernel<true, false>
880 impl_->launchKernel<false, false>