Merge branch 'origin/release-2020' into merge-release-2020-into-master
[alexxy/gromacs.git] / src / gromacs / hardware / printhardware.cpp
index 43f70234094375cc7ed9b0a909b057ee30f5a93e..0720a12bbe9398a344acffd7eb8f6d24ad491268 100644 (file)
@@ -44,8 +44,8 @@
 #include <string>
 #include <vector>
 
-#include "gromacs/gpu_utils/gpu_utils.h"
 #include "gromacs/hardware/cpuinfo.h"
+#include "gromacs/hardware/device_management.h"
 #include "gromacs/hardware/hardwaretopology.h"
 #include "gromacs/hardware/hw_info.h"
 #include "gromacs/hardware/identifyavx512fmaunits.h"
 #include "architecture.h"
 
 //! Constant used to help minimize preprocessed code
-static const bool bGPUBinary = GMX_GPU != GMX_GPU_NONE;
+static constexpr bool bGPUBinary = (GMX_GPU != 0);
 
 /*! \internal \brief
  * Returns the GPU information text, one GPU per line.
  */
-static std::string sprint_gpus(const gmx_gpu_info_t& gpu_info)
+static std::string sprint_gpus(const std::vector<std::unique_ptr<DeviceInformation>>& deviceInfoList)
 {
-    char                     stmp[STRLEN];
-    std::vector<std::string> gpuStrings;
-    for (int i = 0; i < gpu_info.n_dev; i++)
+    std::vector<std::string> gpuStrings(0);
+    for (const auto& deviceInfo : deviceInfoList)
     {
-        get_gpu_device_info_string(stmp, gpu_info, i);
-        gpuStrings.push_back(gmx::formatString("    %s", stmp));
+        gpuStrings.emplace_back("    " + getDeviceInformationString(*deviceInfo));
     }
     return gmx::joinStrings(gpuStrings, "\n");
 }
@@ -84,7 +82,7 @@ static std::string sprint_gpus(const gmx_gpu_info_t& gpu_info)
    and runtime CPU do not match. */
 static void check_use_of_rdtscp_on_this_cpu(const gmx::MDLogger& mdlog, const gmx::CpuInfo& cpuInfo)
 {
-    bool binaryUsesRdtscp = HAVE_RDTSCP;
+    bool binaryUsesRdtscp = GMX_USE_RDTSCP;
 
     const char* programName = gmx::getProgramContext().displayName();
 
@@ -147,14 +145,21 @@ static std::string detected_hardware_string(const gmx_hw_info_t* hwinfo, bool bF
         s += gmx::formatString(" %d cores,", hwinfo->ncore_tot);
     }
     s += gmx::formatString(" %d logical cores", hwinfo->nhwthread_tot);
-    if (hwinfo->gpu_info.bDetectGPUs)
+    if (canPerformDeviceDetection(nullptr))
     {
         s += gmx::formatString(", %d compatible GPU%s", hwinfo->ngpu_compatible_tot,
                                hwinfo->ngpu_compatible_tot == 1 ? "" : "s");
     }
     else if (bGPUBinary)
     {
-        s += gmx::formatString(" (GPU detection deactivated)");
+        if (isDeviceDetectionEnabled())
+        {
+            s += gmx::formatString(" (GPU detection failed)");
+        }
+        else
+        {
+            s += gmx::formatString(" (GPU detection deactivated)");
+        }
     }
     s += gmx::formatString("\n");
 
@@ -346,11 +351,12 @@ static std::string detected_hardware_string(const gmx_hw_info_t* hwinfo, bool bF
         }
     }
 
-    if (bGPUBinary && hwinfo->gpu_info.n_dev > 0)
+    if (bGPUBinary && !hwinfo->deviceInfoList.empty())
     {
         s += gmx::formatString("  GPU info:\n");
-        s += gmx::formatString("    Number of GPUs detected: %d\n", hwinfo->gpu_info.n_dev);
-        s += sprint_gpus(hwinfo->gpu_info) + "\n";
+        s += gmx::formatString("    Number of GPUs detected: %d\n",
+                               static_cast<int>(hwinfo->deviceInfoList.size()));
+        s += sprint_gpus(hwinfo->deviceInfoList) + "\n";
     }
     return s;
 }