Unify handling of GMX_ENABLE_GPU_TIMING and GMX_DISABLE_GPU_TIMING
[alexxy/gromacs.git] / src / gromacs / gpu_utils / gpu_utils.cpp
index 501d6b625fc8ff9b0aeea6478e64c232e9950a78..2d8846caa334f827ad6c3ed6846b87694a0c4b17 100644 (file)
@@ -59,3 +59,26 @@ const char* enumValueToString(GpuApiCallBehavior enumValue)
     };
     return s_gpuApiCallBehaviorNames[enumValue];
 }
+
+bool decideGpuTimingsUsage()
+{
+    if (GMX_GPU_CUDA || GMX_GPU_SYCL)
+    {
+        /* CUDA: timings are incorrect with multiple streams.
+         * This is the main reason why they are disabled by default.
+         * TODO: Consider turning on by default when we can detect nr of streams.
+         *
+         * SYCL: compilers and runtimes change rapidly, so we disable timings by default
+         * to avoid any possible overhead. */
+        return (getenv("GMX_ENABLE_GPU_TIMING") != nullptr);
+    }
+    else if (GMX_GPU_OPENCL)
+    {
+        return (getenv("GMX_DISABLE_GPU_TIMING") == nullptr);
+    }
+    else
+    {
+        // CPU-only build
+        return false;
+    }
+}