From 1d52685ab67e5f6a935d5171549933da6f4c7e18 Mon Sep 17 00:00:00 2001 From: Aleksei Iupinov Date: Wed, 14 Dec 2016 18:14:13 +0100 Subject: [PATCH] Simplify gmx_count_gpu_dev_unique() Simplified counting of GPUs in use. A redundant call to gmx_gpu_sharing_supported() is also removed, as it should only be used during the GPU assignment stage. Change-Id: I203f5b270dc8d1bbb87cb9b847ff9a77b7e703e5 --- src/gromacs/hardware/detecthardware.cpp | 42 +++++++++------------------------ 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/src/gromacs/hardware/detecthardware.cpp b/src/gromacs/hardware/detecthardware.cpp index 910021a6bd..9a6c7b49c6 100644 --- a/src/gromacs/hardware/detecthardware.cpp +++ b/src/gromacs/hardware/detecthardware.cpp @@ -140,8 +140,8 @@ static tMPI_Thread_mutex_t hw_info_lock = TMPI_THREAD_MUTEX_INITIALIZER; #define HOSTNAMELEN 80 /* FW decl. */ -static int gmx_count_gpu_dev_unique(const gmx_gpu_info_t *gpu_info, - const gmx_gpu_opt_t *gpu_opt); +static size_t gmx_count_gpu_dev_unique(const gmx_gpu_info_t *gpu_info, + const gmx_gpu_opt_t *gpu_opt); gmx_bool gmx_multiple_gpu_per_node_supported() { @@ -227,14 +227,14 @@ makeGpuUsageReport(const gmx_gpu_info_t *gpu_info, } std::string gpuIdsString = formatAndJoin(gpuIdsInUse, ",", gmx::StringFormatter("%d")); - int numGpusInUse = gmx_count_gpu_dev_unique(gpu_info, gpu_opt); + size_t numGpusInUse = gmx_count_gpu_dev_unique(gpu_info, gpu_opt); bool bPluralGpus = numGpusInUse > 1; if (bPrintHostName) { output += gmx::formatString("On host %s ", host); } - output += gmx::formatString("%d GPU%s %sselected for this run.\n" + output += gmx::formatString("%zu GPU%s %sselected for this run.\n" "Mapping of GPU ID%s to the %d PP rank%s in this node: %s\n", numGpusInUse, bPluralGpus ? "s" : "", gpu_opt->bUserSet ? "user-" : "auto-", @@ -547,39 +547,19 @@ int gmx_count_gpu_dev_shared(const gmx_gpu_opt_t *gpu_opt) * GPU IDs, the number of GPUs user (per node) can be different from the * number of GPU IDs selected. */ -static int gmx_count_gpu_dev_unique(const gmx_gpu_info_t *gpu_info, - const gmx_gpu_opt_t *gpu_opt) +static size_t gmx_count_gpu_dev_unique(const gmx_gpu_info_t *gpu_info, + const gmx_gpu_opt_t *gpu_opt) { - int i, uniq_count, ngpu; - int *uniq_ids; - GMX_RELEASE_ASSERT(gpu_info, "gpu_info must be a non-NULL pointer"); GMX_RELEASE_ASSERT(gpu_opt, "gpu_opt must be a non-NULL pointer"); - ngpu = gpu_info->n_dev; - - uniq_count = 0; - - snew(uniq_ids, ngpu); - - /* Each element in uniq_ids will be set to 0 or 1. The n-th element set - * to 1 indicates that the respective GPU was selected to be used. */ - for (i = 0; i < gpu_opt->n_dev_use; i++) + std::set uniqIds; + for (int i = 0; i < gpu_opt->n_dev_use; i++) { - int device_id; - - device_id = gmx_gpu_sharing_supported() ? get_gpu_device_id(gpu_info, gpu_opt, i) : i; - uniq_ids[device_id] = 1; + int deviceId = get_gpu_device_id(gpu_info, gpu_opt, i); + uniqIds.insert(deviceId); } - /* Count the devices used. */ - for (i = 0; i < ngpu; i++) - { - uniq_count += uniq_ids[i]; - } - - sfree(uniq_ids); - - return uniq_count; + return uniqIds.size(); } static void gmx_detect_gpus(const gmx::MDLogger &mdlog, const t_commrec *cr) -- 2.11.4.GIT