From 188bfacdf709c37b0a9cf5a91fb6b72b56012b9c Mon Sep 17 00:00:00 2001 From: ejjordan Date: Wed, 24 Mar 2021 23:33:40 +0100 Subject: [PATCH] ArrayRef and const ref in gmx_nb_free_energy_kernel Use const ref where possible in nonbonded free energy kernels. Also use ArrayRef for passing coordinates. --- .../gmxlib/nonbonded/nb_free_energy.cpp | 110 +++++++++--------- src/gromacs/gmxlib/nonbonded/nb_free_energy.h | 20 ++-- src/gromacs/mdlib/sim_util.cpp | 8 +- src/gromacs/nbnxm/kerneldispatch.cpp | 18 +-- src/gromacs/nbnxm/nbnxm.h | 20 ++-- 5 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp b/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp index 66adc9fc3e..5fb29200b8 100644 --- a/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp +++ b/src/gromacs/gmxlib/nonbonded/nb_free_energy.cpp @@ -199,16 +199,16 @@ static inline RealType potSwitchPotentialMod(const RealType potentialInp, //! Templated free-energy non-bonded kernel template -static void nb_free_energy_kernel(const t_nblist* gmx_restrict nlist, - rvec* gmx_restrict xx, - gmx::ForceWithShiftForces* forceWithShiftForces, - const t_forcerec* gmx_restrict fr, - const t_mdatoms* gmx_restrict mdatoms, - int flags, - gmx::ArrayRef lambda, - gmx::ArrayRef dvdl, - gmx::ArrayRef energygrp_elec, - gmx::ArrayRef energygrp_vdw, +static void nb_free_energy_kernel(const t_nblist& nlist, + gmx::ArrayRef coords, + gmx::ForceWithShiftForces* forceWithShiftForces, + const t_forcerec& fr, + const t_mdatoms& mdatoms, + int flags, + gmx::ArrayRef lambda, + gmx::ArrayRef dvdl, + gmx::ArrayRef energygrp_elec, + gmx::ArrayRef energygrp_vdw, t_nrnb* gmx_restrict nrnb) { #define STATE_A 0 @@ -228,24 +228,24 @@ static void nb_free_energy_kernel(const t_nblist* gmx_restrict nlist, constexpr real six = 6.0; /* Extract pointer to non-bonded interaction constants */ - const interaction_const_t* ic = fr->ic.get(); + const interaction_const_t* ic = fr.ic.get(); // Extract pair list data - const int nri = nlist->nri; - gmx::ArrayRef iinr = nlist->iinr; - gmx::ArrayRef jindex = nlist->jindex; - gmx::ArrayRef jjnr = nlist->jjnr; - gmx::ArrayRef shift = nlist->shift; - gmx::ArrayRef gid = nlist->gid; - - const real* shiftvec = fr->shift_vec[0]; - const real* chargeA = mdatoms->chargeA; - const real* chargeB = mdatoms->chargeB; - const int* typeA = mdatoms->typeA; - const int* typeB = mdatoms->typeB; - const int ntype = fr->ntype; - gmx::ArrayRef nbfp = fr->nbfp; - gmx::ArrayRef nbfp_grid = fr->ljpme_c6grid; + const int nri = nlist.nri; + gmx::ArrayRef iinr = nlist.iinr; + gmx::ArrayRef jindex = nlist.jindex; + gmx::ArrayRef jjnr = nlist.jjnr; + gmx::ArrayRef shift = nlist.shift; + gmx::ArrayRef gid = nlist.gid; + + const real* shiftvec = fr.shift_vec[0]; + const real* chargeA = mdatoms.chargeA; + const real* chargeB = mdatoms.chargeB; + const int* typeA = mdatoms.typeA; + const int* typeB = mdatoms.typeB; + const int ntype = fr.ntype; + gmx::ArrayRef nbfp = fr.nbfp; + gmx::ArrayRef nbfp_grid = fr.ljpme_c6grid; const real lambda_coul = lambda[static_cast(FreeEnergyPerturbationCouplingType::Coul)]; const real lambda_vdw = lambda[static_cast(FreeEnergyPerturbationCouplingType::Vdw)]; @@ -374,11 +374,11 @@ static void nb_free_energy_kernel(const t_nblist* gmx_restrict nlist, } // TODO: We should get rid of using pointers to real - const real* x = xx[0]; + const real* x = coords[0]; 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(fr.rlist); int numExcludedPairsBeyondRlist = 0; @@ -421,7 +421,7 @@ static void nb_free_energy_kernel(const t_nblist* gmx_restrict nlist, const RealType rSq = dX * dX + dY * dY + dZ * dZ; RealType fScalC[NSTATES], fScalV[NSTATES]; /* Check if this pair on the exlusions list.*/ - const bool bPairIncluded = nlist->excl_fep.empty() || nlist->excl_fep[k]; + const bool bPairIncluded = nlist.excl_fep.empty() || nlist.excl_fep[k]; if (rSq >= rcutoff_max2 && bPairIncluded) { @@ -849,7 +849,7 @@ static void nb_free_energy_kernel(const t_nblist* gmx_restrict nlist, * 12 flops per outer iteration * 150 flops per inner iteration */ - atomicNrnbIncrement(nrnb, eNR_NBKERNEL_FREE_ENERGY, nlist->nri * 12 + nlist->jindex[nri] * 150); + atomicNrnbIncrement(nrnb, eNR_NBKERNEL_FREE_ENERGY, nlist.nri * 12 + nlist.jindex[nri] * 150); if (numExcludedPairsBeyondRlist > 0) { @@ -862,20 +862,20 @@ static void nb_free_energy_kernel(const t_nblist* gmx_restrict 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); + fr.rlist); } } -typedef void (*KernelFunction)(const t_nblist* gmx_restrict nlist, - rvec* gmx_restrict xx, - gmx::ForceWithShiftForces* forceWithShiftForces, - const t_forcerec* gmx_restrict fr, - const t_mdatoms* gmx_restrict mdatoms, - int flags, - gmx::ArrayRef lambda, - gmx::ArrayRef dvdl, - gmx::ArrayRef energygrp_elec, - gmx::ArrayRef energygrp_vdw, +typedef void (*KernelFunction)(const t_nblist& nlist, + gmx::ArrayRef coords, + gmx::ForceWithShiftForces* forceWithShiftForces, + const t_forcerec& fr, + const t_mdatoms& mdatoms, + int flags, + gmx::ArrayRef lambda, + gmx::ArrayRef dvdl, + gmx::ArrayRef energygrp_elec, + gmx::ArrayRef energygrp_vdw, t_nrnb* gmx_restrict nrnb); template @@ -991,19 +991,19 @@ static KernelFunction dispatchKernel(const bool scLambdasOrAlpha } -void gmx_nb_free_energy_kernel(const t_nblist* nlist, - rvec* xx, - gmx::ForceWithShiftForces* ff, - const t_forcerec* fr, - const t_mdatoms* mdatoms, - int flags, - gmx::ArrayRef lambda, - gmx::ArrayRef dvdl, - gmx::ArrayRef energygrp_elec, - gmx::ArrayRef energygrp_vdw, - t_nrnb* nrnb) +void gmx_nb_free_energy_kernel(const t_nblist& nlist, + gmx::ArrayRef coords, + gmx::ForceWithShiftForces* ff, + const t_forcerec& fr, + const t_mdatoms& mdatoms, + int flags, + gmx::ArrayRef lambda, + gmx::ArrayRef dvdl, + gmx::ArrayRef energygrp_elec, + gmx::ArrayRef energygrp_vdw, + t_nrnb* nrnb) { - const interaction_const_t& ic = *fr->ic; + 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"); @@ -1013,7 +1013,7 @@ 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; + const bool useSimd = fr.use_simd_kernels; if (scParams.alphaCoulomb == 0 && scParams.alphaVdw == 0) { @@ -1036,5 +1036,5 @@ void gmx_nb_free_energy_kernel(const t_nblist* nlist, vdwModifierIsPotSwitch, useSimd, ic); - kernelFunc(nlist, xx, ff, fr, mdatoms, flags, lambda, dvdl, energygrp_elec, energygrp_vdw, nrnb); + kernelFunc(nlist, coords, ff, fr, mdatoms, flags, lambda, dvdl, energygrp_elec, energygrp_vdw, nrnb); } diff --git a/src/gromacs/gmxlib/nonbonded/nb_free_energy.h b/src/gromacs/gmxlib/nonbonded/nb_free_energy.h index d3cf9f546e..67920fc4ae 100644 --- a/src/gromacs/gmxlib/nonbonded/nb_free_energy.h +++ b/src/gromacs/gmxlib/nonbonded/nb_free_energy.h @@ -52,16 +52,16 @@ template class ArrayRef; } // namespace gmx -void gmx_nb_free_energy_kernel(const t_nblist* gmx_restrict nlist, - rvec* gmx_restrict xx, - gmx::ForceWithShiftForces* forceWithShiftForces, - const t_forcerec* gmx_restrict fr, - const t_mdatoms* gmx_restrict mdatoms, - int flags, - gmx::ArrayRef lambda, - gmx::ArrayRef dvdl, - gmx::ArrayRef energygrp_elec, - gmx::ArrayRef energygrp_vdw, +void gmx_nb_free_energy_kernel(const t_nblist& nlist, + gmx::ArrayRef coords, + gmx::ForceWithShiftForces* forceWithShiftForces, + const t_forcerec& fr, + const t_mdatoms& mdatoms, + int flags, + gmx::ArrayRef lambda, + gmx::ArrayRef dvdl, + gmx::ArrayRef energygrp_elec, + gmx::ArrayRef energygrp_vdw, t_nrnb* gmx_restrict nrnb); #endif diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index 362cbaccf4..abb68c4a76 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -1756,8 +1756,8 @@ void do_force(FILE* fplog, * Happens here on the CPU both with and without GPU. */ nbv->dispatchFreeEnergyKernel(InteractionLocality::Local, - fr, - as_rvec_array(x.unpaddedArrayRef().data()), + *fr, + x.unpaddedArrayRef(), &forceOutNonbonded->forceWithShiftForces(), *mdatoms, inputrec.fepvals.get(), @@ -1769,8 +1769,8 @@ void do_force(FILE* fplog, if (havePPDomainDecomposition(cr)) { nbv->dispatchFreeEnergyKernel(InteractionLocality::NonLocal, - fr, - as_rvec_array(x.unpaddedArrayRef().data()), + *fr, + x.unpaddedArrayRef(), &forceOutNonbonded->forceWithShiftForces(), *mdatoms, inputrec.fepvals.get(), diff --git a/src/gromacs/nbnxm/kerneldispatch.cpp b/src/gromacs/nbnxm/kerneldispatch.cpp index ca88b0a5b6..e40f04f8bb 100644 --- a/src/gromacs/nbnxm/kerneldispatch.cpp +++ b/src/gromacs/nbnxm/kerneldispatch.cpp @@ -493,9 +493,9 @@ void nonbonded_verlet_t::dispatchNonbondedKernel(gmx::InteractionLocality iLoc accountFlops(nrnb, pairlistSet, *this, ic, stepWork); } -void nonbonded_verlet_t::dispatchFreeEnergyKernel(gmx::InteractionLocality iLocality, - const t_forcerec* fr, - rvec x[], +void nonbonded_verlet_t::dispatchFreeEnergyKernel(gmx::InteractionLocality iLocality, + const t_forcerec& fr, + gmx::ArrayRef coords, gmx::ForceWithShiftForces* forceWithShiftForces, const t_mdatoms& mdatoms, t_lambda* fepvals, @@ -546,11 +546,11 @@ void nonbonded_verlet_t::dispatchFreeEnergyKernel(gmx::InteractionLocality iLo { try { - gmx_nb_free_energy_kernel(nbl_fep[th].get(), - x, + gmx_nb_free_energy_kernel(*nbl_fep[th], + coords, forceWithShiftForces, fr, - &mdatoms, + mdatoms, kernelFlags, kernelLambda, kernelDvdl, @@ -604,11 +604,11 @@ void nonbonded_verlet_t::dispatchFreeEnergyKernel(gmx::InteractionLocality iLo { try { - gmx_nb_free_energy_kernel(nbl_fep[th].get(), - x, + gmx_nb_free_energy_kernel(*nbl_fep[th], + coords, forceWithShiftForces, fr, - &mdatoms, + mdatoms, kernelFlags, kernelLambda, kernelDvdl, diff --git a/src/gromacs/nbnxm/nbnxm.h b/src/gromacs/nbnxm/nbnxm.h index a36efad023..37f09824e7 100644 --- a/src/gromacs/nbnxm/nbnxm.h +++ b/src/gromacs/nbnxm/nbnxm.h @@ -367,16 +367,16 @@ public: t_nrnb* nrnb); //! Executes the non-bonded free-energy kernel, always runs on the CPU - void dispatchFreeEnergyKernel(gmx::InteractionLocality iLocality, - const t_forcerec* fr, - rvec x[], - gmx::ForceWithShiftForces* forceWithShiftForces, - const t_mdatoms& mdatoms, - t_lambda* fepvals, - gmx::ArrayRef lambda, - gmx_enerdata_t* enerd, - const gmx::StepWorkload& stepWork, - t_nrnb* nrnb); + void dispatchFreeEnergyKernel(gmx::InteractionLocality iLocality, + const t_forcerec& fr, + gmx::ArrayRef coords, + gmx::ForceWithShiftForces* forceWithShiftForces, + const t_mdatoms& mdatoms, + t_lambda* fepvals, + gmx::ArrayRef lambda, + gmx_enerdata_t* enerd, + const gmx::StepWorkload& stepWork, + t_nrnb* nrnb); /*! \brief Add the forces stored in nbat to f, zeros the forces in nbat * \param [in] locality Local or non-local -- 2.22.0