2019-02-15 00:37:12 +08:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License.
|
|
|
|
# Copyright Stefano Sinigardi
|
|
|
|
|
|
|
|
#.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.
|
|
|
|
#
|
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
|
2019-02-18 06:56:25 +08:00
|
|
|
if(NOT CUDNN_INCLUDE_DIR)
|
|
|
|
find_path(CUDNN_INCLUDE_DIR cudnn.h
|
2019-02-22 16:14:41 +08:00
|
|
|
HINTS ${CUDA_HOME} ${CUDA_TOOLKIT_ROOT_DIR} $ENV{cudnn} $ENV{CUDNN}
|
2019-02-15 00:37:12 +08:00
|
|
|
PATH_SUFFIXES cuda/include include)
|
2019-02-18 06:56:25 +08:00
|
|
|
endif()
|
2019-02-15 00:37:12 +08:00
|
|
|
|
2019-02-18 06:56:25 +08:00
|
|
|
if(NOT CUDNN_LIBRARY)
|
|
|
|
find_library(CUDNN_LIBRARY cudnn
|
2019-02-22 16:14:41 +08:00
|
|
|
HINTS ${CUDA_HOME} ${CUDA_TOOLKIT_ROOT_DIR} $ENV{cudnn} $ENV{CUDNN}
|
2019-02-15 00:37:12 +08:00
|
|
|
PATH_SUFFIXES lib lib64 cuda/lib cuda/lib64 lib/x64)
|
2019-02-18 06:56:25 +08:00
|
|
|
endif()
|
2019-02-15 00:37:12 +08:00
|
|
|
|
2019-08-24 19:46:45 +08:00
|
|
|
if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn.h")
|
2019-02-15 00:37:12 +08:00
|
|
|
file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h 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()
|
2019-03-04 22:15:19 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR})
|
|
|
|
set(CUDNN_LIBRARIES ${CUDNN_LIBRARY})
|
2019-04-18 15:17:31 +08:00
|
|
|
mark_as_advanced(CUDNN_LIBRARY CUDNN_INCLUDE_DIR)
|
2019-02-15 00:37:12 +08:00
|
|
|
|
2019-08-24 19:46:45 +08:00
|
|
|
find_package_handle_standard_args(CUDNN
|
|
|
|
REQUIRED_VARS CUDNN_INCLUDE_DIR CUDNN_LIBRARY
|
|
|
|
VERSION_VAR CUDNN_VERSION
|
|
|
|
)
|
|
|
|
|
2019-03-04 22:15:19 +08:00
|
|
|
if(WIN32)
|
2019-08-01 19:39:45 +08:00
|
|
|
set(CUDNN_DLL_DIR ${CUDNN_INCLUDE_DIR})
|
|
|
|
list(TRANSFORM CUDNN_DLL_DIR APPEND "/../bin")
|
2019-08-24 19:46:45 +08:00
|
|
|
find_file(CUDNN_LIBRARY_DLL NAMES cudnn64_${CUDNN_VERSION_MAJOR}.dll PATHS ${CUDNN_DLL_DIR})
|
2019-03-04 22:15:19 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if( CUDNN_FOUND AND NOT TARGET CuDNN::CuDNN )
|
2019-04-18 15:17:31 +08:00
|
|
|
if( EXISTS "${CUDNN_LIBRARY_DLL}" )
|
2019-03-04 22:15:19 +08:00
|
|
|
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()
|
2019-02-15 00:37:12 +08:00
|
|
|
endif()
|