Extract nbnxm PairlistSets
authorBerk Hess <hess@kth.se>
Mon, 18 Mar 2019 12:30:47 +0000 (13:30 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 28 Mar 2019 09:02:10 +0000 (10:02 +0100)
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

20 files changed:
src/gromacs/ewald/pme_load_balancing.cpp
src/gromacs/ewald/pme_load_balancing.h
src/gromacs/mdlib/sim_util.cpp
src/gromacs/mdrun/md.cpp
src/gromacs/nbnxm/cuda/nbnxm_cuda_data_mgmt.cu
src/gromacs/nbnxm/gpu_data_mgmt.h
src/gromacs/nbnxm/kerneldispatch.cpp
src/gromacs/nbnxm/nbnxm.cpp
src/gromacs/nbnxm/nbnxm.h
src/gromacs/nbnxm/nbnxm_setup.cpp
src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp
src/gromacs/nbnxm/pairlist.cpp
src/gromacs/nbnxm/pairlist.h
src/gromacs/nbnxm/pairlist_tuning.cpp
src/gromacs/nbnxm/pairlist_tuning.h
src/gromacs/nbnxm/pairlistparams.cpp [new file with mode: 0644]
src/gromacs/nbnxm/pairlistparams.h [new file with mode: 0644]
src/gromacs/nbnxm/pairlistset.cpp
src/gromacs/nbnxm/pairlistsets.h [new file with mode: 0644]
src/gromacs/nbnxm/prunekerneldispatch.cpp

index ba3c90c12ef064dfb4398b8723abd27e3a6578dd..8e49c6330d5a0f2162431214b2ca5d4512828218 100644 (file)
@@ -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)
         {
index 11ea28cb869f3dc781e2af49dfbb4d16f497e41e..1d48b7cfb5f249476836bf807e4222b1d2a6345c 100644 (file)
@@ -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);
index 843b1db72d068f9bdbafda7aacd43f200aa98b92..596fc8fa756502609fb1517ab61ffb4f98515fe0 100644 (file)
@@ -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);
         }
index 5e1db3704fc98b51ea4a078ee82540d02a62d1ef..fc45d55448dd2d82608d42735db854e4ad02954c 100644 (file)
@@ -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);
     }
 
index b19b7f6c4c7691eb51511d2765ce6c31284361b5..46e8c771e3d19d44a1a1b32506d0628ce1ffb967 100644 (file)
@@ -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)
index c1a19b7f635d554a9a67d65ade04fd560e94ea2f..407521c69d85560abc616c4cafabbd06f5439565 100644 (file)
@@ -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
index b676f0c0775154a4397d2a2d63fbb7e602a7a27b..6b40e39048d79f50f61049d46792c298f23e9830 100644 (file)
@@ -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
index 270512b266978c9a54e05bf0b4e23207afd8dc64..1d486c60bc0e7eef92549e2e37575fa80c54bf79 100644 (file)
@@ -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<const int> 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 */
index 4c84070ddedc6d14684bc464137e0bbd8451853c..24752af1131b2d210d1c6717b8431295fe664401 100644 (file)
@@ -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 &params() 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<PairlistSet>          localSet_;
-                //! Non-local pairlist set
-                std::unique_ptr<PairlistSet>          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>      pairlistSets,
                            std::unique_ptr<PairSearch>        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
index d88ca578724b15cc2ee2efa1cd5a05b439024ba6..5d6576dcf83226d0554f781e439ba3c2ef1dfb0d 100644 (file)
 
 #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<PairlistSet>(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<nonbonded_verlet_t::PairlistSets>(listParams,
-                                                           haveMultipleDomains,
-                                                           minimumIlistCountForGpuBalancing);
+        std::make_unique<PairlistSets>(pairlistParams,
+                                       haveMultipleDomains,
+                                       minimumIlistCountForGpuBalancing);
 
     auto pairSearch =
         std::make_unique<PairSearch>(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));
 
index f669d63a9301ff6abcd540a3a5efc2cce20022e6..81cb7aac56a2ab91b525991b99a38e9b34e05b92 100644 (file)
@@ -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)
index e1e165839c01fcf83504cdb9a7c8d7bd0429a29a..aba3775eb93a5a58d2ded242bb06c1416eacfc39 100644 (file)
@@ -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);
 
index 60e71bcf48648f961900c7bd629bd04eac83ee81..20ef2a4bbcdedc0fb4eb10cd8d2a995f5955700e 100644 (file)
 
 #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<NbnxnPairlistGpu>  gpuLists_;
         //! Pairlist parameters describing setup and ranges
-        const NbnxnListParameters     &params_;
+        const PairlistParams          &params_;
         //! 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
index 0aa8048e83ab8f80a06ad508cb297f9c96b84125..aa1c76cbec414dfcb7db79715edb559b9745993e 100644 (file)
@@ -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");
 
index 3c2227dea99e8225ed34691499403793fab5870d..e3af9a42fb2064563d6ba43d3f1e14dabe95a566 100644 (file)
@@ -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 (file)
index 0000000..ca27ef5
--- /dev/null
@@ -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 <hess@kth.se>
+ * \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 (file)
index 0000000..b897b65
--- /dev/null
@@ -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 <hess@kth.se>
+ * \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
index 5607a88f07465b216086c4456d9234e3cbe21435..65216be66abb7721a2a2f0f11e75eb7eed348a69 100644 (file)
@@ -35,7 +35,7 @@
 
 /*! \internal \file
  * \brief
- * Implements functionality for nbnxn_pairlist_set_t.
+ * Implements functionality for PairlistSet.
  *
  * \author Berk Hess <hess@kth.se>
  * \ingroup module_nbnxm
 
 #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 (file)
index 0000000..ccfc099
--- /dev/null
@@ -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 <hess@kth.se>
+ * \ingroup module_nbnxm
+ */
+
+#ifndef GMX_NBNXM_PAIRLISTSETS_H
+#define GMX_NBNXM_PAIRLISTSETS_H
+
+#include <memory>
+
+#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 &params() 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<PairlistSet> localSet_;
+        //! Non-local pairlist set
+        std::unique_ptr<PairlistSet> nonlocalSet_;
+        //! MD step at with the outer lists in pairlistSets_ were created
+        int64_t                      outerListCreationStep_;
+};
+
+#endif
index a1beaf2ac9d177b667c46f041165b6e937b68651..76482e16479a5e241430d8b4e1efa17b0c94fd04 100644 (file)
 #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);
+}