From 9d8df0e12c9b7bf071456d91685617781c5cfac6 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Sun, 6 Aug 2017 14:33:54 +0200 Subject: [PATCH] Simplified handling of GPU device IDs Removed gmx_gpu_device_id lookup function, whose indirect lookup of the device ID was more complicated than we need. We already require the user to select GPUs based on the IDs as understood by CUDA, so for simplicity, and without loss of generality, we can do that everywhere in the code. Removed a previously unused function for querying the name of an OpenCL device. Change-Id: I6557dd51f6b23591d4fd2b6383deb6abf58a0b92 --- src/gromacs/gpu_utils/gpu_utils.cu | 10 ---------- src/gromacs/gpu_utils/gpu_utils.h | 33 --------------------------------- src/gromacs/gpu_utils/gpu_utils_ocl.cpp | 23 ----------------------- src/gromacs/hardware/printhardware.cpp | 18 ++++++------------ 4 files changed, 6 insertions(+), 78 deletions(-) diff --git a/src/gromacs/gpu_utils/gpu_utils.cu b/src/gromacs/gpu_utils/gpu_utils.cu index 4ae442a374..0369333811 100644 --- a/src/gromacs/gpu_utils/gpu_utils.cu +++ b/src/gromacs/gpu_utils/gpu_utils.cu @@ -682,16 +682,6 @@ void get_gpu_device_info_string(char *s, const gmx_gpu_info_t &gpu_info, int ind } } -int get_gpu_device_id(const gmx_gpu_info_t &gpu_info, - const gmx_gpu_opt_t *gpu_opt, - int idx) -{ - assert(gpu_opt); - assert(idx >= 0 && idx < gpu_opt->n_dev_use); - - return gpu_info.gpu_dev[gpu_opt->dev_use[idx]].id; -} - int get_current_cuda_gpu_device_id(void) { int gpuid; diff --git a/src/gromacs/gpu_utils/gpu_utils.h b/src/gromacs/gpu_utils/gpu_utils.h index 2bb1e21f0c..b4371049be 100644 --- a/src/gromacs/gpu_utils/gpu_utils.h +++ b/src/gromacs/gpu_utils/gpu_utils.h @@ -52,7 +52,6 @@ struct gmx_device_info_t; struct gmx_gpu_info_t; -struct gmx_gpu_opt_t; namespace gmx { @@ -154,38 +153,6 @@ gmx_device_info_t *getDeviceInfo(const gmx_gpu_info_t &GPU_FUNC_ARGUMENT(gpu_inf CUDA_FUNC_QUALIFIER int get_current_cuda_gpu_device_id(void) CUDA_FUNC_TERM_WITH_RETURN(-1) -/*! \brief Returns an identifier for the GPU with a given index into the array of used GPUs. - * - * Getter function which, given an index into the array of GPUs in use - * (dev_use) -- typically an MPI rank --, returns an identifier of the - * respective GPU. - * - * \param[in] gpu_info Information about detected GPUs - * \param[in] gpu_opt Pointer to structure holding GPU options - * \param[in] idx Index into the array of used GPUs - * \returns device ID of the requested GPU - */ -GPU_FUNC_QUALIFIER -int get_gpu_device_id(const struct gmx_gpu_info_t &GPU_FUNC_ARGUMENT(gpu_info), - const gmx_gpu_opt_t *GPU_FUNC_ARGUMENT(gpu_opt), - int GPU_FUNC_ARGUMENT(idx)) GPU_FUNC_TERM_WITH_RETURN(-1) - -/*! \brief Returns the name for the OpenCL GPU with a given index into the array of used GPUs. - * - * Getter function which, given an index into the array of GPUs in use - * (dev_use) -- typically a tMPI/MPI rank --, returns the device name for the - * respective OpenCL GPU. - * - * \param[in] gpu_info Pointer to structure holding GPU information - * \param[in] gpu_opt Pointer to structure holding GPU options - * \param[in] idx Index into the array of used GPUs - * \returns A string with the name of the requested OpenCL GPU - */ -OPENCL_FUNC_QUALIFIER -char* get_ocl_gpu_device_name(const struct gmx_gpu_info_t *OPENCL_FUNC_ARGUMENT(gpu_info), - const gmx_gpu_opt_t *OPENCL_FUNC_ARGUMENT(gpu_opt), - int OPENCL_FUNC_ARGUMENT(idx)) OPENCL_FUNC_TERM_WITH_RETURN(NULL) - /*! \brief Formats and returns a device information string for a given GPU. * * Given an index *directly* into the array of available GPUs (gpu_dev) diff --git a/src/gromacs/gpu_utils/gpu_utils_ocl.cpp b/src/gromacs/gpu_utils/gpu_utils_ocl.cpp index efbb796879..9ffb558588 100644 --- a/src/gromacs/gpu_utils/gpu_utils_ocl.cpp +++ b/src/gromacs/gpu_utils/gpu_utils_ocl.cpp @@ -417,17 +417,6 @@ void init_gpu(const gmx::MDLogger & /*mdlog*/, } //! This function is documented in the header file -int get_gpu_device_id(const gmx_gpu_info_t &, - const gmx_gpu_opt_t *gpu_opt, - int idx) -{ - assert(gpu_opt); - assert(idx >= 0 && idx < gpu_opt->n_dev_use); - - return gpu_opt->dev_use[idx]; -} - -//! This function is documented in the header file gmx_device_info_t *getDeviceInfo(const gmx_gpu_info_t &gpu_info, int deviceId) { @@ -439,18 +428,6 @@ gmx_device_info_t *getDeviceInfo(const gmx_gpu_info_t &gpu_info, } //! This function is documented in the header file -char* get_ocl_gpu_device_name(const gmx_gpu_info_t *gpu_info, - const gmx_gpu_opt_t *gpu_opt, - int idx) -{ - assert(gpu_info); - assert(gpu_opt); - assert(idx >= 0 && idx < gpu_opt->n_dev_use); - - return gpu_info->gpu_dev[gpu_opt->dev_use[idx]].device_name; -} - -//! This function is documented in the header file size_t sizeof_gpu_dev_info(void) { return sizeof(gmx_device_info_t); diff --git a/src/gromacs/hardware/printhardware.cpp b/src/gromacs/hardware/printhardware.cpp index f02c4a8475..3aab8536e5 100644 --- a/src/gromacs/hardware/printhardware.cpp +++ b/src/gromacs/hardware/printhardware.cpp @@ -94,15 +94,13 @@ static int gmx_count_gpu_dev_shared(const gmx_gpu_opt_t *gpu_opt, bool userSetGp * GPU IDs, the number of GPUs user (per node) can be different from the * number of GPU IDs selected. */ -static size_t 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_opt_t *gpu_opt) { GMX_RELEASE_ASSERT(gpu_opt, "gpu_opt must be a non-NULL pointer"); std::set uniqIds; - for (int i = 0; i < gpu_opt->n_dev_use; i++) + for (int deviceId = 0; deviceId < gpu_opt->n_dev_use; deviceId++) { - int deviceId = get_gpu_device_id(gpu_info, gpu_opt, i); uniqIds.insert(deviceId); } return uniqIds.size(); @@ -149,15 +147,11 @@ makeGpuUsageReport(const gmx_gpu_info_t &gpu_info, std::string output; { - std::vector gpuIdsInUse; - for (int i = 0; i < ngpu_use; i++) - { - gpuIdsInUse.push_back(get_gpu_device_id(gpu_info, gpu_opt, i)); - } - std::string gpuIdsString = + std::vector gpuIdsInUse(gpu_opt->dev_use, gpu_opt->dev_use + ngpu_use); + std::string gpuIdsString = formatAndJoin(gpuIdsInUse, ",", gmx::StringFormatter("%d")); - size_t numGpusInUse = gmx_count_gpu_dev_unique(gpu_info, gpu_opt); - bool bPluralGpus = numGpusInUse > 1; + size_t numGpusInUse = gmx_count_gpu_dev_unique(gpu_opt); + bool bPluralGpus = numGpusInUse > 1; if (bPrintHostName) { -- 2.11.4.GIT