Clean up pick_nbnxn_resources
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 30 Jun 2017 21:16:22 +0000 (23:16 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 4 Jul 2017 13:36:15 +0000 (15:36 +0200)
GMX_NO_NONBONDED should not trigger GPU emulation, it should disable
nonbonded calculations. Removed that logic, and amended the
documentation.

Made emulateGpu a field of nonbonded_verlet_t, set by the environment
variable, and used it to trigger the subsequent paths.

This simplifies pick_nbnxn_resources.

Change-Id: I5ce4f69e470fe7e24bb554556211697d25f11b0f

docs/user-guide/environment-variables.rst
src/gromacs/mdlib/forcerec.cpp
src/gromacs/mdlib/nb_verlet.h
src/gromacs/mdlib/sim_util.cpp

index 86ce9dd2658f6aa9a5b72fb63e5ad3ca3626d990..43016daf1a941d9a2d70dc4d77ea5ba0b4fe7e99 100644 (file)
@@ -195,8 +195,6 @@ Performance and Run Control
 ``GMX_EMULATE_GPU``
         emulate GPU runs by using algorithmically equivalent CPU reference code instead of
         GPU-accelerated functions. As the CPU code is slow, it is intended to be used only for debugging purposes.
-        The behavior is automatically triggered if non-bonded calculations are turned off using ``GMX_NO_NONBONDED``
-        case in which the non-bonded calculations will not be called, but the CPU-GPU transfer will also be skipped.
 
 ``GMX_ENX_NO_FATAL``
         disable exiting upon encountering a corrupted frame in an :ref:`edr`
@@ -284,6 +282,7 @@ Performance and Run Control
         skip non-bonded calculations; can be used to estimate the possible
         performance gain from adding a GPU accelerator to the current hardware setup -- assuming that this is
         fast enough to complete the non-bonded calculations while the CPU does bonded force and PME computation.
+        Freezing the particles will be required to stop the system blowing up.
 
 ``GMX_NO_PULLVIR``
         when set, do not add virial contribution to COM pull forces.
index f2c3861e5778f6803ee7d34cdbb5f2b56a2be948..77591bda1a1b5fbb2cdff28cac8f975be7743841 100644 (file)
@@ -1705,7 +1705,7 @@ static void pick_nbnxn_kernel(FILE                *fp,
                               const gmx::MDLogger &mdlog,
                               gmx_bool             use_simd_kernels,
                               gmx_bool             bUseGPU,
-                              gmx_bool             bEmulateGPU,
+                              bool                 emulateGpu,
                               const t_inputrec    *ir,
                               int                 *kernel_type,
                               int                 *ewald_excl,
@@ -1716,7 +1716,7 @@ static void pick_nbnxn_kernel(FILE                *fp,
     *kernel_type = nbnxnkNotSet;
     *ewald_excl  = ewaldexclTable;
 
-    if (bEmulateGPU)
+    if (emulateGpu)
     {
         *kernel_type = nbnxnk8x8x8_PlainC;
 
@@ -1764,35 +1764,17 @@ static void pick_nbnxn_kernel(FILE                *fp,
 static void pick_nbnxn_resources(const gmx::MDLogger &mdlog,
                                  const t_commrec     *cr,
                                  const gmx_hw_info_t *hwinfo,
-                                 gmx_bool             bDoNonbonded,
                                  gmx_bool            *bUseGPU,
-                                 gmx_bool            *bEmulateGPU,
+                                 bool                 emulateGpu,
                                  const gmx_gpu_opt_t *gpu_opt)
 {
-    gmx_bool bEmulateGPUEnvVarSet;
     char     gpu_err_str[STRLEN];
 
     *bUseGPU = FALSE;
 
-    bEmulateGPUEnvVarSet = (getenv("GMX_EMULATE_GPU") != nullptr);
-
-    /* Run GPU emulation mode if GMX_EMULATE_GPU is defined. Because
-     * GPUs (currently) only handle non-bonded calculations, we will
-     * automatically switch to emulation if non-bonded calculations are
-     * turned off via GMX_NO_NONBONDED - this is the simple and elegant
-     * way to turn off GPU initialization, data movement, and cleanup.
-     *
-     * GPU emulation can be useful to assess the performance one can expect by
-     * adding GPU(s) to the machine. The conditional below allows this even
-     * if mdrun is compiled without GPU acceleration support.
-     * Note that you should freezing the system as otherwise it will explode.
-     */
-    *bEmulateGPU = (bEmulateGPUEnvVarSet ||
-                    (!bDoNonbonded && gpu_opt->n_dev_use > 0));
-
     /* Enable GPU mode when GPUs are available or no GPU emulation is requested.
      */
-    if (gpu_opt->n_dev_use > 0 && !(*bEmulateGPU))
+    if (gpu_opt->n_dev_use > 0 && !emulateGpu)
     {
         /* Each PP node will use the intra-node id-th device from the
          * list of detected/selected GPUs. */
@@ -2091,17 +2073,17 @@ static void init_nb_verlet(FILE                *fp,
     nonbonded_verlet_t *nbv;
     int                 i;
     char               *env;
-    gmx_bool            bEmulateGPU, bHybridGPURun = FALSE;
+    gmx_bool            bHybridGPURun = FALSE;
 
     nbnxn_alloc_t      *nb_alloc;
     nbnxn_free_t       *nb_free;
 
     snew(nbv, 1);
 
+    nbv->emulateGpu = (getenv("GMX_EMULATE_GPU") != nullptr);
     pick_nbnxn_resources(mdlog, cr, fr->hwinfo,
-                         fr->bNonbonded,
                          &nbv->bUseGPU,
-                         &bEmulateGPU,
+                         nbv->emulateGpu,
                          fr->gpu_opt);
 
     nbv->nbs             = nullptr;
@@ -2117,7 +2099,7 @@ static void init_nb_verlet(FILE                *fp,
         if (i == 0) /* local */
         {
             pick_nbnxn_kernel(fp, mdlog, fr->use_simd_kernels,
-                              nbv->bUseGPU, bEmulateGPU, ir,
+                              nbv->bUseGPU, nbv->emulateGpu, ir,
                               &nbv->grp[i].kernel_type,
                               &nbv->grp[i].ewald_excl,
                               fr->bNonbonded);
@@ -2128,7 +2110,7 @@ static void init_nb_verlet(FILE                *fp,
             {
                 /* Use GPU for local, select a CPU kernel for non-local */
                 pick_nbnxn_kernel(fp, mdlog, fr->use_simd_kernels,
-                                  FALSE, FALSE, ir,
+                                  FALSE, false, ir,
                                   &nbv->grp[i].kernel_type,
                                   &nbv->grp[i].ewald_excl,
                                   fr->bNonbonded);
index b0b69f055a5e8da3745f5fc4472299e4771bec6e..886fbd4d4ef5606e904cf393cd0182dc74f6ec00 100644 (file)
@@ -170,7 +170,8 @@ typedef struct nonbonded_verlet_t {
     int                      ngrp;            /**< number of interaction groups          */
     nonbonded_verlet_group_t grp[2];          /**< local and non-local interaction group */
 
-    gmx_bool                 bUseGPU;         /**< TRUE when GPU acceleration is used */
+    gmx_bool                 bUseGPU;         /**< TRUE when non-bonded interactions are computed on a physical GPU */
+    bool                     emulateGpu;      /**< true when non-bonded interactions are computed on the CPU using GPU-style pair lists */
     gmx_nbnxn_gpu_t         *gpu_nbv;         /**< pointer to GPU nb verlet data     */
     int                      min_ci_balanced; /**< pair list balancing parameter
                                                    used for the 8x8x8 GPU kernels    */
index 07c38d82857f8d91be6c674fc0a3216d8a7c2f91..1d9dba9c590f5e58f0dc6c130362bc5ccffea3b2 100644 (file)
@@ -776,7 +776,7 @@ void do_force_cutsVERLET(FILE *fplog, t_commrec *cr,
     bCalcCGCM     = (bFillGrid && !DOMAINDECOMP(cr));
     bDoForces     = (flags & GMX_FORCE_FORCES);
     bUseGPU       = fr->nbv->bUseGPU;
-    bUseOrEmulGPU = bUseGPU || (nbv->grp[0].kernel_type == nbnxnk8x8x8_PlainC);
+    bUseOrEmulGPU = bUseGPU || fr->nbv->emulateGpu;
 
     if (bStateChanged)
     {