Remove cycle suppression
[gromacs.git] / cmake / FindNVML.cmake
blobc0610ffd48b34d9e6e0c00b41cd643441b0558f4
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2014,2015,2017, 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.
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.
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.
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.
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.
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.
35 #.rst:
36 # FindNVML
37 # --------
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
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.
46 # FindNVML defines the following variables:
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.
53 #   Jiri Kraus, NVIDIA Corp (nvidia.com - jkraus)
55 #   Copyright (c) 2008 - 2014,2017 NVIDIA Corporation.  All rights reserved.
57 #   This code is licensed under the MIT License.  See the FindNVML.cmake script
58 #   for the text of the license.
60 # The MIT License
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:
70 # The above copyright notice and this permission notice shall be included
71 # in all copies or substantial portions of the Software.
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.
81 ###############################################################################
83 if( CMAKE_SYSTEM_NAME STREQUAL "Windows"  )
84   set(NVML_NAMES nvml)
85   if(${CUDA_VERSION_STRING} VERSION_LESS "8.0")
86       set( NVML_LIB_PATHS "C:/Program Files/NVIDIA Corporation/GDK/nvml/lib" )
87       if(GPU_DEPLOYMENT_KIT_ROOT_DIR)
88         list(APPEND NVML_LIB_PATHS "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/nvml/lib")
89       endif()
91       set( NVML_INC_PATHS "C:/Program Files/NVIDIA Corporation/GDK/nvml/include" )
92       if(GPU_DEPLOYMENT_KIT_ROOT_DIR)
93         list(APPEND NVML_INC_PATHS "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/nvml/include")
94       endif()
95   else()
96     set( NVML_LIB_PATHS "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64" )
97     set( NVML_INC_PATHS ${CUDA_INCLUDE_DIRS} )
98   endif()
99 else()
100   set(NVML_NAMES nvidia-ml)
102   set( NVML_LIB_PATHS /usr/lib64 )
103   if(${CUDA_VERSION_STRING} VERSION_LESS "8.0")
104       # The Linux installer for the GPU Deployment Kit adds a "usr"
105       # suffix to a custom path if one is used, so a user could
106       # reasonably set GPU_DEPLOYMENT_KIT_ROOT_DIR to the value they
107       # passed to the installer, or the root where they later found the
108       # kit to be installed. Below, we cater for both possibilities.
109       if(GPU_DEPLOYMENT_KIT_ROOT_DIR)
110           list(APPEND NVML_LIB_PATHS
111               "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/src/gdk/nvml/lib"
112               "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/usr/src/gdk/nvml/lib"
113               )
114       endif()
115   else()
116      list(APPEND NVML_LIB_PATHS "${CUDA_TOOLKIT_ROOT_DIR}/lib64/stubs")
117   endif()
119   if(${CUDA_VERSION_STRING} VERSION_LESS "8.0")
120       set( NVML_INC_PATHS /usr/include/nvidia/gdk/ /usr/include )
121       if(GPU_DEPLOYMENT_KIT_ROOT_DIR)
122           list(APPEND NVML_INC_PATHS
123               "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/include/nvidia/gdk"
124               "${GPU_DEPLOYMENT_KIT_ROOT_DIR}/usr/include/nvidia/gdk"
125               )
126       endif()
127   else()
128     set( NVML_INC_PATHS ${CUDA_INCLUDE_DIRS} )
129   endif()
130 endif()
132 find_library(NVML_LIBRARY NAMES ${NVML_NAMES} PATHS ${NVML_LIB_PATHS} )
134 find_path(NVML_INCLUDE_DIR nvml.h PATHS ${NVML_INC_PATHS})
136 # handle the QUIETLY and REQUIRED arguments and set NVML_FOUND to TRUE if
137 # all listed variables are TRUE
138 include(FindPackageHandleStandardArgs)
139 FIND_PACKAGE_HANDLE_STANDARD_ARGS(NVML DEFAULT_MSG NVML_LIBRARY NVML_INCLUDE_DIR)
141 mark_as_advanced(NVML_LIBRARY NVML_INCLUDE_DIR)