Update use of preprocessor in managing GPU support
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 20 Nov 2015 16:10:02 +0000 (17:10 +0100)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 9 Dec 2015 02:59:21 +0000 (03:59 +0100)
Once CMake has done detection of GPU library support, within CMake we
now use GMX_USE_CUDA and GMX_USE_OPENCL to handle details such as
which source code files should be compiled. This makes code in
CMakeLists.txt files slightly more clear.

To configure the GROMACS build via config.h, CMake sets GMX_GPU_TYPE
to match the name of one of three hard-coded defines in
config.h.cmake.in, and configures GMX_GPU with the value represented
by that name. This ensures GMX_GPU always has a value in source code,
so various kinds of mis-use will found by the compiler. It also means
we can use GMX_GPU and the values of those defines to simplify the
parts of high-level code that are different according to which GPU
configuration is in use - mostly in reporting to the user what is
going on. This reduces the number of complex preprocessor conditionals
that might want documenting or indenting, and makes it harder to write
a syntax error that can only be found with a particular build
configuration.

Minor change to the start-of-run reporting. Rather than show that GPU
is disabled/enabled, and OpenCL likewise, show disabled or which of
CUDA or OpenCL is enabled for GPU acceleration. The OpenCL library
name will make clear whether AMD or NVIDIA libraries is providing the
OpenCL runtime.

No changes to user interface of CMake. Removed redundant declaration
of option(GMX_GPU) from main CMakeLists.txt, since gmxManageGpu()
already did that.

No changes required to current or future compute code, since CMake
still handles whether such code is compiled at all.

Refs #1855

Change-Id: I3448fe284ac526eb2b185e915b95fcc84f3d469a

20 files changed:
CMakeLists.txt
cmake/gmxCFlags.cmake
src/CMakeLists.txt
src/config.h.cmakein
src/gromacs/CMakeLists.txt
src/gromacs/fileio/copyrite.cpp
src/gromacs/gmxlib/CMakeLists.txt
src/gromacs/gmxlib/cuda_tools/CMakeLists.txt
src/gromacs/gmxlib/gmx_detect_hardware.cpp
src/gromacs/gmxlib/gpu_utils/CMakeLists.txt
src/gromacs/gmxlib/gpu_utils/gpu_macros.h
src/gromacs/gmxlib/ocl_tools/CMakeLists.txt
src/gromacs/mdlib/CMakeLists.txt
src/gromacs/mdlib/nbnxn_cuda/CMakeLists.txt
src/gromacs/mdlib/nbnxn_gpu_types.h
src/gromacs/mdlib/nbnxn_ocl/CMakeLists.txt
src/gromacs/mdlib/sim_util.cpp
src/gromacs/utility/baseversion.cpp
src/gromacs/utility/baseversion.h
src/programs/mdrun/tests/moduletest.cpp

index 66bab775fd498b9eabbc38ace3f66b009f8312f2..7a6cbe565e48d065ac81166d38259bb434c734c6 100644 (file)
@@ -207,15 +207,22 @@ set(REQUIRED_CUDA_COMPUTE_CAPABILITY 2.0)
 set(REQUIRED_OPENCL_MIN_VERSION 1.1)
 
 if(NOT GMX_USE_OPENCL)
-    # CUDA detection is done only if GMX_USE_OPENCL is OFF
+    # CUDA detection is done only if GMX_USE_OPENCL is OFF.
     include(gmxManageGPU)
+    set(GMX_USE_CUDA ${GMX_GPU})
+    if(GMX_GPU)
+        set(GMX_GPU_ACCELERATION_FRAMEWORK "GMX_GPU_CUDA")
+    else()
+        set(GMX_GPU_ACCELERATION_FRAMEWORK "GMX_GPU_NONE")
+    endif()
 else()
-    #Now the OpenCL path
+    #Now the OpenCL path (for both AMD and NVIDIA)
     if(GMX_GPU)
         include(gmxManageOpenCL)
-    else(GMX_GPU)
+        set(GMX_GPU_ACCELERATION_FRAMEWORK "GMX_GPU_OPENCL")
+    else()
         message(FATAL_ERROR "OpenCL requested but GPU option is not enabled (try -DGMX_GPU=on) ")
-    endif(GMX_GPU)
+    endif()
 endif()
 
 include(gmxDetectSimd)
@@ -267,7 +274,6 @@ mark_as_advanced(GMX_BROKEN_CALLOC)
 option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
 mark_as_advanced(GMX_LOAD_PLUGINS)
 
-option(GMX_GPU  "Enable GPU acceleration" ON)
 option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
 
 option(GMX_USE_TNG "Use the TNG library for trajectory I/O" ON)
index a7dc69cd3274f5bb73cd46812143f8f69c65485e..c6eb416bce3296b3c1ce5e8fd43a44c7741f379a 100644 (file)
@@ -110,7 +110,7 @@ macro (gmx_c_flags)
         if (GMX_COMPILER_WARNINGS)
             GMX_TEST_CFLAG(CFLAGS_WARN "-Wall -Wno-unused -Wunused-value -Wunused-parameter" GMXC_CFLAGS)
             GMX_TEST_CFLAG(CFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wno-sign-compare -Wpointer-arith" GMXC_CFLAGS)
-            if(NOT GMX_GPU) #TODO: Fix that CUDA code has warnings
+            if(NOT GMX_USE_CUDA) #TODO: Fix that CUDA code has warnings
                 GMX_TEST_CFLAG(CFLAGS_WARN_UNDEF "-Wundef" GMXC_CFLAGS)
             endif()
             # Since 4.8 on by default. For previous version disabling is a no-op. Only disabling for Release because with assert
@@ -136,7 +136,7 @@ macro (gmx_c_flags)
             # Problematic with CUDA
             # GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EFFCXX "-Wnon-virtual-dtor" GMXC_CXXFLAGS)
             GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith" GMXC_CXXFLAGS)
-            if(NOT GMX_GPU)
+            if(NOT GMX_USE_CUDA)
                 GMX_TEST_CXXFLAG(CXXFLAGS_WARN_UNDEF "-Wundef" GMXC_CXXFLAGS)
             endif()
             GMX_TEST_CFLAG(CXXFLAGS_WARN_REL "-Wno-array-bounds" GMXC_CXXFLAGS_RELEASE_ONLY)
index cb08824a02240778b3130c6706c3dbdd78c1911c..11829495889c933dc8b9fa05e0f3af8ff8791f41 100644 (file)
@@ -38,7 +38,7 @@
 include(GetCompilerInfo.cmake)
 get_compiler_info(C BUILD_C_COMPILER BUILD_CFLAGS)
 get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS)
-if(GMX_GPU AND NOT GMX_USE_OPENCL)
+if(GMX_USE_CUDA)
     GMX_SET_CUDA_NVCC_FLAGS()
     get_cuda_compiler_info(CUDA_NVCC_COMPILER_INFO CUDA_NVCC_COMPILER_FLAGS)
 endif()
index 2ddd2a7cda154d96bb4affd7058657cfa1b92dac..4b89f17ef3b74e7bd90f2110948f7f2afd740bf8 100644 (file)
 /* Enable x86 gcc inline assembly */
 #cmakedefine GMX_X86_GCC_INLINE_ASM
 
-/* Use GPU native acceleration */
-#cmakedefine GMX_GPU
+/* Define constants useful for handling GPU support */
+#define GMX_GPU_NONE   0
+#define GMX_GPU_CUDA   1
+#define GMX_GPU_OPENCL 2
+/* Which kind of GPU support is configured */
+#define GMX_GPU @GMX_GPU_ACCELERATION_FRAMEWORK@
 
 /* CUDA runtime API version (identical to CUDART_VERSION from cuda_runtime_api.h) */
 #cmakedefine GMX_CUDA_VERSION @GMX_CUDA_VERSION@
index 7cf2c5d4d560784ab2bfed7d9b481e0be0c0a535..99d6c00ca10511e8ebdd758fdeafb32a37e338d9 100644 (file)
@@ -170,7 +170,7 @@ gmx_configure_version_file(
     REMOTE_HASH SOURCE_FILE)
 list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
 
-if (GMX_GPU AND NOT GMX_USE_OPENCL)
+if (GMX_USE_CUDA)
     cuda_add_library(libgromacs ${LIBGROMACS_SOURCES})
 else()
     add_library(libgromacs ${LIBGROMACS_SOURCES})
@@ -226,8 +226,11 @@ if (NOT GMX_BUILD_MDRUN_ONLY)
     include(InstallLibInfo.cmake)
 endif()
 
+# Technically, the user could want to do this for an OpenCL build
+# using the CUDA runtime, but currently there's no reason to want to
+# do that.
 if (INSTALL_CUDART_LIB) #can be set manual by user
-    if (GMX_GPU AND NOT GMX_USE_OPENCL)
+    if (GMX_USE_CUDA)
         foreach(CUDA_LIB ${CUDA_LIBRARIES})
             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
             if(IS_CUDART) #libcuda should not be installed
@@ -238,11 +241,11 @@ if (INSTALL_CUDART_LIB) #can be set manual by user
             endif()
         endforeach()
     else()
-        message(WARNING "INSTALL_CUDART_LIB only makes sense with GMX_GPU")
+        message(WARNING "INSTALL_CUDART_LIB only makes sense when configuring for CUDA support")
     endif()
 endif()
 
-if(GMX_GPU AND GMX_USE_OPENCL)
+if(GMX_USE_OPENCL)
     set(OPENCL_KERNELS ${MDLIB_OPENCL_KERNELS})
 
     install(FILES ${OPENCL_KERNELS} DESTINATION
index 3ad5e97be5faf65fa80ced8dac7fa2e483cbd48f..5a354dc1ae88b379ed0cc6659b1080226268fdff 100644 (file)
@@ -594,16 +594,7 @@ static void gmx_print_version_info(FILE *fp)
 #else
     fprintf(fp, "OpenMP support:     disabled\n");
 #endif
-#ifdef GMX_GPU
-    fprintf(fp, "GPU support:        enabled\n");
-#else
-    fprintf(fp, "GPU support:        disabled\n");
-#endif
-#if defined(GMX_GPU) && defined(GMX_USE_OPENCL)
-    fprintf(fp, "OpenCL support:     enabled\n");
-#else
-    fprintf(fp, "OpenCL support:     disabled\n");
-#endif
+    fprintf(fp, "GPU support:        %s\n", getGpuImplementationString());
     /* A preprocessor trick to avoid duplicating logic from vec.h */
 #define gmx_stringify2(x) #x
 #define gmx_stringify(x) gmx_stringify2(x)
@@ -649,14 +640,13 @@ static void gmx_print_version_info(FILE *fp)
     fprintf(fp, "Linked with Intel MKL version %d.%d.%d.\n",
             __INTEL_MKL__, __INTEL_MKL_MINOR__, __INTEL_MKL_UPDATE__);
 #endif
-#if defined(GMX_GPU)
-#ifdef GMX_USE_OPENCL
+#if GMX_GPU == GMX_GPU_OPENCL
     fprintf(fp, "OpenCL include dir: %s\n", OPENCL_INCLUDE_DIR);
     fprintf(fp, "OpenCL library:     %s\n", OPENCL_LIBRARY);
     fprintf(fp, "OpenCL version:     %s\n", OPENCL_VERSION_STRING);
-#else
-    gmx_print_version_info_cuda_gpu(fp);
 #endif
+#if GMX_GPU == GMX_GPU_CUDA
+    gmx_print_version_info_cuda_gpu(fp);
 #endif
 }
 
index 4f0d313ea89639d4d447424105208564a1381378..18cbd686956bdbe70061921141365688a475ab82 100644 (file)
@@ -40,14 +40,8 @@ add_subdirectory(nonbonded)
 # conditionally built, so we cannot use a GLOB_RECURSE here.
 file(GLOB GMXLIB_SOURCES *.cpp)
 
-# gpu utils + cuda tools module
-if(GMX_GPU)
-    if(NOT GMX_USE_OPENCL)
-        add_subdirectory(cuda_tools)
-    else()
-        add_subdirectory(ocl_tools)
-    endif()
-endif()
+add_subdirectory(cuda_tools)
+add_subdirectory(ocl_tools)
 add_subdirectory(gpu_utils)
 
 set(GMXLIB_SOURCES ${GMXLIB_SOURCES} ${NONBONDED_SOURCES} PARENT_SCOPE)
index 67d2cbe8650e4d9a09a49c2c1107540e051eabe1..94dbf2b3bb899679af556b4ce26d360acd47ed50 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2012,2014, by the GROMACS development team, led by
+# Copyright (c) 2012,2014,2015, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-if(GMX_GPU)
+if(GMX_USE_CUDA)
     file(GLOB CUDA_TOOLS_SOURCES *.cu)
     set(GMXLIB_SOURCES ${GMXLIB_SOURCES} ${CUDA_TOOLS_SOURCES} PARENT_SCOPE)
 endif()
index 2a00dd5df77f0410ab1ddc46f76f4b5b95134b3b..0ca346bb1df97a63f5f160cbfeed27d710528a90 100644 (file)
@@ -69,6 +69,7 @@
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/basenetwork.h"
+#include "gromacs/utility/baseversion.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/stringutil.h"
 #include "gromacs/utility/sysinfo.h"
 
+static const bool bGPUBinary = GMX_GPU != GMX_GPU_NONE;
 
-#ifdef GMX_GPU
+/* Note that some of the following arrays must match the "GPU support
+ * enumeration" in src/config.h.cmakein, so that GMX_GPU looks up an
+ * array entry. */
 
-static const bool  bGPUBinary = TRUE;
+/* CUDA supports everything. Our current OpenCL implementation only
+ * supports using exactly one GPU per PP rank, so sharing is
+ * impossible */
+static const bool gpuSharingSupport[] = { false, true, false };
+static const bool bGpuSharingSupported = gpuSharingSupport[GMX_GPU];
 
-#  ifdef GMX_USE_OPENCL
-
-static const char *gpu_implementation       = "OpenCL";
-/* Our current OpenCL implementation only supports using exactly one
- * GPU per PP rank, so sharing is impossible */
-static const bool bGpuSharingSupported      = false;
-/* Our current OpenCL implementation seems to handle concurrency
- * correctly with thread-MPI. The AMD OpenCL runtime does not seem to
- * support creating a context from more than one real MPI rank on the
- * same node (it segfaults when you try).
+/* CUDA supports everything. Our current OpenCL implementation seems
+ * to handle concurrency correctly with thread-MPI. The AMD OpenCL
+ * runtime does not seem to support creating a context from more than
+ * one real MPI rank on the same node (it segfaults when you try).
  */
-#    ifdef GMX_THREAD_MPI
-static const bool bMultiGpuPerNodeSupported = true;
-#    else /* GMX_THREAD_MPI */
-/* Real MPI and no MPI */
-static const bool bMultiGpuPerNodeSupported = false;
-#    endif
-
-#  else /* GMX_USE_OPENCL */
-
-// Our CUDA implementation supports everything
-static const char *gpu_implementation        = "CUDA";
-static const bool  bGpuSharingSupported      = true;
-static const bool  bMultiGpuPerNodeSupported = true;
-
-#  endif /* GMX_USE_OPENCL */
-
-#else    /* GMX_GPU */
-
-// Not compiled with GPU support
-static const bool  bGPUBinary                = false;
-static const char *gpu_implementation        = "non-GPU";
-static const bool  bGpuSharingSupported      = false;
-static const bool  bMultiGpuPerNodeSupported = false;
-
-#endif /* GMX_GPU */
+static const bool multiGpuSupport[] = {
+    false, true,
+#ifdef GMX_THREAD_MPI
+    true,
+#else
+    false, /* Real MPI and no MPI */
+#endif
+};
+static const bool bMultiGpuPerNodeSupported = multiGpuSupport[GMX_GPU];
 
 /* Names of the GPU detection/check results (see e_gpu_detect_res_t in hw_info.h). */
 const char * const gpu_detect_res_str[egpuNR] =
@@ -513,7 +499,7 @@ void gmx_check_hw_runconf_consistency(FILE                *fplog,
                         !gmx_multiple_gpu_per_node_supported())
                     {
                         reasonForLimit  = "can be used by ";
-                        reasonForLimit += gpu_implementation;
+                        reasonForLimit += getGpuImplementationString();
                         reasonForLimit += " in GROMACS";
                     }
                     else
@@ -1198,11 +1184,11 @@ void gmx_parse_gpu_ids(gmx_gpu_opt_t *gpu_opt)
                                        &gpu_opt->dev_use);
         if (!gmx_multiple_gpu_per_node_supported() && 1 < gpu_opt->n_dev_use)
         {
-            gmx_fatal(FARGS, "The %s implementation only supports using exactly one PP rank per node", gpu_implementation);
+            gmx_fatal(FARGS, "The %s implementation only supports using exactly one PP rank per node", getGpuImplementationString());
         }
         if (!gmx_gpu_sharing_supported() && anyGpuIdIsRepeated(gpu_opt))
         {
-            gmx_fatal(FARGS, "The %s implementation only supports using exactly one PP rank per GPU", gpu_implementation);
+            gmx_fatal(FARGS, "The %s implementation only supports using exactly one PP rank per GPU", getGpuImplementationString());
         }
         if (gpu_opt->n_dev_use == 0)
         {
index 05060ff2b3f8c97570c0151ba2796b2bf24c0fdb..cc966b3b37ed699932959815621cc3035d6d926b 100644 (file)
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-if(GMX_GPU)
-    if (GMX_USE_OPENCL)
-        file(GLOB GPU_UTILS_SOURCES *ocl*.cpp)
-    else()
-        file(GLOB GPU_UTILS_SOURCES *.cu)
-    endif()
-else()
-    file(GLOB OCL_UTILS_SOURCES *ocl*.cpp)
-    file(GLOB GPU_UTILS_SOURCES *.cpp)
-    list(REMOVE_ITEM GPU_UTILS_SOURCES ${OCL_UTILS_SOURCES})
+file(GLOB GPU_UTILS_SOURCES gpu_utils.cpp)
+if(GMX_USE_OPENCL)
+    file(GLOB GPU_UTILS_SOURCES *ocl*.cpp)
 endif()
+if(GMX_USE_CUDA)
+    file(GLOB GPU_UTILS_SOURCES *.cu)
+endif()
+
 set(GMXLIB_SOURCES ${GMXLIB_SOURCES} ${GPU_UTILS_SOURCES} PARENT_SCOPE)
index 9b3766c2af1b7e006932ca19ec6e2b7a03bf521f..6d72c998ce3d473350b687ad637857817ee1021a 100644 (file)
@@ -67,7 +67,7 @@
 #define OPENCL_FUNC_TERM REAL_FUNC_TERM
 #define OPENCL_FUNC_TERM_WITH_RETURN(arg) REAL_FUNC_TERM_WITH_RETURN(arg)
 
-#elif defined GMX_GPU
+#elif GMX_GPU != GMX_GPU_NONE
 
 /* GPU support is enabled, so these functions will have real code
  * defined somewhere */
@@ -76,7 +76,7 @@
 #define GPU_FUNC_TERM REAL_FUNC_TERM
 #define GPU_FUNC_TERM_WITH_RETURN(arg) REAL_FUNC_TERM_WITH_RETURN(arg)
 
-#  if defined GMX_USE_OPENCL
+#  if GMX_GPU == GMX_GPU_OPENCL
 
 /* OpenCL support is enabled, so CUDA-specific functions need empty
  * implementations, while OpenCL-specific functions will have real
@@ -90,7 +90,8 @@
 #define OPENCL_FUNC_TERM REAL_FUNC_TERM
 #define OPENCL_FUNC_TERM_WITH_RETURN(arg) REAL_FUNC_TERM_WITH_RETURN(arg)
 
-#  else /* !(defined GMX_USE_OPENCL) */
+#  endif
+#  if GMX_GPU == GMX_GPU_CUDA
 
 /* CUDA support is enabled, so OpenCL-specific functions need empty
  * implementations, while CUDA-specific functions will have real
 
 #  endif
 
-#else /* !(defined DOXYGEN) && !(defined GMX_GPU) */
+#elif GMX_GPU == GMX_GPU_NONE
 
 /* No GPU support is configured, so none of these functions will have
  * real definitions. */
index 97660046835cd6c78afa15c3ee3559d760c9581d..406ced76acbb042404cb71ab10dd08e256c88a05 100644 (file)
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-if(GMX_GPU AND GMX_USE_OPENCL)
+if(GMX_USE_OPENCL)
     file(GLOB GMXLIB_OPENCL_SOURCES *.cpp)
     set(GMXLIB_SOURCES ${GMXLIB_SOURCES} ${GMXLIB_OPENCL_SOURCES} PARENT_SCOPE)
 endif()
index b0bf35ad37a36bb44b220958b3c1beedf243e2e3..346a184fe916f99b0aff1876488cd3c584441cea 100644 (file)
 
 file(GLOB MDLIB_SOURCES nbnxn_kernels/simd_4xn/*.cpp nbnxn_kernels/simd_2xnn/*.cpp nbnxn_kernels/*.cpp *.cpp)
 
-if(GMX_GPU AND NOT GMX_USE_OPENCL)
+if(GMX_USE_CUDA)
     add_subdirectory(nbnxn_cuda)
-elseif(GMX_GPU AND GMX_USE_OPENCL)
+endif()
+if(GMX_USE_OPENCL)
     add_subdirectory(nbnxn_ocl)
     set(MDLIB_OPENCL_KERNELS ${MDLIB_OPENCL_KERNELS} PARENT_SCOPE)
 endif()
index ccbecb6806c79f998da349ac785a58961686afa9..216d89761308ceb13dd7d35bbe69d9897c7e4179 100644 (file)
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-if(GMX_GPU AND NOT GMX_USE_OPENCL)
+if(GMX_USE_CUDA)
     file(GLOB CUDA_NB_SOURCES *.cu)
     set(MDLIB_SOURCES ${MDLIB_SOURCES} ${CUDA_NB_SOURCES} PARENT_SCOPE)
 endif()
index 44380f133c1a6255eb85c544d42dc0ce8b22774f..6ce0dad93faed9dbbf7f3fe1b1f5bd1d86879537 100644 (file)
 extern "C" {
 #endif
 
-#ifdef GMX_GPU
-
-#  if defined GMX_USE_OPENCL
-
+#if GMX_GPU == GMX_GPU_OPENCL
 struct gmx_nbnxn_ocl_t;
 typedef struct gmx_nbnxn_ocl_t gmx_nbnxn_gpu_t;
+#endif
 
-#  else
-
+#if GMX_GPU == GMX_GPU_CUDA
 struct gmx_nbnxn_cuda_t;
 typedef struct gmx_nbnxn_cuda_t gmx_nbnxn_gpu_t;
+#endif
 
-#  endif
-
-#else
-
+#if GMX_GPU == GMX_GPU_NONE
 typedef int gmx_nbnxn_gpu_t;
-
 #endif
 
 #ifdef __cplusplus
index 0da18006d0447f4c805ba4f6ceb774bcb5765506..434e708f2619af50ee91784599bd3304fb073664 100644 (file)
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-if(GMX_GPU AND GMX_USE_OPENCL)
+if(GMX_USE_OPENCL)
     file(GLOB OPENCL_NB_SOURCES *.cpp)
     set(MDLIB_SOURCES ${MDLIB_SOURCES} ${OPENCL_NB_SOURCES} PARENT_SCOPE)
     file(GLOB MDLIB_OPENCL_KERNELS *.cl *.clh)
index 27f7dfc749ef81f96f3c15c51e6ba92026526110..e7d3f122c6c98cd7f5ee5f6faeeb699ca00a5681 100644 (file)
 
 #include "nbnxn_gpu.h"
 
-#if defined(GMX_GPU)
-#if defined(GMX_USE_OPENCL)
-// Have OpenCL support
-static const bool useCuda   = false;
-static const bool useOpenCL = true;
-#else
-// Have CUDA support
-static const bool useCuda   = true;
-static const bool useOpenCL = false;
-#endif
-#else
-// No GPU support
-static const bool useCuda   = false;
-static const bool useOpenCL = false;
-#endif
+static const bool useCuda   = GMX_GPU == GMX_GPU_CUDA;
+static const bool useOpenCL = GMX_GPU == GMX_GPU_OPENCL;
 
 void print_time(FILE                     *out,
                 gmx_walltime_accounting_t walltime_accounting,
index 58f46619574625c98981749de188d5c5da1f4950..9a337993b0232a96fd57cc3d0fac7fd5905a0949 100644 (file)
@@ -36,6 +36,8 @@
 
 #include "baseversion.h"
 
+#include "config.h"
+
 #include "baseversion-gen.h"
 
 const char *gmx_version()
@@ -62,3 +64,12 @@ void gmx_is_single_precision()
 {
 }
 #endif
+
+/* Note that this array (and some which follow) must match the "GPU
+ * support enumeration" in src/config.h.cmakein */
+static const char * const gpuImplementationStrings[] = { "disabled", "CUDA", "OpenCL" };
+
+const char *getGpuImplementationString()
+{
+    return gpuImplementationStrings[GMX_GPU];
+}
index 950df601fe5c96c0b0e5e62f0f54980545218c23..c9b6c3012c01f47e5de6d5446421845e03046475 100644 (file)
@@ -72,8 +72,6 @@ const char *gmx_version_git_full_hash(void);
  */
 const char *gmx_version_git_central_base_hash(void);
 
-extern "C" {
-
 /*! \brief
  * Defined if ``libgromacs`` has been compiled in double precision.
  *
@@ -91,8 +89,10 @@ void gmx_is_double_precision();
  *
  * \ingroup module_utility
  */
+
 void gmx_is_single_precision();
 
-}
+/*! \brief Return a string describing what kind of GPU suport was configured in the build. */
+const char *getGpuImplementationString();
 
 #endif
index 3f4bd2656a25f369aefcf6ab2319fa004edce841..5e1726a7ee0668e39cad941a24c97ecb3dec2487 100644 (file)
@@ -218,7 +218,7 @@ SimulationRunner::callMdrun(const CommandLine &callerRef)
     }
 
 #ifdef GMX_MPI
-#  ifdef GMX_GPU
+#  if GMX_GPU != GMX_GPU_NONE
 #    ifdef GMX_THREAD_MPI
     int         numGpusNeeded = g_numThreads;
 #    else   /* Must be real MPI */