From eb078802c4250a21648e0a44f4cfc51a9b6ed99b Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Tue, 15 Aug 2017 22:37:26 +0200 Subject: [PATCH] Moved logging functionality into GPU usage report This moves the logic about whether a GPU usage report is written into one place. Noted TODO to resolve bug created by the formerly split logic. Change-Id: Ieef7853994b4a84a2e45a06598fe852e8f7ac6f9 --- src/gromacs/hardware/printhardware.cpp | 29 +++++++++++++++++++---------- src/gromacs/hardware/printhardware.h | 34 +++++++++++++++++++--------------- src/programs/mdrun/runner.cpp | 14 ++------------ 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/gromacs/hardware/printhardware.cpp b/src/gromacs/hardware/printhardware.cpp index d4593ea298..6cdc812651 100644 --- a/src/gromacs/hardware/printhardware.cpp +++ b/src/gromacs/hardware/printhardware.cpp @@ -123,27 +123,35 @@ static std::string sprint_gpus(const gmx_gpu_info_t &gpu_info) return gmx::joinStrings(gpuStrings, "\n"); } -std::string -makeGpuUsageReport(const gmx_gpu_info_t &gpu_info, - bool userSetGpuIds, - const std::vector &gpuTaskAssignment, - size_t numPpRanks, - bool bPrintHostName) +void reportGpuUsage(const gmx::MDLogger &mdlog, + const gmx_gpu_info_t &gpu_info, + bool userSetGpuIds, + const std::vector &gpuTaskAssignment, + size_t numPpRanks, + bool bPrintHostName) { int ngpu_comp = gpu_info.n_dev_compatible; char host[STRLEN]; + if (gpuTaskAssignment.empty()) + { + return; + } + if (bPrintHostName) { gmx_gethostname(host, STRLEN); } + // TODO The logic for gpuTaskAssignment here and just above is faulty /* Issue a note if GPUs are available but not used */ if (ngpu_comp > 0 && gpuTaskAssignment.empty()) { - return gmx::formatString("%d compatible GPU%s detected in the system, but none will be used.\n" - "Consider trying GPU acceleration with the Verlet scheme!\n", - ngpu_comp, (ngpu_comp > 1) ? "s" : ""); + auto message = gmx::formatString("%d compatible GPU%s detected in the system, but none will be used.\n" + "Consider trying GPU acceleration with the Verlet scheme!\n", + ngpu_comp, (ngpu_comp > 1) ? "s" : ""); + GMX_LOG(mdlog.warning).appendText(message); + return; } std::string output; @@ -184,7 +192,8 @@ makeGpuUsageReport(const gmx_gpu_info_t &gpu_info, " PP ranks on a node than GPUs available on that node.\n"); } - return output; + /* NOTE: this print is only for and on one physical node */ + GMX_LOG(mdlog.warning).appendText(output); } /* Give a suitable fatal error or warning if the build configuration diff --git a/src/gromacs/hardware/printhardware.h b/src/gromacs/hardware/printhardware.h index c90b81ef26..bd563683c8 100644 --- a/src/gromacs/hardware/printhardware.h +++ b/src/gromacs/hardware/printhardware.h @@ -56,21 +56,25 @@ void gmx_print_detected_hardware(FILE *fplog, const t_commrec *cr, const gmx::MDLogger &mdlog, const gmx_hw_info_t *hwinfo); -/*! \brief Helper function for reporting GPU usage information - * in the mdrun log file +/*! \brief Log a report on how GPUs are (or could be) being used on + * the ranks of the physical node of rank 0 of the simulation. * - * \param[in] gpu_info Information detected about GPUs - * \param[in] userSetGpuIds Whether the user selected the GPU ids - * \param[in] gpuTaskAssignment The selected GPU IDs. - * \param[in] numPpRanks Number of PP ranks per node - * \param[in] bPrintHostName Print the hostname in the usage information - * \return String to write to the log file - * \throws std::bad_alloc if out of memory */ -std::string -makeGpuUsageReport(const gmx_gpu_info_t &gpu_info, - bool userSetGpuIds, - const std::vector &gpuTaskAssignment, - size_t numPpRanks, - bool bPrintHostName); + * \todo It could be useful to report also whether any nodes differed, + * and in what way. + * + * \param[out] mdlog Logging object. + * \param[in] gpu_info Information detected about GPUs + * \param[in] userSetGpuIds Whether the user selected the GPU ids + * \param[in] gpuTaskAssignment The selected GPU IDs. + * \param[in] numPpRanks Number of PP ranks per node + * \param[in] bPrintHostName Print the hostname in the usage information + * + * \throws std::bad_alloc if out of memory */ +void reportGpuUsage(const gmx::MDLogger &mdlog, + const gmx_gpu_info_t &gpu_info, + bool userSetGpuIds, + const std::vector &gpuTaskAssignment, + size_t numPpRanks, + bool bPrintHostName); #endif diff --git a/src/programs/mdrun/runner.cpp b/src/programs/mdrun/runner.cpp index ee3664cb21..088a573540 100644 --- a/src/programs/mdrun/runner.cpp +++ b/src/programs/mdrun/runner.cpp @@ -1114,18 +1114,8 @@ int Mdrunner::mdrunner() userGpuTaskAssignment); } - /* If we are using GPUs, report on this rank how they are being - * used on this node. */ - if (!gpuTaskAssignment.empty()) - { - auto gpuUsageReport = - makeGpuUsageReport(hwinfo->gpu_info, !userGpuTaskAssignment.empty(), - gpuTaskAssignment, cr->nrank_pp_intranode, - cr->nnodes > 1); - - /* NOTE: this print is only for and on one physical node */ - GMX_LOG(mdlog.warning).appendText(gpuUsageReport); - } + reportGpuUsage(mdlog, hwinfo->gpu_info, !userGpuTaskAssignment.empty(), + gpuTaskAssignment, cr->nrank_pp_intranode, cr->nnodes > 1); /* check consistency across ranks of things like SIMD * support and number of GPUs selected */ -- 2.11.4.GIT