/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2014,2015,2017,2018, 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 "config.h"
-#include <cassert>
+#include "gromacs/utility/arrayref.h"
+#include "gromacs/utility/enumerationhelpers.h"
+#include "gromacs/utility/stringutil.h"
-#include "gromacs/hardware/gpu_hw_info.h"
-#include "gromacs/utility/smalloc.h"
-
-#if !GMX_GPU
-/*! \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 /*unused*/,
- gmx_host_alloc_t **nb_alloc,
- gmx_host_free_t **nb_free)
-{
- *nb_alloc = nullptr;
- *nb_free = nullptr;
-}
-
-int gpu_info_get_stat(const gmx_gpu_info_t & /*unused*/, int /*unused*/)
-{
- return egpuNonexistent;
-}
+#ifdef _MSC_VER
+# pragma warning(disable : 6237)
#endif
-void free_gpu_info(const gmx_gpu_info_t *gpu_info)
+const char* enumValueToString(GpuApiCallBehavior enumValue)
{
- sfree(static_cast<void*>(gpu_info->gpu_dev)); //circumvent is_pod check in sfree
+ static constexpr gmx::EnumerationArray<GpuApiCallBehavior, const char*> s_gpuApiCallBehaviorNames = {
+ "Synchronous", "Asynchronous"
+ };
+ return s_gpuApiCallBehaviorNames[enumValue];
}
-std::vector<int> getCompatibleGpus(const gmx_gpu_info_t &gpu_info)
+bool decideGpuTimingsUsage()
{
- // Possible minor over-allocation here, but not important for anything
- std::vector<int> compatibleGpus;
- compatibleGpus.reserve(gpu_info.n_dev);
- for (int i = 0; i < gpu_info.n_dev; i++)
+ if (GMX_GPU_CUDA || GMX_GPU_SYCL)
{
- assert(gpu_info.gpu_dev);
- if (gpu_info_get_stat(gpu_info, i) == egpuCompatible)
- {
- compatibleGpus.push_back(i);
- }
+ /* 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;
}
- return compatibleGpus;
-}
-
-const char *getGpuCompatibilityDescription(const gmx_gpu_info_t &gpu_info,
- int index)
-{
- return (index >= gpu_info.n_dev ?
- gpu_detect_res_str[egpuNonexistent] :
- gpu_detect_res_str[gpu_info_get_stat(gpu_info, index)]);
}