Fix OpenCL mdrun from installed path
[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 endif()
39
40 set(ELEC_DEFS
41     "-DEL_CUTOFF\;-DEELNAME=_ElecCut"
42     "-DEL_RF\;-DEELNAME=_ElecRF"
43     "-DEL_EWALD_TAB\;-DEELNAME=_ElecEwQSTab"
44     "-DEL_EWALD_TAB\;-DVDW_CUTOFF_CHECK\;-DEELNAME=_ElecEwQSTabTwinCut"
45     "-DEL_EWALD_ANA\;-DEELNAME=_ElecEw"
46     "-DEL_EWALD_ANA\;-DVDW_CUTOFF_CHECK\;-DEELNAME=_ElecEwTwinCut")
47 set(VDW_DEFS
48     "-DVDWNAME=_VdwLJ"
49     "-DLJ_COMB_GEOM\;-DVDWNAME=_VdwLJCombGeom"
50     "-DLJ_COMB_LB\;-DVDWNAME=_VdwLJCombLB"
51     "-DLJ_FORCE_SWITCH\;-DVDWNAME=_VdwLJFsw"
52     "-DLJ_POT_SWITCH\;-DVDWNAME=_VdwLJPsw"
53     "-DLJ_EWALD_COMB_GEOM\;-DVDWNAME=_VdwLJEwCombGeom"
54     "-DLJ_EWALD_COMB_LB\;-DVDWNAME=_VdwLJEwCombLB")
55 if(CLANG_TIDY_EXE)
56    set(OCL_COMPILER "${CLANG_TIDY_EXE}")
57    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}")
58 else()
59    set(OCL_COMPILER "${CMAKE_C_COMPILER}")
60 endif()
61 foreach(ELEC_DEF IN LISTS ELEC_DEFS)
62     foreach(VDW_DEF IN LISTS VDW_DEFS)
63         foreach(VENDOR AMD NVIDIA INTEL)
64             if(VENDOR STREQUAL INTEL)
65                set(CLUSTER_SIZE 4)
66             else()
67                set(CLUSTER_SIZE 8)
68             endif()
69             string(REGEX REPLACE ".*=" "" ELEC_NAME "${ELEC_DEF}")
70             string(REGEX REPLACE ".*=" "" VDW_NAME "${VDW_DEF}")
71             set(OBJ_FILE nbnxn_ocl_kernel${ELEC_NAME}${VDW_NAME}_${VENDOR}.o)
72             add_custom_command(OUTPUT ${OBJ_FILE} COMMAND ${OCL_COMPILER}
73                 ${CMAKE_CURRENT_SOURCE_DIR}/nbnxn_ocl_kernels.cl ${CLANG_TIDY_ARGS}
74                 -Xclang -finclude-default-header  -D_${VENDOR}_SOURCE_
75                 -DGMX_OCL_FASTGEN ${ELEC_DEF} ${VDW_DEF}
76                 -DNBNXN_GPU_CLUSTER_SIZE=${CLUSTER_SIZE} -DIATYPE_SHMEM
77                 -c -I ${CMAKE_SOURCE_DIR}/src -std=cl1.2
78                 -Weverything  -Wno-conversion -Wno-missing-variable-declarations -Wno-used-but-marked-unused
79                 -Wno-cast-align -Wno-incompatible-pointer-types
80                 -o${OBJ_FILE}
81                 )
82             list(APPEND NBNXN_OCL_KERNELS ${OBJ_FILE})
83         endforeach()
84     endforeach()
85 endforeach()
86 add_custom_target(ocl_kernel DEPENDS ${NBNXN_OCL_KERNELS})