Unify handling of GMX_ENABLE_GPU_TIMING and GMX_DISABLE_GPU_TIMING
[alexxy/gromacs.git] / src / gromacs / gpu_utils / gpu_utils.cpp
index 3b943dabfb31f3fd29f1d5ab39c48e1e236e5a7f..2d8846caa334f827ad6c3ed6846b87694a0c4b17 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015,2017,2018,2019, by the GROMACS development team.
+ * Copyright (c) 2020,2021, 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.
 
 #include "gpu_utils.h"
 
-#include "gromacs/hardware/gpu_hw_info.h"
+#include "config.h"
 
-/*! \brief Set allocation functions used by the GPU host
- *
- * Since GPU support is not configured, there is no host memory to
- * allocate. */
-void gpu_set_host_malloc_and_free(bool,
-                                  gmx_host_alloc_t **nb_alloc,
-                                  gmx_host_free_t  **nb_free)
-{
-    *nb_alloc = nullptr;
-    *nb_free  = nullptr;
-}
+#include "gromacs/utility/arrayref.h"
+#include "gromacs/utility/enumerationhelpers.h"
+#include "gromacs/utility/stringutil.h"
+
+#ifdef _MSC_VER
+#    pragma warning(disable : 6237)
+#endif
 
-//! This function is documented in the header file
-std::vector<int> getCompatibleGpus(const gmx_gpu_info_t & /*gpu_info*/)
+const char* enumValueToString(GpuApiCallBehavior enumValue)
 {
-    // There can't be any compatible GPUs
-    return std::vector<int>();
+    static constexpr gmx::EnumerationArray<GpuApiCallBehavior, const char*> s_gpuApiCallBehaviorNames = {
+        "Synchronous", "Asynchronous"
+    };
+    return s_gpuApiCallBehaviorNames[enumValue];
 }
 
-const char *getGpuCompatibilityDescription(const gmx_gpu_info_t & /*gpu_info*/,
-                                           int                    /*index*/)
+bool decideGpuTimingsUsage()
 {
-    return gpu_detect_res_str[egpuNonexistent];
+    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;
+    }
 }