Remove cycle suppression
[gromacs.git] / cmake / gmxManageClangCudaConfig.cmake
blob40a492b0024672bba3b25911124078c18a2f89de
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2017, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 function (gmx_test_clang_cuda_support)
37     if ((NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR
38         (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.9"))
39         message(FATAL_ERROR "clang 3.9 or later required with GMX_CLANG_CUDA=ON!")
40     endif()
42     # NOTE: we'd ideally like to use a compile check here, but the link-stage
43     # fails as the clang invocation generated seems to not handle well some
44     # (GPU code) in the object file generated during compilation.
45     # SET(CMAKE_REQUIRED_FLAGS ${FLAGS})
46     # SET(CMAKE_REQUIRED_LIBRARIES ${LIBS})
47     # CHECK_CXX_SOURCE_COMPILES("int main() { int c; cudaGetDeviceCount(&c); return 0; }" _CLANG_CUDA_COMPILES)
48 endfunction ()
51 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0" AND
52     NOT CUDA_VERSION VERSION_LESS "8.0")
53     message(FATAL_ERROR "clang ${CMAKE_CXX_COMPILER_VERSION} for CUDA is only compatible with CUDA version <8.0")
54 endif()
56 if (GMX_CUDA_TARGET_COMPUTE)
57     message(WARNING "Values passed in GMX_CUDA_TARGET_COMPUTE will be ignored; clang will by default include PTX in the binary.")
58 endif()
60 if (GMX_CUDA_TARGET_SM)
61     set(_CUDA_CLANG_GENCODE_FLAGS)
62     set(_target_sm_list ${GMX_CUDA_TARGET_SM})
63     foreach(_target ${_target_sm_list})
64         list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_${_target}")
65     endforeach()
66 else()
67     list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_20")
68     list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_30")
69     list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_35")
70     list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_37")
71     list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_50")
72     list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_52")
73     if (NOT CUDA_VERSION VERSION_LESS 8.0)
74         list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_60")
75         list(APPEND _CUDA_CLANG_GENCODE_FLAGS "--cuda-gpu-arch=sm_61")
76     endif()
77     # TODO: test CUDA 9.0 and figure out which clang releases support it
78     #       and the sm_70 arch.
79 endif()
80 if (GMX_CUDA_TARGET_SM)
81     set_property(CACHE GMX_CUDA_TARGET_SM PROPERTY HELPSTRING "List of CUDA GPU architecture codes to compile for (without the sm_ prefix)")
82     set_property(CACHE GMX_CUDA_TARGET_SM PROPERTY TYPE STRING)
83 endif()
85 # default flags
86 list(APPEND _CUDA_CLANG_FLAGS "-x cuda" "-ffast-math")
87 # CUDA toolkit
88 list(APPEND _CUDA_CLANG_FLAGS "--cuda-path=${CUDA_TOOLKIT_ROOT_DIR}")
89 # codegen flags
90 list(APPEND _CUDA_CLANG_FLAGS "${_CUDA_CLANG_GENCODE_FLAGS}")
91 foreach(_flag ${_CUDA_CLANG_FLAGS})
92     set(GMX_CUDA_CLANG_FLAGS "${GMX_CUDA_CLANG_FLAGS} ${_flag}")
93 endforeach()
95 if (CUDA_USE_STATIC_CUDA_RUNTIME)
96     set(GMX_CUDA_CLANG_LINK_LIBS "cudart_static")
97 else()
98     set(GMX_CUDA_CLANG_LINK_LIBS "cudart")
99 endif()
100 set(GMX_CUDA_CLANG_LINK_LIBS "${GMX_CUDA_CLANG_LINK_LIBS}" "dl" "rt")
101 if (CUDA_64_BIT_DEVICE_CODE)
102     set(GMX_CUDA_CLANG_LINK_DIRS "${CUDA_TOOLKIT_ROOT_DIR}/lib64")
103 else()
104     set(GMX_CUDA_CLANG_LINK_DIRS "${CUDA_TOOLKIT_ROOT_DIR}/lib")
105 endif()
107 gmx_test_clang_cuda_support()