Fix constraints cycle counting
[alexxy/gromacs.git] / cmake / FindNVML.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2014,2015,2017,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 #.rst:
36 # FindNVML
37 # --------
38 #
39 # Find the NVIDIA Management Library (NVML) includes and library. NVML documentation
40 # is available at: http://docs.nvidia.com/deploy/nvml-api/index.html
41 #
42 # Starting with CUDA 8 NVML is part of the CUDA Toolkit. Prior to CUDA 8 NVML was part
43 # of the GPU Deployment Kit (GDK) and GPU_DEPLOYMENT_KIT_ROOT_DIR can be specified
44 # if the GPU Deployment Kit is not installed in a default location.
45 #
46 # FindNVML defines the following variables:
47 #
48 #   NVML_INCLUDE_DIR, where to find nvml.h, etc.
49 #   NVML_LIBRARY, the libraries needed to use NVML.
50 #   NVML_FOUND, If false, do not try to use NVML.
51 #
52
53 #   Jiri Kraus, NVIDIA Corp (nvidia.com - jkraus)
54 #
55 #   Copyright (c) 2008 - 2014,2017 NVIDIA Corporation.  All rights reserved.
56 #
57 #   This code is licensed under the MIT License.  See the FindNVML.cmake script
58 #   for the text of the license.
59
60 # The MIT License
61 #
62 # License for the specific language governing rights and limitations under
63 # Permission is hereby granted, free of charge, to any person obtaining a
64 # copy of this software and associated documentation files (the "Software"),
65 # to deal in the Software without restriction, including without limitation
66 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
67 # and/or sell copies of the Software, and to permit persons to whom the
68 # Software is furnished to do so, subject to the following conditions:
69 #
70 # The above copyright notice and this permission notice shall be included
71 # in all copies or substantial portions of the Software.
72 #
73 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
74 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
75 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
76 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
77 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
78 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
79 # DEALINGS IN THE SOFTWARE.
80 #
81 ###############################################################################
82
83 if( CMAKE_SYSTEM_NAME STREQUAL "Windows"  )
84     set(NVML_NAMES nvml)
85 else()
86     set(NVML_NAMES nvidia-ml)
87 endif()
88
89 if (CUDA_FOUND)
90     if( CMAKE_SYSTEM_NAME STREQUAL "Windows"  )
91         if(${CUDA_VERSION_STRING} VERSION_LESS "8.0")
92             set( NVML_LIB_PATHS "C:/Program Files/NVIDIA Corporation/GDK/nvml/lib" )
93             if(GPU_DEPLOYMENT_KIT_ROOT_DIR)
94                 list(APPEND NVML_LIB_PATHS "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/nvml/lib")
95             endif()
96
97             set( NVML_INC_PATHS "C:/Program Files/NVIDIA Corporation/GDK/nvml/include" )
98             if(GPU_DEPLOYMENT_KIT_ROOT_DIR)
99                 list(APPEND NVML_INC_PATHS "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/nvml/include")
100             endif()
101         else()
102             set( NVML_LIB_PATHS "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64" )
103             set( NVML_INC_PATHS ${CUDA_INCLUDE_DIRS} )
104         endif()
105     else()
106
107         set( NVML_LIB_PATHS /usr/lib64 )
108         if(${CUDA_VERSION_STRING} VERSION_LESS "8.0")
109             # The Linux installer for the GPU Deployment Kit adds a "usr"
110             # suffix to a custom path if one is used, so a user could
111             # reasonably set GPU_DEPLOYMENT_KIT_ROOT_DIR to the value they
112             # passed to the installer, or the root where they later found the
113             # kit to be installed. Below, we cater for both possibilities.
114             if(GPU_DEPLOYMENT_KIT_ROOT_DIR)
115                 list(APPEND NVML_LIB_PATHS
116                     "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/src/gdk/nvml/lib"
117                     "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/usr/src/gdk/nvml/lib"
118                     )
119             endif()
120         else()
121             list(APPEND NVML_LIB_PATHS "${CUDA_TOOLKIT_ROOT_DIR}/lib64/stubs")
122         endif()
123
124         if(${CUDA_VERSION_STRING} VERSION_LESS "8.0")
125             set( NVML_INC_PATHS /usr/include/nvidia/gdk/ /usr/include )
126             if(GPU_DEPLOYMENT_KIT_ROOT_DIR)
127                 list(APPEND NVML_INC_PATHS
128                     "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/include/nvidia/gdk"
129                     "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/usr/include/nvidia/gdk"
130                     )
131             endif()
132         else()
133             set( NVML_INC_PATHS ${CUDA_INCLUDE_DIRS} )
134         endif()
135     endif()
136 endif()
137
138 find_library(NVML_LIBRARY NAMES ${NVML_NAMES} PATHS ${NVML_LIB_PATHS} )
139
140 find_path(NVML_INCLUDE_DIR nvml.h PATHS ${NVML_INC_PATHS})
141
142 # handle the QUIETLY and REQUIRED arguments and set NVML_FOUND to TRUE if
143 # all listed variables are TRUE
144 include(FindPackageHandleStandardArgs)
145 FIND_PACKAGE_HANDLE_STANDARD_ARGS(NVML DEFAULT_MSG NVML_LIBRARY NVML_INCLUDE_DIR)
146
147 mark_as_advanced(NVML_LIBRARY NVML_INCLUDE_DIR)