Test that nvcc/host compiler combo works
authorErik Lindahl <erik@kth.se>
Fri, 15 Dec 2017 15:16:02 +0000 (16:16 +0100)
committerErik Lindahl <erik.lindahl@gmail.com>
Fri, 5 Jan 2018 15:58:23 +0000 (16:58 +0100)
Compile a trivial CUDA program during CMake time
to catch both unsupported nvcc/host compiler
version combinations and other unknown errors.

Fixes #1616.

Change-Id: I3cc55e4d0db9d6eb01e8a7cd8916cc7a7a1e21fd

cmake/TestCUDA.cu [new file with mode: 0644]
cmake/gmxManageGPU.cmake

diff --git a/cmake/TestCUDA.cu b/cmake/TestCUDA.cu
new file mode 100644 (file)
index 0000000..3ff93c2
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2018, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+__global__ void kernel (void) {}
+
+int
+main()
+{
+    kernel<<< 1, 1>>> ();
+    return 0;
+}
index 42a7a22e29824e9de7c21ab5f984511a89868102..4e10e93eecc6c1989f6abf639226345c5e60871c 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+# Copyright (c) 2012,2013,2014,2015,2016,2017,2018, 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.
@@ -271,6 +271,31 @@ macro(gmx_gpu_setup)
         if(NOT GMX_OPENMP)
             message(WARNING "To use GPU acceleration efficiently, mdrun requires OpenMP multi-threading. Without OpenMP a single CPU core can be used with a GPU which is not optimal. Note that with MPI multiple processes can be forced to use a single GPU, but this is typically inefficient. You need to set both C and C++ compilers that support OpenMP (CC and CXX environment variables, respectively) when using GPUs.")
         endif()
+
+        if(NOT GMX_CLANG_CUDA)
+            gmx_check_if_changed(GMX_CHECK_NVCC CUDA_NVCC_EXECUTABLE CUDA_HOST_COMPILER CUDA_NVCC_FLAGS)
+
+            if(GMX_CHECK_NVCC OR NOT GMX_NVCC_WORKS)
+                message(STATUS "Check for working NVCC/C compiler combination")
+                execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} -ccbin ${CUDA_HOST_COMPILER} -c ${CUDA_NVCC_FLAGS} ${CMAKE_SOURCE_DIR}/cmake/TestCUDA.cu
+                                RESULT_VARIABLE _cuda_test_res
+                                OUTPUT_VARIABLE _cuda_test_out
+                                ERROR_VARIABLE  _cuda_test_err
+                                OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+                if(${_cuda_test_res})
+                    message(STATUS "Check for working NVCC/C compiler combination - broken")
+                    if(${_cuda_test_err} MATCHES "nsupported")
+                        message(FATAL_ERROR "NVCC/C compiler combination does not seem to be supported. CUDA frequently does not support the latest versions of the host compiler, so you might want to try an earlier C/C++ compiler version and make sure your CUDA compiler and driver are as recent as possible.")
+                    else()
+                        message(FATAL_ERROR "CUDA compiler does not seem to be functional.")
+                    endif()
+                elseif(NOT GMX_CUDA_TEST_COMPILER_QUIETLY)
+                    message(STATUS "Check for working NVCC/C compiler combination - works")
+                    set(GMX_NVCC_WORKS TRUE CACHE INTERNAL "Nvcc can compile a trivial test program")
+                endif()
+            endif() # GMX_CHECK_NVCC
+        endif() #GMX_CLANG_CUDA
     endif() # GMX_GPU
 
     if (GMX_CLANG_CUDA)