1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2010, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
42 #include "types/hw_info.h"
44 #include "gpu_utils.h"
45 #include "../cuda_tools/cudautils.cuh"
46 #include "memtestG80_core.h"
49 #define QUICK_MEM 250 /*!< Amount of memory to be used in quick memtest. */
50 #define QUICK_TESTS MOD_20_32BIT | LOGIC_4_ITER_SHMEM | RANDOM_BLOCKS /*!< Bit flag with type of tests
51 to run in quick memtest. */
52 #define QUICK_ITER 3 /*!< Number of iterations in quick memtest. */
54 #define FULL_TESTS 0x3FFF /*!< Bitflag with all test set on for full memetest. */
55 #define FULL_ITER 25 /*!< Number of iterations in full memtest. */
57 #define TIMED_TESTS MOD_20_32BIT | LOGIC_4_ITER_SHMEM | RANDOM_BLOCKS /*!< Bit flag with type of tests to
58 run in time constrained memtest. */
60 /*! Number of supported GPUs */
61 #define NB_GPUS (sizeof(SupportedGPUs)/sizeof(SupportedGPUs[0]))
63 static int cuda_max_device_count = 32; /*! Max number of devices supported by CUDA (for consistency checking).
64 In reality it 16 with CUDA <=v5.0, but let's stay on the safe side. */
66 /*! Dummy kernel used for sanity checking. */
67 __global__ void k_dummy_test(){}
70 /*! Bit-flags which refer to memtestG80 test types and are used in do_memtest to specify which tests to run. */
71 enum memtest_G80_test_types {
72 MOVING_INVERSIONS_10 = 0x1,
73 MOVING_INVERSIONS_RAND = 0x2,
74 WALKING_8BIT_M86 = 0x4,
76 WALKING_1_8BIT = 0x10,
77 WALKING_0_32BIT = 0x20,
78 WALKING_1_32BIT = 0x40,
83 LOGIC_1_ITER_SHMEM = 0x800,
84 LOGIC_4_ITER_SHMEM = 0x1000
87 // TODO put this list into an external file and include it so that the list is easily accessible
88 /*! List of supported GPUs. */
89 static const char * const SupportedGPUs[] = {
125 "Quadro Plex 2200 D2",
126 "Quadro Plex 2200 S4",
129 "GeForce 9800 G", /* GX2, GTX, GTX+, GT */
133 "Quadro Plex 2100 D4"
138 * \brief Runs GPU sanity checks.
140 * Runs a series of checks to determine that the given GPU and underlying CUDA
141 * driver/runtime functions properly.
142 * Returns properties of a device with given ID or the one that has
143 * already been initialized earlier in the case if of \dev_id == -1.
145 * \param[in] dev_id the device ID of the GPU or -1 if the device has already been initialized
146 * \param[out] dev_prop pointer to the structure in which the device properties will be returned
147 * \returns 0 if the device looks OK
149 static int do_sanity_checks(int dev_id, cudaDeviceProp *dev_prop)
154 cu_err = cudaGetDeviceCount(&dev_count);
155 if (cu_err != cudaSuccess)
157 fprintf(stderr, "Error %d while querying device count: %s\n", cu_err,
158 cudaGetErrorString(cu_err));
162 /* no CUDA compatible device at all */
166 /* things might go horribly wrong if cudart is not compatible with the driver */
167 if (dev_count < 0 || dev_count > cuda_max_device_count)
170 if (dev_id == -1) /* device already selected let's not destroy the context */
172 cu_err = cudaGetDevice(&id);
173 if (cu_err != cudaSuccess)
175 fprintf(stderr, "Error %d while querying device id: %s\n", cu_err,
176 cudaGetErrorString(cu_err));
183 if (id > dev_count - 1) /* pfff there's no such device */
185 fprintf(stderr, "The requested device with id %d does not seem to exist (device count=%d)\n",
191 memset(dev_prop, 0, sizeof(cudaDeviceProp));
192 cu_err = cudaGetDeviceProperties(dev_prop, id);
193 if (cu_err != cudaSuccess)
195 fprintf(stderr, "Error %d while querying device properties: %s\n", cu_err,
196 cudaGetErrorString(cu_err));
200 /* both major & minor is 9999 if no CUDA capable devices are present */
201 if (dev_prop->major == 9999 && dev_prop->minor == 9999)
203 /* we don't care about emulation mode */
204 if (dev_prop->major == 0)
209 cu_err = cudaSetDevice(id);
210 if (cu_err != cudaSuccess)
212 fprintf(stderr, "Error %d while switching to device #%d: %s\n",
213 cu_err, id, cudaGetErrorString(cu_err));
218 /* try to execute a dummy kernel */
219 k_dummy_test<<<1, 512>>>();
220 CU_LAUNCH_ERR_SYNC("dummy test kernel");
222 /* destroy context if we created one */
225 #if CUDA_VERSION < 4000
226 cu_err = cudaThreadExit();
227 CU_RET_ERR(cu_err, "cudaThreadExit failed");
229 cu_err = cudaDeviceReset();
230 CU_RET_ERR(cu_err, "cudaDeviceReset failed");
239 * \brief Checks whether the GPU with the given name is supported in Gromacs-OpenMM.
241 * \param[in] gpu_name the name of the CUDA device
242 * \returns TRUE if the device is supported, otherwise FALSE
244 static bool is_gmx_openmm_supported_gpu_name(char *gpuName)
247 for (i = 0; i < NB_GPUS; i++)
250 if (gmx_strncasecmp(gpuName, SupportedGPUs[i], strlen(SupportedGPUs[i])) == 0)
256 /*! \brief Checks whether the GPU with the given device id is supported in Gromacs-OpenMM.
258 * \param[in] dev_id the device id of the GPU or -1 if the device has already been selected
259 * \param[out] gpu_name Set to contain the name of the CUDA device, if NULL passed, no device name is set.
260 * \returns TRUE if the device is supported, otherwise FALSE
263 gmx_bool is_gmx_openmm_supported_gpu(int dev_id, char *gpu_name)
265 cudaDeviceProp dev_prop;
267 if (debug) fprintf(debug, "Checking compatibility with device #%d, %s\n", dev_id, gpu_name);
269 if (do_sanity_checks(dev_id, &dev_prop) != 0)
272 if (gpu_name != NULL)
274 strcpy(gpu_name, dev_prop.name);
276 return is_gmx_openmm_supported_gpu_name(dev_prop.name);
281 * \brief Runs a set of memory tests specified by the given bit-flags.
282 * Tries to allocate and do the test on \p megs Mb memory or
283 * the greatest amount that can be allocated (>10Mb).
284 * In case if an error is detected it stops without finishing the remaining
285 * steps/iterations and returns greater then zero value.
286 * In case of other errors (e.g. kernel launch errors, device querying errors)
289 * \param[in] which_tests variable with bit-flags of the requested tests
290 * \param[in] megs amount of memory that will be tested in MB
291 * \param[in] iter number of iterations
292 * \returns 0 if no error was detected, otherwise >0
294 static int do_memtest(unsigned int which_tests, int megs, int iter)
298 uint err_count; //, err_iter;
300 // no parameter check as this fn won't be called externally
302 // let's try to allocate the mem
303 while (!tester.allocate(megs) && (megs - 10 > 0))
304 { megs -= 10; tester.deallocate(); }
308 fprintf(stderr, "Unable to allocate GPU memory!\n");
312 // clear the first 18 bits
313 which_tests &= 0x3FFF;
314 for (i = 0; i < iter; i++)
316 // Moving Inversions (ones and zeros)
317 if ((MOVING_INVERSIONS_10 & which_tests) == MOVING_INVERSIONS_10)
319 tester.gpuMovingInversionsOnesZeros(err_count);
321 return MOVING_INVERSIONS_10;
323 // Moving Inversions (random)
324 if ((MOVING_INVERSIONS_RAND & which_tests) == MOVING_INVERSIONS_RAND)
326 tester.gpuMovingInversionsRandom(err_count);
328 return MOVING_INVERSIONS_RAND;
330 // Memtest86 Walking 8-bit
331 if ((WALKING_8BIT_M86 & which_tests) == WALKING_8BIT_M86)
333 for (uint shift = 0; shift < 8; shift++)
335 tester.gpuWalking8BitM86(err_count, shift);
337 return WALKING_8BIT_M86;
340 // True Walking zeros (8-bit)
341 if ((WALKING_0_8BIT & which_tests) == WALKING_0_8BIT)
343 for (uint shift = 0; shift < 8; shift++)
345 tester.gpuWalking8Bit(err_count, false, shift);
347 return WALKING_0_8BIT;
350 // True Walking ones (8-bit)
351 if ((WALKING_1_8BIT & which_tests) == WALKING_1_8BIT)
353 for (uint shift = 0; shift < 8; shift++)
355 tester.gpuWalking8Bit(err_count, true, shift);
357 return WALKING_1_8BIT;
360 // Memtest86 Walking zeros (32-bit)
361 if ((WALKING_0_32BIT & which_tests) == WALKING_0_32BIT)
363 for (uint shift = 0; shift < 32; shift++)
365 tester.gpuWalking32Bit(err_count, false, shift);
367 return WALKING_0_32BIT;
370 // Memtest86 Walking ones (32-bit)
371 if ((WALKING_1_32BIT & which_tests) == WALKING_1_32BIT)
373 for (uint shift = 0; shift < 32; shift++)
375 tester.gpuWalking32Bit(err_count, true, shift);
377 return WALKING_1_32BIT;
381 if ((RANDOM_BLOCKS & which_tests) == RANDOM_BLOCKS)
383 tester.gpuRandomBlocks(err_count,rand());
385 return RANDOM_BLOCKS;
389 // Memtest86 Modulo-20
390 if ((MOD_20_32BIT & which_tests) == MOD_20_32BIT)
392 for (uint shift = 0; shift < 20; shift++)
394 tester.gpuModuloX(err_count, shift, rand(), 20, 2);
399 // Logic (one iteration)
400 if ((LOGIC_1_ITER & which_tests) == LOGIC_1_ITER)
402 tester.gpuShortLCG0(err_count,1);
406 // Logic (4 iterations)
407 if ((LOGIC_4_ITER & which_tests) == LOGIC_4_ITER)
409 tester.gpuShortLCG0(err_count,4);
414 // Logic (shared memory, one iteration)
415 if ((LOGIC_1_ITER_SHMEM & which_tests) == LOGIC_1_ITER_SHMEM)
417 tester.gpuShortLCG0Shmem(err_count,1);
419 return LOGIC_1_ITER_SHMEM;
421 // Logic (shared-memory, 4 iterations)
422 if ((LOGIC_4_ITER_SHMEM & which_tests) == LOGIC_4_ITER_SHMEM)
424 tester.gpuShortLCG0Shmem(err_count,4);
426 return LOGIC_4_ITER_SHMEM;
434 /*! \brief Runs a quick memory test and returns 0 in case if no error is detected.
435 * If an error is detected it stops before completing the test and returns a
436 * value greater then 0. In case of other errors (e.g. kernel launch errors,
437 * device querying errors) -1 is returned.
439 * \param[in] dev_id the device id of the GPU or -1 if the device has already been selected
440 * \returns 0 if no error was detected, otherwise >0
442 int do_quick_memtest(int dev_id)
444 cudaDeviceProp dev_prop;
445 int devmem, res, time=0;
447 if (debug) { time = getTimeMilliseconds(); }
449 if (do_sanity_checks(dev_id, &dev_prop) != 0)
451 // something went wrong
457 devmem = dev_prop.totalGlobalMem/(1024*1024); // in MiB
458 fprintf(debug, ">> Running QUICK memtests on %d MiB (out of total %d MiB), %d iterations\n",
459 QUICK_MEM, devmem, QUICK_ITER);
462 res = do_memtest(QUICK_TESTS, QUICK_MEM, QUICK_ITER);
466 fprintf(debug, "Q-RES = %d\n", res);
467 fprintf(debug, "Q-runtime: %d ms\n", getTimeMilliseconds() - time);
470 /* destroy context only if we created it */
471 if (dev_id !=-1) cudaThreadExit();
475 /*! \brief Runs a full memory test and returns 0 in case if no error is detected.
476 * If an error is detected it stops before completing the test and returns a
477 * value greater then 0. In case of other errors (e.g. kernel launch errors,
478 * device querying errors) -1 is returned.
480 * \param[in] dev_id the device id of the GPU or -1 if the device has already been selected
481 * \returns 0 if no error was detected, otherwise >0
484 int do_full_memtest(int dev_id)
486 cudaDeviceProp dev_prop;
487 int devmem, res, time=0;
489 if (debug) { time = getTimeMilliseconds(); }
491 if (do_sanity_checks(dev_id, &dev_prop) != 0)
493 // something went wrong
497 devmem = dev_prop.totalGlobalMem/(1024*1024); // in MiB
501 fprintf(debug, ">> Running FULL memtests on %d MiB (out of total %d MiB), %d iterations\n",
502 devmem, devmem, FULL_ITER);
505 /* do all test on the entire memory */
506 res = do_memtest(FULL_TESTS, devmem, FULL_ITER);
510 fprintf(debug, "F-RES = %d\n", res);
511 fprintf(debug, "F-runtime: %d ms\n", getTimeMilliseconds() - time);
514 /* destroy context only if we created it */
515 if (dev_id != -1) cudaThreadExit();
519 /*! \brief Runs a time constrained memory test and returns 0 in case if no error is detected.
520 * If an error is detected it stops before completing the test and returns a value greater
521 * than zero. In case of other errors (e.g. kernel launch errors, device querying errors) -1
522 * is returned. Note, that test iterations are not interrupted therefor the total runtime of
523 * the test will always be multipple of one iteration's runtime.
525 * \param[in] dev_id the device id of the GPU or -1 if the device has laredy been selected
526 * \param[in] time_constr the time limit of the testing
527 * \returns 0 if no error was detected, otherwise >0
529 int do_timed_memtest(int dev_id, int time_constr)
531 cudaDeviceProp dev_prop;
532 int devmem, res=0, time=0, startt;
534 if (debug) { time = getTimeMilliseconds(); }
536 time_constr *= 1000; /* convert to ms for convenience */
537 startt = getTimeMilliseconds();
539 if (do_sanity_checks(dev_id, &dev_prop) != 0)
541 // something went wrong
545 devmem = dev_prop.totalGlobalMem/(1024*1024); // in MiB
549 fprintf(debug, ">> Running time constrained memtests on %d MiB (out of total %d MiB), time limit of %d s \n",
550 devmem, devmem, time_constr);
553 /* do the TIMED_TESTS set, one step at a time on the entire memory
554 that can be allocated, and stop when the given time is exceeded */
555 while ( ((int)getTimeMilliseconds() - startt) < time_constr)
557 res = do_memtest(TIMED_TESTS, devmem, 1);
563 fprintf(debug, "T-RES = %d\n", res);
564 fprintf(debug, "T-runtime: %d ms\n", getTimeMilliseconds() - time);
567 /* destroy context only if we created it */
568 if (dev_id != -1) cudaThreadExit();
572 /*! \brief Initializes the GPU with the given index.
574 * The varible \mygpu is the index of the GPU to initialize in the
575 * gpu_info.cuda_dev array.
577 * \param[in] mygpu index of the GPU to initialize
578 * \param[out] result_str the message related to the error that occurred
579 * during the initialization (if there was any).
580 * \param[in] gpu_info GPU info of all detected devices in the system.
581 * \returns true if no error occurs during initialization.
583 gmx_bool init_gpu(int mygpu, char *result_str, const gmx_gpu_info_t *gpu_info)
592 if (mygpu < 0 || mygpu >= gpu_info->ncuda_dev_use)
594 sprintf(sbuf, "Trying to initialize an inexistent GPU: "
595 "there are %d %s-selected GPU(s), but #%d was requested.",
596 gpu_info->ncuda_dev_use, gpu_info->bUserSet ? "user" : "auto", mygpu);
600 gpuid = gpu_info->cuda_dev[gpu_info->cuda_dev_use[mygpu]].id;
602 stat = cudaSetDevice(gpuid);
603 strncpy(result_str, cudaGetErrorString(stat), STRLEN);
607 fprintf(stderr, "Initialized GPU ID #%d: %s\n", gpuid, gpu_info->cuda_dev[gpuid].prop.name);
610 return (stat == cudaSuccess);
613 /*! \brief Frees up the CUDA GPU used by the active context at the time of calling.
615 * The context is explicitly destroyed and therefore all data uploaded to the GPU
616 * is lost. This should only be called when none of this data is required anymore.
618 * \param[out] result_str the message related to the error that occurred
619 * during the initialization (if there was any).
620 * \returns true if no error occurs during the freeing.
622 gmx_bool free_gpu(char *result_str)
631 stat = cudaGetDevice(&gpuid);
632 CU_RET_ERR(stat, "cudaGetDevice failed");
633 fprintf(stderr, "Cleaning up context on GPU ID #%d\n", gpuid);
636 #if CUDA_VERSION < 4000
637 stat = cudaThreadExit();
639 stat = cudaDeviceReset();
641 strncpy(result_str, cudaGetErrorString(stat), STRLEN);
643 return (stat == cudaSuccess);
646 /*! \brief Returns true if the gpu characterized by the device properties is
647 * supported by the native gpu acceleration.
649 * \param[in] dev_prop the CUDA device properties of the gpus to test.
650 * \returns true if the GPU properties passed indicate a compatible
651 * GPU, otherwise false.
653 static bool is_gmx_supported_gpu(const cudaDeviceProp *dev_prop)
655 return (dev_prop->major >= 2);
658 /*! \brief Helper function that checks whether a given GPU status indicates compatible GPU.
660 * \param[in] stat GPU status.
661 * \returns true if the provided status is egpuCompatible, otherwise false.
663 static bool is_compatible_gpu(int stat)
665 return (stat == egpuCompatible);
668 /*! \brief Checks if a GPU with a given ID is supported by the native GROMACS acceleration.
670 * Returns a status value which indicates compatibility or one of the following
671 * errors: incompatibility, insistence, or insanity (=unexpected behavior).
672 * It also returns the respective device's properties in \dev_prop (if applicable).
674 * \param[in] dev_id the ID of the GPU to check.
675 * \param[out] dev_prop the CUDA device properties of the device checked.
676 * \returns the status of the requested device
678 static int is_gmx_supported_gpu_id(int dev_id, cudaDeviceProp *dev_prop)
683 stat = cudaGetDeviceCount(&ndev);
684 CU_RET_ERR(stat, "cudaGetDeviceCount failed");
686 if (dev_id > ndev - 1)
688 return egpuNonexistent;
691 if (do_sanity_checks(dev_id, dev_prop) == 0)
693 if (is_gmx_supported_gpu(dev_prop))
695 return egpuCompatible;
699 return egpuIncompatible;
709 /*! \brief Detect all NVIDIA GPUs in the system.
711 * Will detect every NVIDIA GPU supported by the device driver in use. Also
712 * check for the compatibility of each and fill the gpu_info->cuda_dev array
713 * with the required information on each the device: ID, device properties,
716 * \param[in] gpu_info pointer to structure holding GPU information.
718 void detect_cuda_gpus(gmx_gpu_info_t *gpu_info)
720 int i, ndev, checkres;
723 cuda_dev_info_t *devs;
727 stat = cudaGetDeviceCount(&ndev);
728 CU_RET_ERR(stat, "cudaGetDeviceCount failed");
731 for (i = 0; i < ndev; i++)
733 checkres = is_gmx_supported_gpu_id(i, &prop);
737 devs[i].stat = checkres;
740 gpu_info->ncuda_dev = ndev;
741 gpu_info->cuda_dev = devs;
744 /*! \brief Select the GPUs compatible with the native GROMACS acceleration.
746 * This function selects the compatible gpus and initializes
747 * gpu_info->cuda_dev_use and gpu_info->ncuda_dev_use.
749 * Given the list of GPUs available in the system the it checks each gpu in
750 * gpu_info->cuda_dev and puts the the indices (into gpu_info->cuda_dev) of
751 * the compatible ones into cuda_dev_use with this marking the respective
752 * GPUs as "available for use."
753 * Note that \detect_cuda_gpus must have been called before.
755 * \param[in] gpu_info pointer to structure holding GPU information
757 void pick_compatible_gpus(gmx_gpu_info_t *gpu_info)
763 /* cuda_dev/ncuda_dev have to be either NULL/0 or not (NULL/0) */
764 assert((gpu_info->ncuda_dev != 0 ? 0 : 1) ^ (gpu_info->cuda_dev == NULL ? 0 : 1));
766 snew(compat, gpu_info->ncuda_dev);
768 for (i = 0; i < gpu_info->ncuda_dev; i++)
770 if (is_compatible_gpu(gpu_info->cuda_dev[i].stat))
773 compat[ncompat - 1] = i;
777 gpu_info->ncuda_dev_use = ncompat;
778 snew(gpu_info->cuda_dev_use, ncompat);
779 memcpy(gpu_info->cuda_dev_use, compat, ncompat*sizeof(*compat));
783 /*! \brief Check the existence/compatibility of a set of GPUs specified by their device IDs.
785 * Given the a list of GPU devide IDs in \requested_devs, check for the
786 * existence and compatibility of the respective GPUs and fill in \gpu_info
787 * with the collected information. Also provide the caller with an array with
788 * the result of checks in \checkres.
790 * \param[out] checkres check result for each ID passed in \requested_devs
791 * \param[in] gpu_info pointer to structure holding GPU information
792 * \param[in] requested_devs array of requested device IDs
793 * \param[in] count number of IDs in \requested_devs
794 * \returns TRUE if every requested GPU is compatible
796 gmx_bool check_select_cuda_gpus(int *checkres, gmx_gpu_info_t *gpu_info,
797 const int *requested_devs, int count)
804 assert(requested_devs);
812 /* we will assume that all GPUs requested are valid IDs,
813 otherwise we'll bail anyways */
814 gpu_info->ncuda_dev_use = count;
815 snew(gpu_info->cuda_dev_use, count);
818 for (i = 0; i < count; i++)
820 id = requested_devs[i];
822 /* devices are stored in increasing order of IDs in cuda_dev */
823 gpu_info->cuda_dev_use[i] = id;
825 checkres[i] = (id >= gpu_info->ncuda_dev) ?
826 egpuNonexistent : gpu_info->cuda_dev[id].stat;
828 bAllOk = bAllOk && is_compatible_gpu(checkres[i]);
834 /*! \brief Frees the cuda_dev and cuda_dev_use array fields of \gpu_info.
836 * \param[in] gpu_info pointer to structure holding GPU information
838 void free_gpu_info(const gmx_gpu_info_t *gpu_info)
840 if (gpu_info == NULL)
845 sfree(gpu_info->cuda_dev_use);
846 sfree(gpu_info->cuda_dev);
849 /*! \brief Formats and returns a device information string for a given GPU.
851 * Given an index *directly* into the array of available GPUs (cuda_dev)
852 * returns a formatted info string for the respective GPU which includes
853 * ID, name, compute capability, and detection status.
855 * \param[out] s pointer to output string (has to be allocated externally)
856 * \param[in] gpu_info pointer to structure holding GPU information
857 * \param[in] index an index *directly* into the array of available GPUs
859 void get_gpu_device_info_string(char *s, const gmx_gpu_info_t *gpu_info, int index)
864 if (index < 0 && index >= gpu_info->ncuda_dev)
869 cuda_dev_info_t *dinfo = &gpu_info->cuda_dev[index];
872 dinfo->stat == egpuCompatible ||
873 dinfo->stat == egpuIncompatible;
877 sprintf(s, "#%d: %s, stat: %s",
879 gpu_detect_res_str[dinfo->stat]);
883 sprintf(s, "#%d: NVIDIA %s, compute cap.: %d.%d, ECC: %3s, stat: %s",
884 dinfo->id, dinfo->prop.name,
885 dinfo->prop.major, dinfo->prop.minor,
886 dinfo->prop.ECCEnabled ? "yes" : " no",
887 gpu_detect_res_str[dinfo->stat]);
891 /*! \brief Returns the device ID of the GPU with a given index into the array of used GPUs.
893 * Getter function which, given an index into the array of GPUs in use
894 * (cuda_dev_use) -- typically a tMPI/MPI rank --, returns the device ID of the
895 * respective CUDA GPU.
897 * \param[in] gpu_info pointer to structure holding GPU information
898 * \param[in] idx index into the array of used GPUs
899 * \returns device ID of the requested GPU
901 int get_gpu_device_id(const gmx_gpu_info_t *gpu_info, int idx)
904 if (idx < 0 && idx >= gpu_info->ncuda_dev_use)
909 return gpu_info->cuda_dev[gpu_info->cuda_dev_use[idx]].id;
912 /*! \brief Returns the device ID of the GPU currently in use.
914 * The GPU used is the one that is active at the time of the call in the active context.
916 * \param[in] gpu_info pointer to structure holding GPU information
917 * \returns device ID of the GPU in use at the time of the call
919 int get_current_gpu_device_id(void)
922 CU_RET_ERR(cudaGetDevice(&gpuid), "cudaGetDevice failed");