mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-28 03:10:57 +08:00
104 lines
4.7 KiB
CMake
104 lines
4.7 KiB
CMake
# Distributed under the OSI-approved BSD 3-Clause License.
|
|
|
|
#.rst:
|
|
# FindCUDNN
|
|
# --------
|
|
#
|
|
# Result Variables
|
|
# ^^^^^^^^^^^^^^^^
|
|
#
|
|
# This module will set the following variables in your project::
|
|
#
|
|
# ``CUDNN_FOUND``
|
|
# True if CUDNN found on the local system
|
|
#
|
|
# ``CUDNN_INCLUDE_DIRS``
|
|
# Location of CUDNN header files.
|
|
#
|
|
# ``CUDNN_LIBRARIES``
|
|
# The CUDNN libraries.
|
|
#
|
|
# ``CuDNN::CuDNN``
|
|
# The CUDNN target
|
|
#
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
find_path(CUDNN_INCLUDE_DIR NAMES cudnn.h cudnn_v8.h cudnn_v7.h
|
|
HINTS ${CUDA_TOOLKIT_ROOT} $ENV{CUDA_PATH} $ENV{CUDA_TOOLKIT_ROOT_DIR} $ENV{cudnn} $ENV{CUDNN} $ENV{CUDNN_ROOT_DIR} $ENV{CUDA_PATH}/../../../NVIDIA/CUDNN/v9.0 $ENV{CUDA_PATH}/../../../NVIDIA/CUDNN/v9.1 $ENV{CUDA_PATH}/../../../NVIDIA/CUDNN/v9.2 $ENV{CUDA_PATH}/../../../NVIDIA/CUDNN/v9.3 /usr/include /usr/include/x86_64-linux-gnu/ /usr/include/aarch64-linux-gnu/
|
|
PATH_SUFFIXES cuda/include include include/11.8 include/12.0 include/12.1 include/12.2 include/12.3 include/12.4 include/12.5 include/12.6)
|
|
find_library(CUDNN_LIBRARY NAMES cudnn cudnn8 cudnn7
|
|
HINTS ${CUDA_TOOLKIT_ROOT} $ENV{CUDA_PATH} $ENV{CUDA_TOOLKIT_ROOT_DIR} $ENV{cudnn} $ENV{CUDNN} $ENV{CUDNN_ROOT_DIR} $ENV{CUDA_PATH}/../../../NVIDIA/CUDNN/v9.0 $ENV{CUDA_PATH}/../../../NVIDIA/CUDNN/v9.1 $ENV{CUDA_PATH}/../../../NVIDIA/CUDNN/v9.2 $ENV{CUDA_PATH}/../../../NVIDIA/CUDNN/v9.3 /usr/lib/x86_64-linux-gnu/ /usr/include/aarch64-linux-gnu/ /usr/
|
|
PATH_SUFFIXES lib lib64 cuda/lib cuda/lib64 lib/x64 cuda/lib/x64 lib/11.8/x64 lib/12.0/x64 lib/12.1/x64 lib/12.2/x64 lib/12.3/x64 lib/12.4/x64 lib/12.5/x64 lib/12.6/x64)
|
|
|
|
if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn.h")
|
|
file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_HEADER_CONTENTS)
|
|
elseif(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_v8.h")
|
|
file(READ ${CUDNN_INCLUDE_DIR}/cudnn_v8.h CUDNN_HEADER_CONTENTS)
|
|
elseif(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_v7.h")
|
|
file(READ ${CUDNN_INCLUDE_DIR}/cudnn_v7.h CUDNN_HEADER_CONTENTS)
|
|
endif()
|
|
if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_version.h")
|
|
file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version.h" CUDNN_VERSION_H_CONTENTS)
|
|
string(APPEND CUDNN_HEADER_CONTENTS "${CUDNN_VERSION_H_CONTENTS}")
|
|
unset(CUDNN_VERSION_H_CONTENTS)
|
|
elseif(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_version_v8.h")
|
|
file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version_v8.h" CUDNN_VERSION_H_CONTENTS)
|
|
string(APPEND CUDNN_HEADER_CONTENTS "${CUDNN_VERSION_H_CONTENTS}")
|
|
unset(CUDNN_VERSION_H_CONTENTS)
|
|
elseif(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_version_v7.h")
|
|
file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version_v7.h" CUDNN_VERSION_H_CONTENTS)
|
|
string(APPEND CUDNN_HEADER_CONTENTS "${CUDNN_VERSION_H_CONTENTS}")
|
|
unset(CUDNN_VERSION_H_CONTENTS)
|
|
endif()
|
|
if(CUDNN_HEADER_CONTENTS)
|
|
string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)"
|
|
_CUDNN_VERSION_MAJOR "${CUDNN_HEADER_CONTENTS}")
|
|
string(REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1"
|
|
_CUDNN_VERSION_MAJOR "${_CUDNN_VERSION_MAJOR}")
|
|
string(REGEX MATCH "define CUDNN_MINOR * +([0-9]+)"
|
|
_CUDNN_VERSION_MINOR "${CUDNN_HEADER_CONTENTS}")
|
|
string(REGEX REPLACE "define CUDNN_MINOR * +([0-9]+)" "\\1"
|
|
_CUDNN_VERSION_MINOR "${_CUDNN_VERSION_MINOR}")
|
|
string(REGEX MATCH "define CUDNN_PATCHLEVEL * +([0-9]+)"
|
|
_CUDNN_VERSION_PATCH "${CUDNN_HEADER_CONTENTS}")
|
|
string(REGEX REPLACE "define CUDNN_PATCHLEVEL * +([0-9]+)" "\\1"
|
|
_CUDNN_VERSION_PATCH "${_CUDNN_VERSION_PATCH}")
|
|
if(NOT _CUDNN_VERSION_MAJOR)
|
|
set(_CUDNN_VERSION "?")
|
|
else()
|
|
set(_CUDNN_VERSION "${_CUDNN_VERSION_MAJOR}.${_CUDNN_VERSION_MINOR}.${_CUDNN_VERSION_PATCH}")
|
|
endif()
|
|
endif()
|
|
|
|
set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR})
|
|
set(CUDNN_LIBRARIES ${CUDNN_LIBRARY})
|
|
mark_as_advanced(CUDNN_LIBRARY CUDNN_INCLUDE_DIR)
|
|
|
|
find_package_handle_standard_args(CUDNN
|
|
REQUIRED_VARS CUDNN_INCLUDE_DIR CUDNN_LIBRARY
|
|
VERSION_VAR CUDNN_VERSION
|
|
)
|
|
|
|
if(WIN32)
|
|
set(CUDNN_DLL_DIR ${CUDNN_INCLUDE_DIR})
|
|
list(TRANSFORM CUDNN_DLL_DIR APPEND "/../bin")
|
|
find_file(CUDNN_LIBRARY_DLL NAMES cudnn64_${CUDNN_VERSION_MAJOR}.dll PATHS ${CUDNN_DLL_DIR})
|
|
endif()
|
|
|
|
if( CUDNN_FOUND AND NOT TARGET CuDNN::CuDNN )
|
|
if( EXISTS "${CUDNN_LIBRARY_DLL}" )
|
|
add_library( CuDNN::CuDNN SHARED IMPORTED )
|
|
set_target_properties( CuDNN::CuDNN PROPERTIES
|
|
IMPORTED_LOCATION "${CUDNN_LIBRARY_DLL}"
|
|
IMPORTED_IMPLIB "${CUDNN_LIBRARY}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${CUDNN_INCLUDE_DIR}"
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C" )
|
|
else()
|
|
add_library( CuDNN::CuDNN UNKNOWN IMPORTED )
|
|
set_target_properties( CuDNN::CuDNN PROPERTIES
|
|
IMPORTED_LOCATION "${CUDNN_LIBRARY}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${CUDNN_INCLUDE_DIR}"
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C" )
|
|
endif()
|
|
endif()
|