enable GPU emulation without GPU support
authorSzilard Pall <pszilard@cbr.su.se>
Fri, 16 Nov 2012 04:26:13 +0000 (05:26 +0100)
committerBerk Hess <hess@kth.se>
Wed, 28 Nov 2012 09:54:39 +0000 (10:54 +0100)
GPU emulation can be useful to estimate the performance one could get
by adding GPU(s) to the machine by running with GMX_EMULATE_GPU and
GMX_NO_NONBONDED environment variables set. As this feature is useful
even with mdrun compiled without GPU support, this commit makes GPU
emulation mode always available.

Change-Id: I0b90b8ec1c6e3116f28f66aac4f3c8ae0831239d

src/mdlib/forcerec.c

index c092463a5fab4529aabceb4ec2941ba3a63d71f6..61e008ff65dfd8e195860c3f830500d0d04c119f 100644 (file)
@@ -1467,23 +1467,33 @@ static void pick_nbnxn_kernel(FILE *fp,
                               int *kernel_type,
                               int *ewald_excl)
 {
-    gmx_bool bEmulateGPU, bGPU;
+    gmx_bool bEmulateGPU, bGPU, bEmulateGPUEnvVarSet;
     char gpu_err_str[STRLEN];
 
     assert(kernel_type);
 
     *kernel_type = nbkNotSet;
     *ewald_excl  = ewaldexclTable;
-    /* if bUseGPU == NULL we don't want a GPU (e.g. hybrid mode kernel selection) */
-    bGPU = (bUseGPU != NULL) && hwinfo->bCanUseGPU;
 
-    /* Run GPU emulation mode if GMX_EMULATE_GPU is defined or in case if nobonded
-       calculations are turned off via GMX_NO_NONBONDED -- this is the simple way
-       to turn off GPU/CUDA initializations as well.. */
-    bEmulateGPU = ((getenv("GMX_EMULATE_GPU") != NULL) ||
-                   (getenv("GMX_NO_NONBONDED") != NULL));
+    bEmulateGPUEnvVarSet = (getenv("GMX_EMULATE_GPU") != NULL);
 
-    if (bGPU)
+    /* if bUseGPU == NULL we don't want a GPU (e.g. hybrid mode kernel selection) */
+    bGPU = ((bUseGPU != NULL) && hwinfo->bCanUseGPU);
+
+    /* Run GPU emulation mode if GMX_EMULATE_GPU is defined. 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. */
+    bEmulateGPU = (bEmulateGPUEnvVarSet || (getenv("GMX_NO_NONBONDED") != NULL && bGPU));
+
+    /* Enable GPU mode when GPUs are available or GPU emulation is requested.
+     * The latter is 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 such a GPU acceleration performance assessment should be
+     * carried out by setting the GMX_EMULATE_GPU and GMX_NO_NONBONDED env. vars
+     * (and freezing the system as otherwise it would explode). */
+    if (bGPU || bEmulateGPUEnvVarSet)
     {
         if (bEmulateGPU)
         {
@@ -1492,10 +1502,10 @@ static void pick_nbnxn_kernel(FILE *fp,
         else
         {
             /* Each PP node will use the intra-node id-th device from the
-             * list of detected/selected GPUs. */ 
+             * list of detected/selected GPUs. */
             if (!init_gpu(cr->nodeid_group_intra, gpu_err_str, &hwinfo->gpu_info))
             {
-                /* At this point the init should never fail as we made sure that 
+                /* At this point the init should never fail as we made sure that
                  * we have all the GPUs we need. If it still does, we'll bail. */
                 gmx_fatal(FARGS, "On node %d failed to initialize GPU #%d: %s",
                           cr->nodeid,