Simplified uniform GPU selection in CMake
[alexxy/gromacs.git] / src / gromacs / nbnxm / opencl / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013,2014,2015,2018 by the GROMACS development team.
5 # Copyright (c) 2019,2020, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
9 #
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
14 #
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24 #
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
32 #
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
35
36 if(GMX_GPU_OPENCL)
37     file(GLOB OPENCL_NB_SOURCES *.cpp)
38     set(NBNXM_SOURCES ${NBNXM_SOURCES} ${OPENCL_NB_SOURCES} PARENT_SCOPE)
39 endif()
40
41 set(ELEC_DEFS
42     "-DEL_CUTOFF\;-DEELNAME=_ElecCut"
43     "-DEL_RF\;-DEELNAME=_ElecRF"
44     "-DEL_EWALD_TAB\;-DEELNAME=_ElecEwQSTab"
45     "-DEL_EWALD_TAB\;-DVDW_CUTOFF_CHECK\;-DEELNAME=_ElecEwQSTabTwinCut"
46     "-DEL_EWALD_ANA\;-DEELNAME=_ElecEw"
47     "-DEL_EWALD_ANA\;-DVDW_CUTOFF_CHECK\;-DEELNAME=_ElecEwTwinCut")
48 set(VDW_DEFS
49     "-DVDWNAME=_VdwLJ"
50     "-DLJ_COMB_GEOM\;-DVDWNAME=_VdwLJCombGeom"
51     "-DLJ_COMB_LB\;-DVDWNAME=_VdwLJCombLB"
52     "-DLJ_FORCE_SWITCH\;-DVDWNAME=_VdwLJFsw"
53     "-DLJ_POT_SWITCH\;-DVDWNAME=_VdwLJPsw"
54     "-DLJ_EWALD_COMB_GEOM\;-DVDWNAME=_VdwLJEwCombGeom"
55     "-DLJ_EWALD_COMB_LB\;-DVDWNAME=_VdwLJEwCombLB")
56 if(CLANG_TIDY_EXE)
57    set(OCL_COMPILER "${CLANG_TIDY_EXE}")
58    # TODO: remove readability-isolate-declaration when the nbnxm OpenCL kernels get modernized
59    set(CLANG_TIDY_ARGS "-quiet;-checks=*,-readability-isolate-declaration,-readability-implicit-bool-conversion,-llvm-header-guard,-hicpp-signed-bitwise,-clang-analyzer-deadcode.DeadStores,-google-readability-todo;--;${CMAKE_C_COMPILER}")
60 else()
61    set(OCL_COMPILER "${CMAKE_C_COMPILER}")
62 endif()
63 foreach(ELEC_DEF IN LISTS ELEC_DEFS)
64     foreach(VDW_DEF IN LISTS VDW_DEFS)
65         foreach(VENDOR AMD NVIDIA INTEL)
66             if(VENDOR STREQUAL INTEL)
67                set(CLUSTER_SIZE 4)
68             else()
69                set(CLUSTER_SIZE 8)
70             endif()
71             string(REGEX REPLACE ".*=" "" ELEC_NAME "${ELEC_DEF}")
72             string(REGEX REPLACE ".*=" "" VDW_NAME "${VDW_DEF}")
73             set(OBJ_FILE nbnxm_ocl_kernel${ELEC_NAME}${VDW_NAME}_${VENDOR}.o)
74             # The constants below duplicate various others (e.g. from pairlist.h)
75             # but as the kernels compiled here are not used for production,
76             # it will be OK if the values would fall out of sync.
77             add_custom_command(OUTPUT ${OBJ_FILE} COMMAND ${OCL_COMPILER}
78                 ${CMAKE_CURRENT_SOURCE_DIR}/nbnxm_ocl_kernels.cl ${CLANG_TIDY_ARGS}
79                 -Xclang -finclude-default-header  -D_${VENDOR}_SOURCE_
80                 -DGMX_OCL_FASTGEN ${ELEC_DEF} ${VDW_DEF}
81                 -Dc_nbnxnGpuClusterSize=${CLUSTER_SIZE}
82                 -Dc_nbnxnMinDistanceSquared=3.82e-07F
83                 -Dc_nbnxnGpuNumClusterPerSupercluster=8
84                 -Dc_nbnxnGpuJgroupSize=4
85                 -DIATYPE_SHMEM
86                 -c -I ${CMAKE_SOURCE_DIR}/src -std=cl1.2
87                 -Weverything  -Wno-conversion -Wno-missing-variable-declarations -Wno-used-but-marked-unused
88                 -Wno-cast-align -Wno-incompatible-pointer-types
89                 -o${OBJ_FILE}
90                 )
91             list(APPEND NBNXM_OCL_KERNELS ${OBJ_FILE})
92         endforeach()
93     endforeach()
94 endforeach()
95 add_custom_target(ocl_nbnxm_kernels DEPENDS ${NBNXM_OCL_KERNELS})