From 18931f6cb5d801d1989de3d3291758752473de1c Mon Sep 17 00:00:00 2001 From: Berk Hess Date: Mon, 18 Mar 2019 13:30:47 +0100 Subject: [PATCH] Extract nbnxm PairlistSets The class PairlistSets was part of nonbonded_verlet_t. This change extracts it, moves it to pairlistsets.h and hides it from the rest of the code. This requires a few more, trivial, methods in nonbonded_verlet_t to operate on PairlistSets. Also renamed the pairlist params struct to PairlistParams and moved it to separate include and source files. Change-Id: I8e728663e145ce1f8504ae7302d7208344cc7cf3 --- src/gromacs/ewald/pme_load_balancing.cpp | 22 +-- src/gromacs/ewald/pme_load_balancing.h | 4 +- src/gromacs/mdlib/sim_util.cpp | 4 +- src/gromacs/mdrun/md.cpp | 2 +- .../nbnxm/cuda/nbnxm_cuda_data_mgmt.cu | 20 +- src/gromacs/nbnxm/gpu_data_mgmt.h | 7 +- src/gromacs/nbnxm/kerneldispatch.cpp | 1 + src/gromacs/nbnxm/nbnxm.cpp | 27 +++ src/gromacs/nbnxm/nbnxm.h | 185 ++---------------- src/gromacs/nbnxm/nbnxm_setup.cpp | 37 ++-- .../nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp | 20 +- src/gromacs/nbnxm/pairlist.cpp | 19 +- src/gromacs/nbnxm/pairlist.h | 6 +- src/gromacs/nbnxm/pairlist_tuning.cpp | 7 +- src/gromacs/nbnxm/pairlist_tuning.h | 4 +- src/gromacs/nbnxm/pairlistparams.cpp | 87 ++++++++ src/gromacs/nbnxm/pairlistparams.h | 87 ++++++++ src/gromacs/nbnxm/pairlistset.cpp | 47 +---- src/gromacs/nbnxm/pairlistsets.h | 169 ++++++++++++++++ src/gromacs/nbnxm/prunekerneldispatch.cpp | 18 +- 20 files changed, 486 insertions(+), 287 deletions(-) create mode 100644 src/gromacs/nbnxm/pairlistparams.cpp create mode 100644 src/gromacs/nbnxm/pairlistparams.h create mode 100644 src/gromacs/nbnxm/pairlistsets.h diff --git a/src/gromacs/ewald/pme_load_balancing.cpp b/src/gromacs/ewald/pme_load_balancing.cpp index ba3c90c12e..8e49c6330d 100644 --- a/src/gromacs/ewald/pme_load_balancing.cpp +++ b/src/gromacs/ewald/pme_load_balancing.cpp @@ -177,7 +177,7 @@ void pme_loadbal_init(pme_load_balancing_t **pme_lb_p, const t_inputrec &ir, const matrix box, const interaction_const_t &ic, - const NbnxnListParameters &listParams, + const nonbonded_verlet_t &nbv, gmx_pme_t *pmedata, gmx_bool bUseGPU, gmx_bool *bPrinting) @@ -206,10 +206,10 @@ void pme_loadbal_init(pme_load_balancing_t **pme_lb_p, pme_lb->cutoff_scheme = ir.cutoff_scheme; - pme_lb->rbufOuter_coulomb = listParams.rlistOuter - ic.rcoulomb; - pme_lb->rbufOuter_vdw = listParams.rlistOuter - ic.rvdw; - pme_lb->rbufInner_coulomb = listParams.rlistInner - ic.rcoulomb; - pme_lb->rbufInner_vdw = listParams.rlistInner - ic.rvdw; + pme_lb->rbufOuter_coulomb = nbv.pairlistOuterRadius() - ic.rcoulomb; + pme_lb->rbufOuter_vdw = nbv.pairlistOuterRadius() - ic.rvdw; + pme_lb->rbufInner_coulomb = nbv.pairlistInnerRadius() - ic.rcoulomb; + pme_lb->rbufInner_vdw = nbv.pairlistInnerRadius() - ic.rvdw; /* Scale box with Ewald wall factor; note that we pmedata->boxScaler * can't always usedd as it's not available with separate PME ranks. @@ -224,8 +224,8 @@ void pme_loadbal_init(pme_load_balancing_t **pme_lb_p, pme_lb->cur = 0; pme_lb->setup[0].rcut_coulomb = ic.rcoulomb; - pme_lb->setup[0].rlistOuter = listParams.rlistOuter; - pme_lb->setup[0].rlistInner = listParams.rlistInner; + pme_lb->setup[0].rlistOuter = nbv.pairlistOuterRadius(); + pme_lb->setup[0].rlistInner = nbv.pairlistInnerRadius(); pme_lb->setup[0].grid[XX] = ir.nkx; pme_lb->setup[0].grid[YY] = ir.nky; pme_lb->setup[0].grid[ZZ] = ir.nkz; @@ -794,7 +794,7 @@ pme_load_balance(pme_load_balancing_t *pme_lb, set = &pme_lb->setup[pme_lb->cur]; ic->rcoulomb = set->rcut_coulomb; - nbv->pairlistSets_->changeRadii(set->rlistOuter, set->rlistInner); + nbv->changePairlistRadii(set->rlistOuter, set->rlistInner); ic->ewaldcoeff_q = set->ewaldcoeff_q; /* TODO: centralize the code that sets the potentials shifts */ if (ic->coulomb_modifier == eintmodPOTSHIFT) @@ -822,7 +822,7 @@ pme_load_balance(pme_load_balancing_t *pme_lb, /* We always re-initialize the tables whether they are used or not */ init_interaction_const_tables(nullptr, ic, rtab); - Nbnxm::gpu_pme_loadbal_update_param(nbv, ic, &nbv->pairlistSets().params()); + Nbnxm::gpu_pme_loadbal_update_param(nbv, ic); if (!pme_lb->bSepPMERanks) { @@ -994,7 +994,7 @@ void pme_loadbal_do(pme_load_balancing_t *pme_lb, * This also ensures that we won't disable the currently * optimal setting during a second round of PME balancing. */ - set_dd_dlb_max_cutoff(cr, fr->nbv->pairlistSets().params().rlistOuter); + set_dd_dlb_max_cutoff(cr, fr->nbv->pairlistOuterRadius()); } } @@ -1011,7 +1011,7 @@ void pme_loadbal_do(pme_load_balancing_t *pme_lb, step); /* Update deprecated rlist in forcerec to stay in sync with fr->nbv */ - fr->rlist = fr->nbv->pairlistSets().params().rlistOuter; + fr->rlist = fr->nbv->pairlistOuterRadius(); if (ir.eDispCorr != edispcNO) { diff --git a/src/gromacs/ewald/pme_load_balancing.h b/src/gromacs/ewald/pme_load_balancing.h index 11ea28cb86..1d48b7cfb5 100644 --- a/src/gromacs/ewald/pme_load_balancing.h +++ b/src/gromacs/ewald/pme_load_balancing.h @@ -50,7 +50,7 @@ #include "gromacs/mdtypes/interaction_const.h" #include "gromacs/timing/wallcycle.h" -struct NbnxnListParameters; +struct nonbonded_verlet_t; struct t_commrec; struct t_inputrec; class t_state; @@ -80,7 +80,7 @@ void pme_loadbal_init(pme_load_balancing_t **pme_lb_p, const t_inputrec &ir, const matrix box, const interaction_const_t &ic, - const NbnxnListParameters &listParams, + const nonbonded_verlet_t &nbv, gmx_pme_t *pmedata, gmx_bool bUseGPU, gmx_bool *bPrinting); diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index 843b1db72d..596fc8fa75 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -329,7 +329,7 @@ static void do_nb_verlet(t_forcerec *fr, /* When dynamic pair-list pruning is requested, we need to prune * at nstlistPrune steps. */ - if (nbv->pairlistSets().isDynamicPruningStepCpu(step)) + if (nbv->isDynamicPruningStepCpu(step)) { /* Prune the pair-list beyond fr->ic->rlistPrune using * the current coordinates of the atoms. @@ -1393,7 +1393,7 @@ static void do_force_cutsVERLET(FILE *fplog, wallcycle_sub_start_nocount(wcycle, ewcsLAUNCH_GPU_NONBONDED); Nbnxm::gpu_clear_outputs(nbv->gpu_nbv, flags); - if (nbv->pairlistSets().isDynamicPruningStepGpu(step)) + if (nbv->isDynamicPruningStepGpu(step)) { nbv->dispatchPruneKernelGpu(step); } diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index 5e1db3704f..fc45d55448 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -413,7 +413,7 @@ void gmx::Integrator::do_md() if (bPMETune) { pme_loadbal_init(&pme_loadbal, cr, mdlog, *ir, state->box, - *fr->ic, fr->nbv->pairlistSets().params(), fr->pmedata, fr->nbv->useGpu(), + *fr->ic, *fr->nbv, fr->pmedata, fr->nbv->useGpu(), &bPMETunePrinting); } diff --git a/src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu b/src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu index b19b7f6c4c..46e8c771e3 100644 --- a/src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu +++ b/src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu @@ -60,6 +60,7 @@ #include "gromacs/nbnxm/atomdata.h" #include "gromacs/nbnxm/gpu_data_mgmt.h" #include "gromacs/nbnxm/nbnxm.h" +#include "gromacs/nbnxm/pairlistsets.h" #include "gromacs/pbcutil/ishift.h" #include "gromacs/timing/gpu_timing.h" #include "gromacs/utility/basedefinitions.h" @@ -203,7 +204,7 @@ static int pick_ewald_kernel_type(bool bTwinCut) /*! Copies all parameters related to the cut-off from ic to nbp */ static void set_cutoff_parameters(cu_nbparam_t *nbp, const interaction_const_t *ic, - const NbnxnListParameters *listParams) + const PairlistParams &listParams) { nbp->ewald_beta = ic->ewaldcoeff_q; nbp->sh_ewald = ic->sh_ewald; @@ -212,9 +213,9 @@ static void set_cutoff_parameters(cu_nbparam_t *nbp, nbp->c_rf = ic->c_rf; nbp->rvdw_sq = ic->rvdw * ic->rvdw; nbp->rcoulomb_sq = ic->rcoulomb * ic->rcoulomb; - nbp->rlistOuter_sq = listParams->rlistOuter * listParams->rlistOuter; - nbp->rlistInner_sq = listParams->rlistInner * listParams->rlistInner; - nbp->useDynamicPruning = listParams->useDynamicPruning; + nbp->rlistOuter_sq = listParams.rlistOuter * listParams.rlistOuter; + nbp->rlistInner_sq = listParams.rlistInner * listParams.rlistInner; + nbp->useDynamicPruning = listParams.useDynamicPruning; nbp->sh_lj_ewald = ic->sh_lj_ewald; nbp->ewaldcoeff_lj = ic->ewaldcoeff_lj; @@ -228,7 +229,7 @@ static void set_cutoff_parameters(cu_nbparam_t *nbp, /*! Initializes the nonbonded parameter data structure. */ static void init_nbparam(cu_nbparam_t *nbp, const interaction_const_t *ic, - const NbnxnListParameters *listParams, + const PairlistParams &listParams, const nbnxn_atomdata_t::Params &nbatParams) { int ntypes; @@ -339,8 +340,7 @@ static void init_nbparam(cu_nbparam_t *nbp, /*! Re-generate the GPU Ewald force table, resets rlist, and update the * electrostatic type switching to twin cut-off (or back) if needed. */ void gpu_pme_loadbal_update_param(const nonbonded_verlet_t *nbv, - const interaction_const_t *ic, - const NbnxnListParameters *listParams) + const interaction_const_t *ic) { if (!nbv || !nbv->useGpu()) { @@ -348,7 +348,7 @@ void gpu_pme_loadbal_update_param(const nonbonded_verlet_t *nbv, } cu_nbparam_t *nbp = nbv->gpu_nbv->nbparam; - set_cutoff_parameters(nbp, ic, listParams); + set_cutoff_parameters(nbp, ic, nbv->pairlistSets().params()); nbp->eeltype = pick_ewald_kernel_type(ic->rcoulomb != ic->rvdw); @@ -405,7 +405,7 @@ static void init_timings(gmx_wallclock_gpu_nbnxn_t *t) /*! Initializes simulation constant data. */ static void cuda_init_const(gmx_nbnxn_cuda_t *nb, const interaction_const_t *ic, - const NbnxnListParameters *listParams, + const PairlistParams &listParams, const nbnxn_atomdata_t::Params &nbatParams) { init_atomdata_first(nb->atdat, nbatParams.numTypes); @@ -418,7 +418,7 @@ static void cuda_init_const(gmx_nbnxn_cuda_t *nb, gmx_nbnxn_cuda_t * gpu_init(const gmx_device_info_t *deviceInfo, const interaction_const_t *ic, - const NbnxnListParameters *listParams, + const PairlistParams &listParams, const nbnxn_atomdata_t *nbat, int /*rank*/, gmx_bool bLocalAndNonlocal) diff --git a/src/gromacs/nbnxm/gpu_data_mgmt.h b/src/gromacs/nbnxm/gpu_data_mgmt.h index c1a19b7f63..407521c69d 100644 --- a/src/gromacs/nbnxm/gpu_data_mgmt.h +++ b/src/gromacs/nbnxm/gpu_data_mgmt.h @@ -55,7 +55,7 @@ struct nonbonded_verlet_group_t; struct NbnxnPairlistGpu; struct nbnxn_atomdata_t; -struct NbnxnListParameters; +struct PairlistParams; struct gmx_wallclock_gpu_nbnxn_t; struct gmx_gpu_info_t; struct gmx_device_info_t; @@ -68,7 +68,7 @@ GPU_FUNC_QUALIFIER gmx_nbnxn_gpu_t * gpu_init(const gmx_device_info_t gmx_unused *deviceInfo, const interaction_const_t gmx_unused *ic, - const NbnxnListParameters gmx_unused *listParams, + const PairlistParams gmx_unused &listParams, const nbnxn_atomdata_t gmx_unused *nbat, int gmx_unused rank, /* true if both local and non-local are done on GPU */ @@ -90,8 +90,7 @@ void gpu_init_atomdata(gmx_nbnxn_gpu_t gmx_unused *nb, */ GPU_FUNC_QUALIFIER void gpu_pme_loadbal_update_param(const struct nonbonded_verlet_t gmx_unused *nbv, - const interaction_const_t gmx_unused *ic, - const NbnxnListParameters gmx_unused *listParams) GPU_FUNC_TERM + const interaction_const_t gmx_unused *ic) GPU_FUNC_TERM /** Uploads shift vector to the GPU if the box is dynamic (otherwise just returns). */ GPU_FUNC_QUALIFIER diff --git a/src/gromacs/nbnxm/kerneldispatch.cpp b/src/gromacs/nbnxm/kerneldispatch.cpp index b676f0c077..6b40e39048 100644 --- a/src/gromacs/nbnxm/kerneldispatch.cpp +++ b/src/gromacs/nbnxm/kerneldispatch.cpp @@ -58,6 +58,7 @@ #include "gromacs/utility/real.h" #include "kernel_common.h" +#include "pairlistsets.h" #define INCLUDE_KERNELFUNCTION_TABLES #include "gromacs/nbnxm/kernels_reference/kernel_ref.h" #ifdef GMX_NBNXN_SIMD_2XNN diff --git a/src/gromacs/nbnxm/nbnxm.cpp b/src/gromacs/nbnxm/nbnxm.cpp index 270512b266..1d486c60bc 100644 --- a/src/gromacs/nbnxm/nbnxm.cpp +++ b/src/gromacs/nbnxm/nbnxm.cpp @@ -49,6 +49,7 @@ #include "gromacs/nbnxm/atomdata.h" #include "gromacs/timing/wallcycle.h" +#include "pairlistsets.h" #include "pairsearch.h" /*! \cond INTERNAL */ @@ -100,6 +101,16 @@ void nbnxn_put_on_grid_nonlocal(nonbonded_verlet_t *nbv, } } +bool nonbonded_verlet_t::isDynamicPruningStepCpu(int64_t step) const +{ + return pairlistSets_->isDynamicPruningStepCpu(step); +} + +bool nonbonded_verlet_t::isDynamicPruningStepGpu(int64_t step) const +{ + return pairlistSets_->isDynamicPruningStepGpu(step); +} + gmx::ArrayRef nonbonded_verlet_t::getLocalAtomOrder() const { /* Return the atom order for the home cell (index 0) */ @@ -170,4 +181,20 @@ nonbonded_verlet_t::atomdata_add_nbat_f_to_f(const Nbnxm::AtomLocality locality wallcycle_stop(wcycle, ewcNB_XF_BUF_OPS); } +real nonbonded_verlet_t::pairlistInnerRadius() const +{ + return pairlistSets_->params().rlistInner; +} + +real nonbonded_verlet_t::pairlistOuterRadius() const +{ + return pairlistSets_->params().rlistOuter; +} + +void nonbonded_verlet_t::changePairlistRadii(real rlistOuter, + real rlistInner) +{ + pairlistSets_->changePairlistRadii(rlistOuter, rlistInner); +} + /*! \endcond */ diff --git a/src/gromacs/nbnxm/nbnxm.h b/src/gromacs/nbnxm/nbnxm.h index 4c84070dde..24752af113 100644 --- a/src/gromacs/nbnxm/nbnxm.h +++ b/src/gromacs/nbnxm/nbnxm.h @@ -118,9 +118,8 @@ struct gmx_mtop_t; struct gmx_wallcycle; struct interaction_const_t; struct nonbonded_verlet_t; -enum class PairlistType; class PairSearch; -class PairlistSet; +class PairlistSets; struct t_blocka; struct t_commrec; struct t_lambda; @@ -140,39 +139,6 @@ namespace Nbnxm enum class KernelType; } -/*! \libinternal - * \brief The setup for generating and pruning the nbnxn pair list. - * - * Without dynamic pruning rlistOuter=rlistInner. - */ -struct NbnxnListParameters -{ - /*! \brief Constructor producing a struct with dynamic pruning disabled - */ - NbnxnListParameters(Nbnxm::KernelType kernelType, - bool haveFep, - real rlist, - bool haveMultipleDomains); - - PairlistType pairlistType; //!< The type of cluster-pair list - bool haveFep; //!< Tells whether we have perturbed interactions - real rlistOuter; //!< Cut-off of the larger, outer pair-list - real rlistInner; //!< Cut-off of the smaller, inner pair-list - bool haveMultipleDomains; //!< True when using DD with multiple domains - bool useDynamicPruning; //!< Are we using dynamic pair-list pruning - int nstlistPrune; //!< Pair-list dynamic pruning interval - int numRollingPruningParts; //!< The number parts to divide the pair-list into for rolling pruning, a value of 1 gives no rolling pruning - int lifetime; //!< Lifetime in steps of the pair-list -}; - -/*! \brief Resources that can be used to execute non-bonded kernels on */ -enum class NonbondedResource : int -{ - Cpu, - Gpu, - EmulateGpu -}; - namespace Nbnxm { @@ -220,134 +186,11 @@ enum { enbvClearFNo, enbvClearFYes }; -/*! \brief Generates a pair-list for the given locality. - * - * With perturbed particles, also a group scheme style nbl_fep list is made. - */ -void nbnxn_make_pairlist(nonbonded_verlet_t *nbv, - Nbnxm::InteractionLocality iLocality, - PairlistSet *pairlistSet, - const t_blocka *excl, - int64_t step, - t_nrnb *nrnb); - -/*! \brief Prune all pair-lists with given locality (currently CPU only) - * - * For all pair-lists with given locality, takes the outer list and prunes out - * pairs beyond the pairlist inner radius and writes the result to a list that is - * to be consumed by the non-bonded kernel. - */ -void NbnxnDispatchPruneKernel(PairlistSet *pairlistSet, - Nbnxm::KernelType kernelType, - const nbnxn_atomdata_t *nbat, - const rvec *shift_vec); - /*! \libinternal * \brief Top-level non-bonded data structure for the Verlet-type cut-off scheme. */ struct nonbonded_verlet_t { public: - class PairlistSets - { - public: - PairlistSets(const NbnxnListParameters &listParams, - bool haveMultipleDomains, - int minimumIlistCountForGpuBalancing); - - //! Construct the pairlist set for the given locality - void construct(Nbnxm::InteractionLocality iLocality, - PairSearch *pairSearch, - nbnxn_atomdata_t *nbat, - const t_blocka *excl, - Nbnxm::KernelType kernelbType, - int64_t step, - t_nrnb *nrnb); - - //! Dispatches the dynamic pruning kernel for the given locality - void dispatchPruneKernel(Nbnxm::InteractionLocality iLocality, - const nbnxn_atomdata_t *nbat, - const rvec *shift_vec, - Nbnxm::KernelType kernelbType); - - //! Returns the pair list parameters - const NbnxnListParameters ¶ms() const - { - return params_; - } - - //! Returns the number of steps performed with the current pair list - int numStepsWithPairlist(int64_t step) const - { - return step - outerListCreationStep_; - } - - //! Returns whether step is a dynamic list pruning step, for CPU lists - bool isDynamicPruningStepCpu(int64_t step) const - { - return (params_.useDynamicPruning && - numStepsWithPairlist(step) % params_.nstlistPrune == 0); - } - - //! Returns whether step is a dynamic list pruning step, for GPU lists - bool isDynamicPruningStepGpu(int64_t step) const - { - const int age = numStepsWithPairlist(step); - - return (params_.useDynamicPruning && - age > 0 && - age < params_.lifetime && - (params_.haveMultipleDomains || age % 2 == 0)); - } - - //! Changes the pair-list outer and inner radius - void changeRadii(real rlistOuter, - real rlistInner) - { - params_.rlistOuter = rlistOuter; - params_.rlistInner = rlistInner; - } - - //! Returns the pair-list set for the given locality - const PairlistSet &pairlistSet(Nbnxm::InteractionLocality iLocality) const - { - if (iLocality == Nbnxm::InteractionLocality::Local) - { - return *localSet_; - } - else - { - GMX_ASSERT(nonlocalSet_, "Need a non-local set when requesting access"); - return *nonlocalSet_; - } - } - - private: - //! Returns the pair-list set for the given locality - PairlistSet &pairlistSet(Nbnxm::InteractionLocality iLocality) - { - if (iLocality == Nbnxm::InteractionLocality::Local) - { - return *localSet_; - } - else - { - GMX_ASSERT(nonlocalSet_, "Need a non-local set when requesting access"); - return *nonlocalSet_; - } - } - - //! Parameters for the search and list pruning setup - NbnxnListParameters params_; - //! Pair list balancing parameter for use with GPU - int minimumIlistCountForGpuBalancing_; - //! Local pairlist set - std::unique_ptr localSet_; - //! Non-local pairlist set - std::unique_ptr nonlocalSet_; - //! MD step at with the outer lists in pairlistSets_ were created - int64_t outerListCreationStep_; - }; - //! Constructs an object from its components nonbonded_verlet_t(std::unique_ptr pairlistSets, std::unique_ptr pairSearch, @@ -409,19 +252,18 @@ struct nonbonded_verlet_t return *pairlistSets_; } + //! Returns whether step is a dynamic list pruning step, for CPU lists + bool isDynamicPruningStepCpu(int64_t step) const; + + //! Returns whether step is a dynamic list pruning step, for GPU lists + bool isDynamicPruningStepGpu(int64_t step) const; + //! Dispatches the dynamic pruning kernel for the given locality, for CPU lists void dispatchPruneKernelCpu(Nbnxm::InteractionLocality iLocality, const rvec *shift_vec); //! Dispatches the dynamic pruning kernel for GPU lists - void dispatchPruneKernelGpu(int64_t step) - { - const bool stepIsEven = (pairlistSets().numStepsWithPairlist(step) % 2 == 0); - - Nbnxm::gpu_launch_kernel_pruneonly(gpu_nbv, - stepIsEven ? Nbnxm::InteractionLocality::Local : Nbnxm::InteractionLocality::NonLocal, - pairlistSets().params().numRollingPruningParts); - } + void dispatchPruneKernelGpu(int64_t step); //! \brief Executes the non-bonded kernel of the GPU or launches it on the GPU void dispatchNonbondedKernel(Nbnxm::InteractionLocality iLocality, @@ -459,6 +301,17 @@ struct nonbonded_verlet_t void getLocalNumCells(int *numCellsX, int *numCellsY) const; + + //! Returns the outer radius for the pair list + real pairlistInnerRadius() const; + + //! Returns the outer radius for the pair list + real pairlistOuterRadius() const; + + //! Changes the pair-list outer and inner radius + void changePairlistRadii(real rlistOuter, + real rlistInner); + // TODO: Make all data members private public: //! All data related to the pair lists diff --git a/src/gromacs/nbnxm/nbnxm_setup.cpp b/src/gromacs/nbnxm/nbnxm_setup.cpp index d88ca57872..5d6576dcf8 100644 --- a/src/gromacs/nbnxm/nbnxm_setup.cpp +++ b/src/gromacs/nbnxm/nbnxm_setup.cpp @@ -63,11 +63,20 @@ #include "gpu_types.h" #include "grid.h" +#include "pairlistsets.h" #include "pairsearch.h" namespace Nbnxm { +/*! \brief Resources that can be used to execute non-bonded kernels on */ +enum class NonbondedResource : int +{ + Cpu, + Gpu, + EmulateGpu +}; + /*! \brief Returns whether CPU SIMD support exists for the given inputrec * * If the return value is FALSE and fplog/cr != NULL, prints a fallback @@ -293,10 +302,10 @@ pick_nbnxn_kernel(const gmx::MDLogger &mdlog, } // namespace Nbnxm -nonbonded_verlet_t::PairlistSets::PairlistSets(const NbnxnListParameters &listParams, - const bool haveMultipleDomains, - const int minimumIlistCountForGpuBalancing) : - params_(listParams), +PairlistSets::PairlistSets(const PairlistParams &pairlistParams, + const bool haveMultipleDomains, + const int minimumIlistCountForGpuBalancing) : + params_(pairlistParams), minimumIlistCountForGpuBalancing_(minimumIlistCountForGpuBalancing) { localSet_ = std::make_unique(Nbnxm::InteractionLocality::Local, @@ -383,13 +392,13 @@ init_nb_verlet(const gmx::MDLogger &mdlog, const bool haveMultipleDomains = (DOMAINDECOMP(cr) && cr->dd->nnodes > 1); - NbnxnListParameters listParams(kernelSetup.kernelType, - bFEP_NonBonded, - ir->rlist, - havePPDomainDecomposition(cr)); + PairlistParams pairlistParams(kernelSetup.kernelType, + bFEP_NonBonded, + ir->rlist, + havePPDomainDecomposition(cr)); setupDynamicPairlistPruning(mdlog, ir, mtop, box, fr->ic, - &listParams); + &pairlistParams); int enbnxninitcombrule; if (fr->ic->vdwtype == evdwCUT && @@ -446,7 +455,7 @@ init_nb_verlet(const gmx::MDLogger &mdlog, * both local and non-local NB calculation on GPU */ gpu_nbv = gpu_init(deviceInfo, fr->ic, - &listParams, + pairlistParams, nbat.get(), cr->nodeid, haveMultipleDomains); @@ -455,15 +464,15 @@ init_nb_verlet(const gmx::MDLogger &mdlog, } auto pairlistSets = - std::make_unique(listParams, - haveMultipleDomains, - minimumIlistCountForGpuBalancing); + std::make_unique(pairlistParams, + haveMultipleDomains, + minimumIlistCountForGpuBalancing); auto pairSearch = std::make_unique(ir->ePBC, DOMAINDECOMP(cr) ? &cr->dd->nc : nullptr, DOMAINDECOMP(cr) ? domdec_zones(cr->dd) : nullptr, - listParams.pairlistType, + pairlistParams.pairlistType, bFEP_NonBonded, gmx_omp_nthreads_get(emntPairsearch)); diff --git a/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp b/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp index f669d63a93..81cb7aac56 100644 --- a/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp +++ b/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp @@ -67,6 +67,7 @@ #include "gromacs/nbnxm/gpu_jit_support.h" #include "gromacs/nbnxm/nbnxm.h" #include "gromacs/nbnxm/nbnxm_gpu.h" +#include "gromacs/nbnxm/pairlistsets.h" #include "gromacs/pbcutil/ishift.h" #include "gromacs/timing/gpu_timing.h" #include "gromacs/utility/cstringutil.h" @@ -202,7 +203,7 @@ static void init_atomdata_first(cl_atomdata_t *ad, int ntypes, gmx_device_runtim */ static void set_cutoff_parameters(cl_nbparam_t *nbp, const interaction_const_t *ic, - const NbnxnListParameters *listParams) + const PairlistParams &listParams) { nbp->ewald_beta = ic->ewaldcoeff_q; nbp->sh_ewald = ic->sh_ewald; @@ -211,9 +212,9 @@ static void set_cutoff_parameters(cl_nbparam_t *nbp, nbp->c_rf = ic->c_rf; nbp->rvdw_sq = ic->rvdw * ic->rvdw; nbp->rcoulomb_sq = ic->rcoulomb * ic->rcoulomb; - nbp->rlistOuter_sq = listParams->rlistOuter * listParams->rlistOuter; - nbp->rlistInner_sq = listParams->rlistInner * listParams->rlistInner; - nbp->useDynamicPruning = listParams->useDynamicPruning; + nbp->rlistOuter_sq = listParams.rlistOuter * listParams.rlistOuter; + nbp->rlistInner_sq = listParams.rlistInner * listParams.rlistInner; + nbp->useDynamicPruning = listParams.useDynamicPruning; nbp->sh_lj_ewald = ic->sh_lj_ewald; nbp->ewaldcoeff_lj = ic->ewaldcoeff_lj; @@ -306,7 +307,7 @@ map_interaction_types_to_gpu_kernel_flavors(const interaction_const_t *ic, */ static void init_nbparam(cl_nbparam_t *nbp, const interaction_const_t *ic, - const NbnxnListParameters *listParams, + const PairlistParams &listParams, const nbnxn_atomdata_t::Params &nbatParams, const gmx_device_runtime_data_t *runData) { @@ -416,8 +417,7 @@ static void init_nbparam(cl_nbparam_t *nbp, //! This function is documented in the header file void gpu_pme_loadbal_update_param(const nonbonded_verlet_t *nbv, - const interaction_const_t *ic, - const NbnxnListParameters *listParams) + const interaction_const_t *ic) { if (!nbv || !nbv->useGpu()) { @@ -426,7 +426,7 @@ void gpu_pme_loadbal_update_param(const nonbonded_verlet_t *nbv, gmx_nbnxn_ocl_t *nb = nbv->gpu_nbv; cl_nbparam_t *nbp = nb->nbparam; - set_cutoff_parameters(nbp, ic, listParams); + set_cutoff_parameters(nbp, ic, nbv->pairlistSets().params()); nbp->eeltype = gpu_pick_ewald_kernel_type(ic->rcoulomb != ic->rvdw); @@ -625,7 +625,7 @@ static void nbnxn_gpu_init_kernels(gmx_nbnxn_ocl_t *nb) */ static void nbnxn_ocl_init_const(gmx_nbnxn_ocl_t *nb, const interaction_const_t *ic, - const NbnxnListParameters *listParams, + const PairlistParams &listParams, const nbnxn_atomdata_t::Params &nbatParams) { init_atomdata_first(nb->atdat, nbatParams.numTypes, nb->dev_rundata); @@ -637,7 +637,7 @@ static void nbnxn_ocl_init_const(gmx_nbnxn_ocl_t *nb, gmx_nbnxn_ocl_t * gpu_init(const gmx_device_info_t *deviceInfo, const interaction_const_t *ic, - const NbnxnListParameters *listParams, + const PairlistParams &listParams, const nbnxn_atomdata_t *nbat, const int rank, const gmx_bool bLocalAndNonlocal) diff --git a/src/gromacs/nbnxm/pairlist.cpp b/src/gromacs/nbnxm/pairlist.cpp index e1e165839c..aba3775eb9 100644 --- a/src/gromacs/nbnxm/pairlist.cpp +++ b/src/gromacs/nbnxm/pairlist.cpp @@ -71,6 +71,7 @@ #include "gromacs/utility/smalloc.h" #include "gridset.h" +#include "pairlistsets.h" #include "pairlistwork.h" #include "pairsearch.h" @@ -683,9 +684,9 @@ NbnxnPairlistGpu::NbnxnPairlistGpu(gmx::PinningPolicy pinningPolicy) : // TODO: Move to pairlistset.cpp PairlistSet::PairlistSet(const Nbnxm::InteractionLocality locality, - const NbnxnListParameters &listParams) : + const PairlistParams &pairlistParams) : locality_(locality), - params_(listParams) + params_(pairlistParams) { isCpuType_ = (params_.pairlistType == PairlistType::Simple4x2 || @@ -4244,13 +4245,13 @@ PairlistSet::constructPairlists(PairSearch *pairSearch, } void -nonbonded_verlet_t::PairlistSets::construct(const InteractionLocality iLocality, - PairSearch *pairSearch, - nbnxn_atomdata_t *nbat, - const t_blocka *excl, - const Nbnxm::KernelType kernelType, - const int64_t step, - t_nrnb *nrnb) +PairlistSets::construct(const InteractionLocality iLocality, + PairSearch *pairSearch, + nbnxn_atomdata_t *nbat, + const t_blocka *excl, + const Nbnxm::KernelType kernelType, + const int64_t step, + t_nrnb *nrnb) { pairlistSet(iLocality).constructPairlists(pairSearch, nbat, excl, kernelType, minimumIlistCountForGpuBalancing_, nrnb); diff --git a/src/gromacs/nbnxm/pairlist.h b/src/gromacs/nbnxm/pairlist.h index 60e71bcf48..20ef2a4bbc 100644 --- a/src/gromacs/nbnxm/pairlist.h +++ b/src/gromacs/nbnxm/pairlist.h @@ -54,10 +54,10 @@ #include "locality.h" -struct NbnxnListParameters; struct NbnxnPairlistCpuWork; struct NbnxnPairlistGpuWork; struct nbnxn_atomdata_t; +struct PairlistParams; class PairSearch; struct t_blocka; struct t_nrnb; @@ -298,7 +298,7 @@ class PairlistSet public: //! Constructor: initializes the pairlist set as empty PairlistSet(Nbnxm::InteractionLocality locality, - const NbnxnListParameters &listParams); + const PairlistParams &listParams); ~PairlistSet(); @@ -356,7 +356,7 @@ class PairlistSet //! List of pairlists in GPU layout std::vector gpuLists_; //! Pairlist parameters describing setup and ranges - const NbnxnListParameters ¶ms_; + const PairlistParams ¶ms_; //! Tells whether multiple lists get merged into one (the first) after creation bool combineLists_; //! Tells whether the lists is of CPU type, otherwise GPU type diff --git a/src/gromacs/nbnxm/pairlist_tuning.cpp b/src/gromacs/nbnxm/pairlist_tuning.cpp index 0aa8048e83..aa1c76cbec 100644 --- a/src/gromacs/nbnxm/pairlist_tuning.cpp +++ b/src/gromacs/nbnxm/pairlist_tuning.cpp @@ -60,7 +60,6 @@ #include "gromacs/mdtypes/inputrec.h" #include "gromacs/mdtypes/interaction_const.h" #include "gromacs/mdtypes/state.h" -#include "gromacs/nbnxm/nbnxm.h" #include "gromacs/nbnxm/nbnxm_geometry.h" #include "gromacs/pbcutil/pbc.h" #include "gromacs/topology/topology.h" @@ -71,6 +70,8 @@ #include "gromacs/utility/strconvert.h" #include "gromacs/utility/stringutil.h" +#include "pairlistsets.h" + /*! \brief Returns if we can (heuristically) change nstlist and rlist * * \param [in] ir The input parameter record @@ -387,7 +388,7 @@ setDynamicPairlistPruningParameters(const t_inputrec *ir, const VerletbufListSetup &listSetup, const bool userSetNstlistPrune, const interaction_const_t *ic, - NbnxnListParameters *listParams) + PairlistParams *listParams) { listParams->lifetime = ir->nstlist - 1; @@ -487,7 +488,7 @@ void setupDynamicPairlistPruning(const gmx::MDLogger &mdlog, const gmx_mtop_t *mtop, matrix box, const interaction_const_t *ic, - NbnxnListParameters *listParams) + PairlistParams *listParams) { GMX_RELEASE_ASSERT(listParams->rlistOuter > 0, "With the nbnxn setup rlist should be > 0"); diff --git a/src/gromacs/nbnxm/pairlist_tuning.h b/src/gromacs/nbnxm/pairlist_tuning.h index 3c2227dea9..e3af9a42fb 100644 --- a/src/gromacs/nbnxm/pairlist_tuning.h +++ b/src/gromacs/nbnxm/pairlist_tuning.h @@ -58,7 +58,7 @@ class MDLogger; struct gmx_mtop_t; struct interaction_const_t; -struct NbnxnListParameters; +struct PairlistParams; struct t_commrec; struct t_inputrec; @@ -94,6 +94,6 @@ void setupDynamicPairlistPruning(const gmx::MDLogger &mdlog, const gmx_mtop_t *mtop, matrix box, const interaction_const_t *ic, - NbnxnListParameters *listParams); + PairlistParams *listParams); #endif /* NBNXM_PAIRLIST_TUNING_H */ diff --git a/src/gromacs/nbnxm/pairlistparams.cpp b/src/gromacs/nbnxm/pairlistparams.cpp new file mode 100644 index 0000000000..ca27ef5246 --- /dev/null +++ b/src/gromacs/nbnxm/pairlistparams.cpp @@ -0,0 +1,87 @@ +/* + * This file is part of the GROMACS molecular simulation package. + * + * Copyright (c) 2019, by the GROMACS development team, led by + * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, + * and including many others, as listed in the AUTHORS file in the + * top-level source directory and at http://www.gromacs.org. + * + * GROMACS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * GROMACS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GROMACS; if not, see + * http://www.gnu.org/licenses, or write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * If you want to redistribute modifications to GROMACS, please + * consider that scientific software is very special. Version + * control is crucial - bugs must be traceable. We will be happy to + * consider code for inclusion in the official distribution, but + * derived work must not be called official GROMACS. Details are found + * in the README & COPYING files - if they are missing, get the + * official version at http://www.gromacs.org. + * + * To help us fund GROMACS development, we humbly ask that you cite + * the research papers on the package. Check out http://www.gromacs.org. + */ + +/*! \internal \file + * \brief + * Implements the PairlistParams constructor + * + * \author Berk Hess + * \ingroup module_nbnxm + */ + +#include "gmxpre.h" + +#include "pairlistparams.h" + +#include "gromacs/nbnxm/nbnxm.h" +#include "gromacs/nbnxm/nbnxm_geometry.h" +#include "gromacs/utility/gmxassert.h" + + +PairlistParams::PairlistParams(const Nbnxm::KernelType kernelType, + const bool haveFep, + const real rlist, + const bool haveMultipleDomains) : + haveFep(haveFep), + rlistOuter(rlist), + rlistInner(rlist), + haveMultipleDomains(haveMultipleDomains), + useDynamicPruning(false), + nstlistPrune(-1), + numRollingPruningParts(1), + lifetime(-1) +{ + if (!Nbnxm::kernelTypeUsesSimplePairlist(kernelType)) + { + pairlistType = PairlistType::HierarchicalNxN; + } + else + { + switch (Nbnxm::JClusterSizePerKernelType[kernelType]) + { + case 2: + pairlistType = PairlistType::Simple4x2; + break; + case 4: + pairlistType = PairlistType::Simple4x4; + break; + case 8: + pairlistType = PairlistType::Simple4x8; + break; + default: + GMX_RELEASE_ASSERT(false, "Kernel type does not have a pairlist type"); + } + } +} diff --git a/src/gromacs/nbnxm/pairlistparams.h b/src/gromacs/nbnxm/pairlistparams.h new file mode 100644 index 0000000000..b897b6551e --- /dev/null +++ b/src/gromacs/nbnxm/pairlistparams.h @@ -0,0 +1,87 @@ +/* + * This file is part of the GROMACS molecular simulation package. + * + * Copyright (c) 2019, by the GROMACS development team, led by + * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, + * and including many others, as listed in the AUTHORS file in the + * top-level source directory and at http://www.gromacs.org. + * + * GROMACS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * GROMACS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GROMACS; if not, see + * http://www.gnu.org/licenses, or write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * If you want to redistribute modifications to GROMACS, please + * consider that scientific software is very special. Version + * control is crucial - bugs must be traceable. We will be happy to + * consider code for inclusion in the official distribution, but + * derived work must not be called official GROMACS. Details are found + * in the README & COPYING files - if they are missing, get the + * official version at http://www.gromacs.org. + * + * To help us fund GROMACS development, we humbly ask that you cite + * the research papers on the package. Check out http://www.gromacs.org. + */ + +/*! \internal \file + * + * \brief + * Declares the PairlistParams class + * + * This class holds the Nbnxm pairlist parameters. + * + * \author Berk Hess + * \ingroup module_nbnxm + */ + +#ifndef GMX_NBNXM_PAIRLISTPARAMS_H +#define GMX_NBNXM_PAIRLISTPARAMS_H + +#include "gromacs/utility/real.h" + +#include "locality.h" + +enum class PairlistType; + +namespace Nbnxm +{ +enum class KernelType; +} + + +/*! \internal + * \brief The setup for generating and pruning the nbnxn pair list. + * + * Without dynamic pruning rlistOuter=rlistInner. + */ +struct PairlistParams +{ + /*! \brief Constructor producing a struct with dynamic pruning disabled + */ + PairlistParams(Nbnxm::KernelType kernelType, + bool haveFep, + real rlist, + bool haveMultipleDomains); + + PairlistType pairlistType; //!< The type of cluster-pair list + bool haveFep; //!< Tells whether we have perturbed interactions + real rlistOuter; //!< Cut-off of the larger, outer pair-list + real rlistInner; //!< Cut-off of the smaller, inner pair-list + bool haveMultipleDomains; //!< True when using DD with multiple domains + bool useDynamicPruning; //!< Are we using dynamic pair-list pruning + int nstlistPrune; //!< Pair-list dynamic pruning interval + int numRollingPruningParts; //!< The number parts to divide the pair-list into for rolling pruning, a value of 1 gives no rolling pruning + int lifetime; //!< Lifetime in steps of the pair-list +}; + +#endif diff --git a/src/gromacs/nbnxm/pairlistset.cpp b/src/gromacs/nbnxm/pairlistset.cpp index 5607a88f07..65216be66a 100644 --- a/src/gromacs/nbnxm/pairlistset.cpp +++ b/src/gromacs/nbnxm/pairlistset.cpp @@ -35,7 +35,7 @@ /*! \internal \file * \brief - * Implements functionality for nbnxn_pairlist_set_t. + * Implements functionality for PairlistSet. * * \author Berk Hess * \ingroup module_nbnxm @@ -45,51 +45,6 @@ #include "pairlistset.h" -#include "gromacs/nbnxm/nbnxm.h" -#include "gromacs/nbnxm/nbnxm_geometry.h" -#include "gromacs/nbnxm/pairlist.h" -#include "gromacs/utility/gmxassert.h" - #include "pairlistwork.h" -/*! \cond INTERNAL */ - -NbnxnListParameters::NbnxnListParameters(const Nbnxm::KernelType kernelType, - const bool haveFep, - const real rlist, - const bool haveMultipleDomains) : - haveFep(haveFep), - rlistOuter(rlist), - rlistInner(rlist), - haveMultipleDomains(haveMultipleDomains), - useDynamicPruning(false), - nstlistPrune(-1), - numRollingPruningParts(1), - lifetime(-1) -{ - if (!Nbnxm::kernelTypeUsesSimplePairlist(kernelType)) - { - pairlistType = PairlistType::HierarchicalNxN; - } - else - { - switch (Nbnxm::JClusterSizePerKernelType[kernelType]) - { - case 2: - pairlistType = PairlistType::Simple4x2; - break; - case 4: - pairlistType = PairlistType::Simple4x4; - break; - case 8: - pairlistType = PairlistType::Simple4x8; - break; - default: - GMX_RELEASE_ASSERT(false, "Kernel type does not have a pairlist type"); - } - } -} - PairlistSet::~PairlistSet() = default; - -/*! \endcond */ diff --git a/src/gromacs/nbnxm/pairlistsets.h b/src/gromacs/nbnxm/pairlistsets.h new file mode 100644 index 0000000000..ccfc0992d5 --- /dev/null +++ b/src/gromacs/nbnxm/pairlistsets.h @@ -0,0 +1,169 @@ +/* + * This file is part of the GROMACS molecular simulation package. + * + * Copyright (c) 2012,2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by + * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, + * and including many others, as listed in the AUTHORS file in the + * top-level source directory and at http://www.gromacs.org. + * + * GROMACS is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * GROMACS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GROMACS; if not, see + * http://www.gnu.org/licenses, or write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * If you want to redistribute modifications to GROMACS, please + * consider that scientific software is very special. Version + * control is crucial - bugs must be traceable. We will be happy to + * consider code for inclusion in the official distribution, but + * derived work must not be called official GROMACS. Details are found + * in the README & COPYING files - if they are missing, get the + * official version at http://www.gromacs.org. + * + * To help us fund GROMACS development, we humbly ask that you cite + * the research papers on the package. Check out http://www.gromacs.org. + */ + +/*! \internal \file + * + * \brief + * Declares the PairlistSets class + * + * This class holds the local and non-local pairlist sets. + * + * \author Berk Hess + * \ingroup module_nbnxm + */ + +#ifndef GMX_NBNXM_PAIRLISTSETS_H +#define GMX_NBNXM_PAIRLISTSETS_H + +#include + +#include "locality.h" +#include "pairlistparams.h" + +struct nbnxn_atomdata_t; +class PairlistSet; +enum class PairlistType; +class PairSearch; +struct t_blocka; +struct t_nrnb; + +namespace Nbnxm +{ +enum class KernelType; +} + + +class PairlistSets +{ + public: + PairlistSets(const PairlistParams &pairlistParams, + bool haveMultipleDomains, + int minimumIlistCountForGpuBalancing); + + //! Construct the pairlist set for the given locality + void construct(Nbnxm::InteractionLocality iLocality, + PairSearch *pairSearch, + nbnxn_atomdata_t *nbat, + const t_blocka *excl, + Nbnxm::KernelType kernelbType, + int64_t step, + t_nrnb *nrnb); + + //! Dispatches the dynamic pruning kernel for the given locality + void dispatchPruneKernel(Nbnxm::InteractionLocality iLocality, + const nbnxn_atomdata_t *nbat, + const rvec *shift_vec, + Nbnxm::KernelType kernelType); + + //! Returns the pair list parameters + const PairlistParams ¶ms() const + { + return params_; + } + + //! Returns the number of steps performed with the current pair list + int numStepsWithPairlist(int64_t step) const + { + return step - outerListCreationStep_; + } + + //! Returns whether step is a dynamic list pruning step, for CPU lists + bool isDynamicPruningStepCpu(int64_t step) const + { + return (params_.useDynamicPruning && + numStepsWithPairlist(step) % params_.nstlistPrune == 0); + } + + //! Returns whether step is a dynamic list pruning step, for GPU lists + bool isDynamicPruningStepGpu(int64_t step) const + { + const int age = numStepsWithPairlist(step); + + return (params_.useDynamicPruning && + age > 0 && + age < params_.lifetime && + (params_.haveMultipleDomains || age % 2 == 0)); + } + + //! Changes the pair-list outer and inner radius + void changePairlistRadii(real rlistOuter, + real rlistInner) + { + params_.rlistOuter = rlistOuter; + params_.rlistInner = rlistInner; + } + + //! Returns the pair-list set for the given locality + const PairlistSet &pairlistSet(Nbnxm::InteractionLocality iLocality) const + { + if (iLocality == Nbnxm::InteractionLocality::Local) + { + return *localSet_; + } + else + { + GMX_ASSERT(nonlocalSet_, "Need a non-local set when requesting access"); + return *nonlocalSet_; + } + } + + private: + //! Returns the pair-list set for the given locality + PairlistSet &pairlistSet(Nbnxm::InteractionLocality iLocality) + { + if (iLocality == Nbnxm::InteractionLocality::Local) + { + return *localSet_; + } + else + { + GMX_ASSERT(nonlocalSet_, "Need a non-local set when requesting access"); + return *nonlocalSet_; + } + } + + //! Parameters for the search and list pruning setup + PairlistParams params_; + //! Pair list balancing parameter for use with GPU + int minimumIlistCountForGpuBalancing_; + //! Local pairlist set + std::unique_ptr localSet_; + //! Non-local pairlist set + std::unique_ptr nonlocalSet_; + //! MD step at with the outer lists in pairlistSets_ were created + int64_t outerListCreationStep_; +}; + +#endif diff --git a/src/gromacs/nbnxm/prunekerneldispatch.cpp b/src/gromacs/nbnxm/prunekerneldispatch.cpp index a1beaf2ac9..76482e1647 100644 --- a/src/gromacs/nbnxm/prunekerneldispatch.cpp +++ b/src/gromacs/nbnxm/prunekerneldispatch.cpp @@ -40,15 +40,16 @@ #include "gromacs/nbnxm/pairlist.h" #include "gromacs/utility/gmxassert.h" +#include "pairlistsets.h" #include "kernels_reference/kernel_ref_prune.h" #include "kernels_simd_2xmm/kernel_prune.h" #include "kernels_simd_4xm/kernel_prune.h" void -nonbonded_verlet_t::PairlistSets::dispatchPruneKernel(const Nbnxm::InteractionLocality iLocality, - const nbnxn_atomdata_t *nbat, - const rvec *shift_vec, - const Nbnxm::KernelType kernelType) +PairlistSets::dispatchPruneKernel(const Nbnxm::InteractionLocality iLocality, + const nbnxn_atomdata_t *nbat, + const rvec *shift_vec, + const Nbnxm::KernelType kernelType) { pairlistSet(iLocality).dispatchPruneKernel(nbat, shift_vec, kernelType); } @@ -94,3 +95,12 @@ nonbonded_verlet_t::dispatchPruneKernelCpu(const Nbnxm::InteractionLocality iLo { pairlistSets_->dispatchPruneKernel(iLocality, nbat.get(), shift_vec, kernelSetup_.kernelType); } + +void nonbonded_verlet_t::dispatchPruneKernelGpu(int64_t step) +{ + const bool stepIsEven = (pairlistSets().numStepsWithPairlist(step) % 2 == 0); + + Nbnxm::gpu_launch_kernel_pruneonly(gpu_nbv, + stepIsEven ? Nbnxm::InteractionLocality::Local : Nbnxm::InteractionLocality::NonLocal, + pairlistSets().params().numRollingPruningParts); +} -- 2.22.0