Simplified uniform GPU selection in CMake
[alexxy/gromacs.git] / cmake / gmxManageOpenCL.cmake
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 # OpenCL required version: 1.2 or newer
37 set(REQUIRED_OPENCL_MIN_VERSION_MAJOR 1)
38 set(REQUIRED_OPENCL_MIN_VERSION_MINOR 2)
39 set(REQUIRED_OPENCL_MIN_VERSION ${REQUIRED_OPENCL_MIN_VERSION_MAJOR}.${REQUIRED_OPENCL_MIN_VERSION_MINOR})
40
41 set(GMX_GPU_OPENCL ON)
42
43 if(GMX_DOUBLE)
44     message(FATAL_ERROR "OpenCL acceleration is not available in double precision")
45 endif()
46
47 # for some reason FindOpenCL checks CUDA_PATH but not CUDA_HOME
48 set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};$ENV{CUDA_HOME})
49 find_package(OpenCL)
50
51 if (OpenCL_FOUND)
52     if (OpenCL_VERSION_STRING VERSION_LESS REQUIRED_OPENCL_MIN_VERSION)
53         message(FATAL_ERROR "OpenCL " "${OpenCL_VERSION_STRING}" " is not supported. OpenCL version " "${REQUIRED_OPENCL_MIN_VERSION}" " or newer is required.")
54         return ()
55     endif()
56 else ()
57     message(FATAL_ERROR "OpenCL not found.")
58     return()
59 endif()
60
61 # Tell compiler to hide warnings for comments caused by cl_gl_ext.h on Linux
62 if (UNIX)
63     set(OpenCL_DEFINITIONS ${OpenCL_DEFINITIONS} " -Wno-comment")
64 endif()
65
66 # Yes Virginia, Darwin kernel version 14.4 corresponds to OS X 10.4.
67 if(APPLE AND ${CMAKE_SYSTEM_VERSION} VERSION_LESS "14.4")
68         message(WARNING "OS X prior to version 10.10.4 produces incorrect AMD OpenCL code at runtime. You will not be able to use AMD GPUs on this host unless you upgrade your operating system.")
69 endif()
70
71 add_definitions(${OpenCL_DEFINITIONS})
72
73 include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
74
75 # Ensure the OpenCL implementation is 64-bit, because we only support that;
76 # Note that this can only be revised if the cl_mem size assumptions made
77 # (originally in pme-gpu-types.h) are relieved.
78 if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
79     message(FATAL_ERROR "The OpenCL implementation is only supported on 64-bit platforms.")
80 endif()
81
82 set(GMX_OPENCL_NB_CLUSTER_SIZE 8 CACHE STRING "Cluster size used by nonbonded OpenCL kernel. Set to 4 for Intel GPUs.")
83 mark_as_advanced(GMX_OPENCL_NB_CLUSTER_SIZE)
84
85 set(GMX_INSTALL_OCLDIR       ${GMX_INSTALL_GMXDATADIR}/opencl)