2019-09-25 03:58:38 +08:00
if ( VCPKG_TARGET_IS_UWP OR VCPKG_TARGET_IS_OSX )
message ( FATAL_ERROR "This port is only for Windows Desktop or Linux" )
endif ( )
if ( NOT VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" )
message ( FATAL_ERROR "This port is only for x64 architectures" )
endif ( )
vcpkg_check_linkage ( ONLY_DYNAMIC_LIBRARY ONLY_DYNAMIC_CRT )
2021-04-14 06:15:32 +08:00
set ( MINIMUM_CUDNN_VERSION "7.6.5" )
2019-09-25 03:58:38 +08:00
2021-04-20 02:22:14 +08:00
include ( ${ CURRENT_INSTALLED_DIR } /share/cuda/vcpkg_find_cuda.cmake )
vcpkg_find_cuda ( OUT_CUDA_TOOLKIT_ROOT CUDA_TOOLKIT_ROOT OUT_CUDA_VERSION CUDA_VERSION )
2020-11-24 07:25:27 +08:00
# Try to find CUDNN if it exists; only download if it doesn't exist
2021-04-14 06:15:32 +08:00
find_path ( CUDNN_INCLUDE_DIR NAMES cudnn.h cudnn_v8.h cudnn_v7.h
2021-04-20 02:22:14 +08:00
H I N T S $ { C U D A _ T O O L K I T _ R O O T } $ E N V { C U D A _ P A T H } $ E N V { C U D A _ T O O L K I T _ R O O T _ D I R } $ E N V { c u d n n } $ E N V { C U D N N } $ E N V { C U D N N _ R O O T _ D I R } / u s r / i n c l u d e
2020-11-24 07:25:27 +08:00
P A T H _ S U F F I X E S c u d a / i n c l u d e i n c l u d e )
2021-04-20 02:22:14 +08:00
message ( STATUS "CUDNN_INCLUDE_DIR: ${CUDNN_INCLUDE_DIR}" )
2021-04-14 06:15:32 +08:00
find_library ( CUDNN_LIBRARY NAMES cudnn cudnn8 cudnn7
2021-04-20 02:22:14 +08:00
H I N T S $ { C U D A _ T O O L K I T _ R O O T } $ E N V { C U D A _ P A T H } $ E N V { C U D A _ T O O L K I T _ R O O T _ D I R } $ E N V { c u d n n } $ E N V { C U D N N } $ E N V { C U D N N _ R O O T _ D I R } / u s r / l i b / x 8 6 _ 6 4 - l i n u x - g n u /
2021-05-25 06:41:57 +08:00
P A T H _ S U F F I X E S l i b l i b 6 4 c u d a / l i b c u d a / l i b 6 4 l i b / x 6 4 c u d a / l i b / x 6 4 )
2021-04-20 02:22:14 +08:00
message ( STATUS "CUDNN_LIBRARY: ${CUDNN_LIBRARY}" )
2020-11-24 07:25:27 +08:00
if ( EXISTS "${CUDNN_INCLUDE_DIR}/cudnn.h" )
file ( READ ${ CUDNN_INCLUDE_DIR } /cudnn.h CUDNN_HEADER_CONTENTS )
2021-04-14 06:15:32 +08:00
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]+)"
_ C U D N N _ V E R S I O N _ M A J O R " $ { C U D N N _ H E A D E R _ C O N T E N T S } " )
string ( REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1"
_ C U D N N _ V E R S I O N _ M A J O R " $ { _ C U D N N _ V E R S I O N _ M A J O R } " )
string ( REGEX MATCH "define CUDNN_MINOR * +([0-9]+)"
_ C U D N N _ V E R S I O N _ M I N O R " $ { C U D N N _ H E A D E R _ C O N T E N T S } " )
string ( REGEX REPLACE "define CUDNN_MINOR * +([0-9]+)" "\\1"
_ C U D N N _ V E R S I O N _ M I N O R " $ { _ C U D N N _ V E R S I O N _ M I N O R } " )
string ( REGEX MATCH "define CUDNN_PATCHLEVEL * +([0-9]+)"
_ C U D N N _ V E R S I O N _ P A T C H " $ { C U D N N _ H E A D E R _ C O N T E N T S } " )
string ( REGEX REPLACE "define CUDNN_PATCHLEVEL * +([0-9]+)" "\\1"
_ C U D N N _ V E R S I O N _ P A T C H " $ { _ C U D N N _ V E R S I O N _ P A T C H } " )
2020-11-24 07:25:27 +08:00
if ( NOT _CUDNN_VERSION_MAJOR )
set ( _CUDNN_VERSION "?" )
else ( )
set ( _CUDNN_VERSION "${_CUDNN_VERSION_MAJOR}.${_CUDNN_VERSION_MINOR}.${_CUDNN_VERSION_PATCH}" )
endif ( )
endif ( )
2021-04-14 06:15:32 +08:00
if ( CUDNN_INCLUDE_DIR AND CUDNN_LIBRARY AND _CUDNN_VERSION VERSION_GREATER_EQUAL MINIMUM_CUDNN_VERSION )
message ( STATUS "Found CUDNN ${_CUDNN_VERSION} located on system: (include ${CUDNN_INCLUDE_DIR} lib: ${CUDNN_LIBRARY})" )
2020-11-24 07:25:27 +08:00
set ( VCPKG_POLICY_EMPTY_PACKAGE enabled )
2021-04-27 01:27:45 +08:00
elseif ( VCPKG_TARGET_IS_WINDOWS )
message ( FATAL_ERROR "Please download CUDNN from official sources (such as https://developer.nvidia.com/rdp/cudnn-download ) and extract the zip into your CUDA_TOOLKIT_ROOT (${CUDA_TOOLKIT_ROOT}). (For example: tar.exe -xvf cudnn-11.2-windows-x64-v8.1.1.33.zip --strip 1 --directory \" ${ CUDA_TOOLKIT_ROOT } \"")
else ( )
message ( FATAL_ERROR "Please install CUDNN using your system package manager (the same way you installed CUDA). For example: apt install libcudnn8-dev." )
2021-04-14 06:15:32 +08:00
endif ( )
2021-05-18 15:28:38 +08:00
file ( INSTALL "${CURRENT_PORT_DIR}/FindCUDNN.cmake" DESTINATION ${ CURRENT_PACKAGES_DIR } /share/ ${ PORT } )
file ( INSTALL "${CURRENT_PORT_DIR}/usage" DESTINATION ${ CURRENT_PACKAGES_DIR } /share/ ${ PORT } )
2021-05-25 06:41:57 +08:00
file ( INSTALL "${CURRENT_PORT_DIR}/vcpkg-cmake-wrapper.cmake" DESTINATION ${ CURRENT_PACKAGES_DIR } /share/ ${ PORT } )