Pass forcerec arguments instead of forcerec to gmx_nb_free_energy_kernel
authorJoe Jordan <ejjordan12@gmail.com>
Wed, 14 Apr 2021 16:16:27 +0000 (16:16 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Wed, 14 Apr 2021 16:16:27 +0000 (16:16 +0000)
src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp
src/gromacs/gmxlib/nonbonded/nb_free_energy.h
src/gromacs/gmxlib/nonbonded/tests/nb_free_energy.cpp
src/gromacs/nbnxm/kerneldispatch.cpp

index 8fde84db9fd86cf40bee0c5703183df2834e5f7e..6f51cee1719de33b9676c411f265f135c23f09b8 100644 (file)
@@ -202,7 +202,12 @@ template<typename DataTypes, bool useSoftCore, bool scLambdasOrAlphasDiffer, boo
 static void nb_free_energy_kernel(const t_nblist&                nlist,
                                   gmx::ArrayRef<const gmx::RVec> coords,
                                   gmx::ForceWithShiftForces*     forceWithShiftForces,
-                                  const t_forcerec&              fr,
+                                  const int                      ntype,
+                                  const real                     rlist,
+                                  const interaction_const_t&     ic,
+                                  gmx::ArrayRef<const gmx::RVec> shiftvec,
+                                  gmx::ArrayRef<const real>      nbfp,
+                                  gmx::ArrayRef<const real>      nbfp_grid,
                                   gmx::ArrayRef<const real>      chargeA,
                                   gmx::ArrayRef<const real>      chargeB,
                                   gmx::ArrayRef<const int>       typeA,
@@ -230,9 +235,6 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
     constexpr real two        = 2.0;
     constexpr real six        = 6.0;
 
-    /* Extract pointer to non-bonded interaction constants */
-    const interaction_const_t* ic = fr.ic.get();
-
     // Extract pair list data
     const int                nri    = nlist.nri;
     gmx::ArrayRef<const int> iinr   = nlist.iinr;
@@ -241,14 +243,9 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
     gmx::ArrayRef<const int> shift  = nlist.shift;
     gmx::ArrayRef<const int> gid    = nlist.gid;
 
-    const auto                shiftvec  = fr.shift_vec;
-    const int                 ntype     = fr.ntype;
-    gmx::ArrayRef<const real> nbfp      = fr.nbfp;
-    gmx::ArrayRef<const real> nbfp_grid = fr.ljpme_c6grid;
-
     const real  lambda_coul   = lambda[static_cast<int>(FreeEnergyPerturbationCouplingType::Coul)];
     const real  lambda_vdw    = lambda[static_cast<int>(FreeEnergyPerturbationCouplingType::Vdw)];
-    const auto& scParams      = *ic->softCoreParameters;
+    const auto& scParams      = *ic.softCoreParameters;
     const real  alpha_coul    = scParams.alphaCoulomb;
     const real  alpha_vdw     = scParams.alphaVdw;
     const real  lam_power     = scParams.lambdaPower;
@@ -259,23 +256,23 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
     const bool  doPotential   = ((flags & GMX_NONBONDED_DO_POTENTIAL) != 0);
 
     // Extract data from interaction_const_t
-    const real facel           = ic->epsfac;
-    const real rCoulomb        = ic->rcoulomb;
-    const real krf             = ic->reactionFieldCoefficient;
-    const real crf             = ic->reactionFieldShift;
-    const real shLjEwald       = ic->sh_lj_ewald;
-    const real rVdw            = ic->rvdw;
-    const real dispersionShift = ic->dispersion_shift.cpot;
-    const real repulsionShift  = ic->repulsion_shift.cpot;
+    const real facel           = ic.epsfac;
+    const real rCoulomb        = ic.rcoulomb;
+    const real krf             = ic.reactionFieldCoefficient;
+    const real crf             = ic.reactionFieldShift;
+    const real shLjEwald       = ic.sh_lj_ewald;
+    const real rVdw            = ic.rvdw;
+    const real dispersionShift = ic.dispersion_shift.cpot;
+    const real repulsionShift  = ic.repulsion_shift.cpot;
 
     // Note that the nbnxm kernels do not support Coulomb potential switching at all
-    GMX_ASSERT(ic->coulomb_modifier != InteractionModifiers::PotSwitch,
+    GMX_ASSERT(ic.coulomb_modifier != InteractionModifiers::PotSwitch,
                "Potential switching is not supported for Coulomb with FEP");
 
     real vdw_swV3, vdw_swV4, vdw_swV5, vdw_swF2, vdw_swF3, vdw_swF4;
     if (vdwModifierIsPotSwitch)
     {
-        const real d = ic->rvdw - ic->rvdw_switch;
+        const real d = ic.rvdw - ic.rvdw_switch;
         vdw_swV3     = -10.0 / (d * d * d);
         vdw_swV4     = 15.0 / (d * d * d * d);
         vdw_swV5     = -6.0 / (d * d * d * d * d);
@@ -290,7 +287,7 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
     }
 
     NbkernelElecType icoul;
-    if (ic->eeltype == CoulombInteractionType::Cut || EEL_RF(ic->eeltype))
+    if (ic.eeltype == CoulombInteractionType::Cut || EEL_RF(ic.eeltype))
     {
         icoul = NbkernelElecType::ReactionField;
     }
@@ -299,7 +296,7 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
         icoul = NbkernelElecType::None;
     }
 
-    real rcutoff_max2 = std::max(ic->rcoulomb, ic->rvdw);
+    real rcutoff_max2 = std::max(ic.rcoulomb, ic.rvdw);
     rcutoff_max2      = rcutoff_max2 * rcutoff_max2;
 
     const real* tab_ewald_F_lj           = nullptr;
@@ -312,18 +309,18 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
     real        sh_ewald                 = 0;
     if (elecInteractionTypeIsEwald || vdwInteractionTypeIsEwald)
     {
-        sh_ewald = ic->sh_ewald;
+        sh_ewald = ic.sh_ewald;
     }
     if (elecInteractionTypeIsEwald)
     {
-        const auto& coulombTables = *ic->coulombEwaldTables;
+        const auto& coulombTables = *ic.coulombEwaldTables;
         ewtab                     = coulombTables.tableFDV0.data();
         coulombTableScale         = coulombTables.scale;
         coulombTableScaleInvHalf  = half / coulombTableScale;
     }
     if (vdwInteractionTypeIsEwald)
     {
-        const auto& vdwTables = *ic->vdwEwaldTables;
+        const auto& vdwTables = *ic.vdwEwaldTables;
         tab_ewald_F_lj        = vdwTables.tableF.data();
         tab_ewald_V_lj        = vdwTables.tableV.data();
         vdwTableScale         = vdwTables.scale;
@@ -377,7 +374,7 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
     real* gmx_restrict f      = &(forceWithShiftForces->force()[0][0]);
     real* gmx_restrict fshift = &(forceWithShiftForces->shiftForces()[0][0]);
 
-    const real rlistSquared = gmx::square(fr.rlist);
+    const real rlistSquared = gmx::square(rlist);
 
     int numExcludedPairsBeyondRlist = 0;
 
@@ -624,7 +621,7 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
 
                             if (vdwModifierIsPotSwitch)
                             {
-                                RealType d        = rV - ic->rvdw_switch;
+                                RealType d        = rV - ic.rvdw_switch;
                                 d                 = (d > zero) ? d : zero;
                                 const RealType d2 = d * d;
                                 const RealType sw =
@@ -862,14 +859,19 @@ static void nb_free_energy_kernel(const t_nblist&                nlist,
                   "The error is likely triggered by the use of couple-intramol=no "
                   "and the maximal distance in the decoupled molecule exceeding rlist.",
                   numExcludedPairsBeyondRlist,
-                  fr.rlist);
+                  rlist);
     }
 }
 
 typedef void (*KernelFunction)(const t_nblist&                nlist,
                                gmx::ArrayRef<const gmx::RVec> coords,
                                gmx::ForceWithShiftForces*     forceWithShiftForces,
-                               const t_forcerec&              fr,
+                               const int                      ntype,
+                               const real                     rlist,
+                               const interaction_const_t&     ic,
+                               gmx::ArrayRef<const gmx::RVec> shiftvec,
+                               gmx::ArrayRef<const real>      nbfp,
+                               gmx::ArrayRef<const real>      nbfp_grid,
                                gmx::ArrayRef<const real>      chargeA,
                                gmx::ArrayRef<const real>      chargeB,
                                gmx::ArrayRef<const int>       typeA,
@@ -997,7 +999,13 @@ static KernelFunction dispatchKernel(const bool                 scLambdasOrAlpha
 void gmx_nb_free_energy_kernel(const t_nblist&                nlist,
                                gmx::ArrayRef<const gmx::RVec> coords,
                                gmx::ForceWithShiftForces*     ff,
-                               const t_forcerec&              fr,
+                               const bool                     useSimd,
+                               const int                      ntype,
+                               const real                     rlist,
+                               const interaction_const_t&     ic,
+                               gmx::ArrayRef<const gmx::RVec> shiftvec,
+                               gmx::ArrayRef<const real>      nbfp,
+                               gmx::ArrayRef<const real>      nbfp_grid,
                                gmx::ArrayRef<const real>      chargeA,
                                gmx::ArrayRef<const real>      chargeB,
                                gmx::ArrayRef<const int>       typeA,
@@ -1009,7 +1017,6 @@ void gmx_nb_free_energy_kernel(const t_nblist&                nlist,
                                gmx::ArrayRef<real>            energygrp_vdw,
                                t_nrnb*                        nrnb)
 {
-    const interaction_const_t& ic = *fr.ic;
     GMX_ASSERT(EEL_PME_EWALD(ic.eeltype) || ic.eeltype == CoulombInteractionType::Cut || EEL_RF(ic.eeltype),
                "Unsupported eeltype with free energy");
     GMX_ASSERT(ic.softCoreParameters, "We need soft-core parameters");
@@ -1019,7 +1026,6 @@ void gmx_nb_free_energy_kernel(const t_nblist&                nlist,
     const bool  elecInteractionTypeIsEwald = (EEL_PME_EWALD(ic.eeltype));
     const bool  vdwModifierIsPotSwitch     = (ic.vdw_modifier == InteractionModifiers::PotSwitch);
     bool        scLambdasOrAlphasDiffer    = true;
-    const bool  useSimd                    = fr.use_simd_kernels;
 
     if (scParams.alphaCoulomb == 0 && scParams.alphaVdw == 0)
     {
@@ -1042,5 +1048,23 @@ void gmx_nb_free_energy_kernel(const t_nblist&                nlist,
                                 vdwModifierIsPotSwitch,
                                 useSimd,
                                 ic);
-    kernelFunc(nlist, coords, ff, fr, chargeA, chargeB, typeA, typeB, flags, lambda, dvdl, energygrp_elec, energygrp_vdw, nrnb);
+    kernelFunc(nlist,
+               coords,
+               ff,
+               ntype,
+               rlist,
+               ic,
+               shiftvec,
+               nbfp,
+               nbfp_grid,
+               chargeA,
+               chargeB,
+               typeA,
+               typeB,
+               flags,
+               lambda,
+               dvdl,
+               energygrp_elec,
+               energygrp_vdw,
+               nrnb);
 }
index 97e64eb0ff858ea3277a8f49aac6812236dd97b2..c08ff371cfbe946974afd18f7bbb172272217ad1 100644 (file)
@@ -44,6 +44,7 @@
 struct t_forcerec;
 struct t_nrnb;
 struct t_nblist;
+struct interaction_const_t;
 namespace gmx
 {
 class ForceWithShiftForces;
@@ -54,7 +55,13 @@ class ArrayRef;
 void gmx_nb_free_energy_kernel(const t_nblist&                nlist,
                                gmx::ArrayRef<const gmx::RVec> coords,
                                gmx::ForceWithShiftForces*     forceWithShiftForces,
-                               const t_forcerec&              fr,
+                               bool                           useSimd,
+                               int                            ntype,
+                               real                           rlist,
+                               const interaction_const_t&     ic,
+                               gmx::ArrayRef<const gmx::RVec> shiftvec,
+                               gmx::ArrayRef<const real>      nbfp,
+                               gmx::ArrayRef<const real>      nbfp_grid,
                                gmx::ArrayRef<const real>      chargeA,
                                gmx::ArrayRef<const real>      chargeB,
                                gmx::ArrayRef<const int>       typeA,
index 145c70f34077d54b40c54ef964e88bf8740c06a7..5b7e08454c12a3ddd7631849dbec5966a7aafba5 100644 (file)
@@ -447,7 +447,13 @@ protected:
         gmx_nb_free_energy_kernel(nbl,
                                   x_.arrayRefWithPadding().unpaddedArrayRef(),
                                   &forces,
-                                  fr,
+                                  fr.use_simd_kernels,
+                                  fr.ntype,
+                                  fr.rlist,
+                                  *fr.ic,
+                                  fr.shift_vec,
+                                  fr.nbfp,
+                                  fr.ljpme_c6grid,
                                   input_.atoms.chargeA,
                                   input_.atoms.chargeB,
                                   input_.atoms.typeA,
index 93e28f8487da8041679dc4c6578aee1544727626..fbd58b0af744de2aa01304a411a02cf805e50cdf 100644 (file)
@@ -556,7 +556,13 @@ void nonbonded_verlet_t::dispatchFreeEnergyKernel(gmx::InteractionLocality
             gmx_nb_free_energy_kernel(*nbl_fep[th],
                                       coords,
                                       forceWithShiftForces,
-                                      fr,
+                                      fr.use_simd_kernels,
+                                      fr.ntype,
+                                      fr.rlist,
+                                      *fr.ic,
+                                      fr.shift_vec,
+                                      fr.nbfp,
+                                      fr.ljpme_c6grid,
                                       chargeA,
                                       chargeB,
                                       typeA,
@@ -617,7 +623,13 @@ void nonbonded_verlet_t::dispatchFreeEnergyKernel(gmx::InteractionLocality
                     gmx_nb_free_energy_kernel(*nbl_fep[th],
                                               coords,
                                               forceWithShiftForces,
-                                              fr,
+                                              fr.use_simd_kernels,
+                                              fr.ntype,
+                                              fr.rlist,
+                                              *fr.ic,
+                                              fr.shift_vec,
+                                              fr.nbfp,
+                                              fr.ljpme_c6grid,
                                               chargeA,
                                               chargeB,
                                               typeA,