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)
commit3451072fd7d5c0266703913430e81abaffc5250c
treef3cc63fee92442849b84422c130013ad0ade670b
parent82d6fc0f2f38b22451b7dfc486ad9b9395190d20
Update use of preprocessor in managing GPU support

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