816928b317bc68257f51e87eec9b5d24275a0d08
[alexxy/gromacs.git] / src / gromacs / mdlib / nbnxn_ocl / 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, 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.
8 #
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.
13 #
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.
18 #
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.
23 #
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.
31 #
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.
34
35 if(GMX_USE_OPENCL)
36     file(GLOB OPENCL_NB_SOURCES *.cpp)
37     set(MDLIB_SOURCES ${MDLIB_SOURCES} ${OPENCL_NB_SOURCES} PARENT_SCOPE)
38     file(GLOB MDLIB_OPENCL_KERNELS *.cl *.clh)
39     set(MDLIB_OPENCL_KERNELS ${MDLIB_OPENCL_KERNELS} PARENT_SCOPE)
40 endif()
41
42 set(ELEC_DEFS
43     "-DEL_CUTOFF\;-DEELNAME=_ElecCut"
44     "-DEL_RF\;-DEELNAME=_ElecRF"
45     "-DEL_EWALD_TAB\;-DEELNAME=_ElecEwQSTab"
46     "-DEL_EWALD_TAB\;-DVDW_CUTOFF_CHECK\;-DEELNAME=_ElecEwQSTabTwinCut"
47     "-DEL_EWALD_ANA\;-DEELNAME=_ElecEw"
48     "-DEL_EWALD_ANA\;-DVDW_CUTOFF_CHECK\;-DEELNAME=_ElecEwTwinCut")
49 set(VDW_DEFS
50     "-DVDWNAME=_VdwLJ"
51     "-DLJ_COMB_GEOM\;-DVDWNAME=_VdwLJCombGeom"
52     "-DLJ_COMB_LB\;-DVDWNAME=_VdwLJCombLB"
53     "-DLJ_FORCE_SWITCH\;-DVDWNAME=_VdwLJFsw"
54     "-DLJ_POT_SWITCH\;-DVDWNAME=_VdwLJPsw"
55     "-DLJ_EWALD_COMB_GEOM\;-DVDWNAME=_VdwLJEwCombGeom"
56     "-DLJ_EWALD_COMB_LB\;-DVDWNAME=_VdwLJEwCombLB")
57 if(CLANG_TIDY_EXE)
58    set(OCL_COMPILER "${CLANG_TIDY_EXE}")
59    set(CLANG_TIDY_ARGS "-quiet;-checks=*,-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 nbnxn_ocl_kernel${ELEC_NAME}${VDW_NAME}_${VENDOR}.o)
74             add_custom_command(OUTPUT ${OBJ_FILE} COMMAND ${OCL_COMPILER}
75                 ${CMAKE_CURRENT_SOURCE_DIR}/nbnxn_ocl_kernels.cl ${CLANG_TIDY_ARGS}
76                 -Xclang -finclude-default-header  -D_${VENDOR}_SOURCE_
77                 -DGMX_OCL_FASTGEN ${ELEC_DEF} ${VDW_DEF}
78                 -DNBNXN_GPU_CLUSTER_SIZE=${CLUSTER_SIZE} -DIATYPE_SHMEM
79                 -c -I ${CMAKE_SOURCE_DIR}/src -std=cl1.2
80                 -Weverything  -Wno-conversion -Wno-missing-variable-declarations -Wno-used-but-marked-unused
81                 -Wno-cast-align -Wno-incompatible-pointer-types
82                 -o${OBJ_FILE}
83                 )
84             list(APPEND NBNXN_OCL_KERNELS ${OBJ_FILE})
85         endforeach()
86     endforeach()
87 endforeach()
88 add_custom_target(ocl_kernel DEPENDS ${NBNXN_OCL_KERNELS})