From 35346d2ef80dc46b9eb4fba57da1737a49f4743e Mon Sep 17 00:00:00 2001 From: Stefano Sinigardi Date: Sat, 24 Aug 2019 13:46:45 +0200 Subject: [PATCH] [cudnn] remove hardcoded version in cmake module (#3738) collateral fixes: * handle opencv4 upgrade on vcpkg * add yasm (ffmpeg prerequisite) on travis * install ffmpeg separately from opencv to circumvent time limits * build only release to halve ci time * do not build as shared libs when using vcpkg, since default triplets are static * remove debug configs from appveyor matrix --- .travis.yml | 30 +++++++++++++++++++----------- appveyor.yml | 30 +++++++++--------------------- build.sh | 2 ++ cmake/Modules/FindCUDNN.cmake | 21 +++++++-------------- 4 files changed, 37 insertions(+), 46 deletions(-) diff --git a/.travis.yml b/.travis.yml index 63c7b2c4..7ae323e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,8 +78,8 @@ matrix: name: macOS - clang - vcpkg osx_image: xcode10.1 env: - - additional_defines="" - - MATRIX_EVAL="brew install gcc && unset CC && unset CXX" + - additional_defines="-DBUILD_SHARED_LIBS=OFF" + - MATRIX_EVAL="brew install gcc && brew install yasm && unset CC && unset CXX" - USE_VCPKG=true - VCPKG_DEFINES="-DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake" @@ -111,8 +111,13 @@ matrix: compiler: gcc dist: bionic name: ubuntu 18.04 - gcc - vcpkg + addons: + apt: + update: true + packages: + - yasm env: - - additional_defines="" + - additional_defines="-DBUILD_SHARED_LIBS=OFF" - USE_VCPKG=true - VCPKG_DEFINES="-DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake" - MATRIX_EVAL="" @@ -181,8 +186,13 @@ matrix: compiler: gcc dist: bionic name: ubuntu 18.04 - gcc - CUDA 10 - vcpkg + addons: + apt: + update: true + packages: + - yasm env: - - additional_defines="" + - additional_defines="-DBUILD_SHARED_LIBS=OFF" - USE_VCPKG=true - VCPKG_DEFINES="-DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake" - CUDACXX=/usr/local/cuda-10.0/bin/nvcc @@ -209,22 +219,20 @@ install: - cd vcpkg - git pull - if [ "${USE_VCPKG}" = true ] ; then ./bootstrap-vcpkg.sh ; fi - - if [ "${USE_VCPKG}" = true ] ; then travis_wait ./vcpkg install stb pthreads ; fi + - if [ "${USE_VCPKG}" = true ] ; then echo "set(VCPKG_BUILD_TYPE release)" >> triplets/x64-osx.cmake ; fi + - if [ "${USE_VCPKG}" = true ] ; then echo "set(VCPKG_BUILD_TYPE release)" >> triplets/x64-linux.cmake ; fi + - if [ "${USE_VCPKG}" = true ] ; then travis_wait ./vcpkg install stb pthreads --recurse; fi + - if [ "${USE_VCPKG}" = true ] ; then travis_wait 45 ./vcpkg install ffmpeg --recurse; fi #- if [ "${USE_VCPKG}" = true ] && [[ ! -z "${CUDACXX}" ]] ; then travis_wait 45 ./vcpkg install opencv[ffmpeg,cuda] --recurse; fi #- if [ "${USE_VCPKG}" = true ] && [[ -z "${CUDACXX}" ]] ; then travis_wait 45 ./vcpkg install opencv[ffmpeg] --recurse; fi - - if [ "${USE_VCPKG}" = true ] ; then travis_wait 45 ./vcpkg install opencv[ffmpeg] ; fi + - if [ "${USE_VCPKG}" = true ] ; then travis_wait 45 ./vcpkg install opencv[ffmpeg] --recurse; fi - popd before_script: - - mkdir build_debug - - cd build_debug - - cmake .. -DCMAKE_BUILD_TYPE="Debug" ${VCPKG_DEFINES} ${additional_defines} - - cd .. - mkdir build_release - cd build_release - cmake .. -DCMAKE_BUILD_TYPE="Release" ${VCPKG_DEFINES} ${additional_defines} - cd .. script: - - cd build_debug && cmake --build . --target install -- -j8 && cd .. - cd build_release && cmake --build . --target install -- -j8 && cd .. diff --git a/appveyor.yml b/appveyor.yml index 26b1add4..380feba4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,29 +10,17 @@ environment: CYGWIN_NOWINPATH: yes CYGSH: C:\cygwin64\bin\bash -c - platform: Win64 - COMPILER: vs - configuration: Release - VCPKG_ROOT: C:\Tools\vcpkg - VCPKG_DEFAULT_TRIPLET: x64-windows USE_CUDA: yes - - platform: Win64 - COMPILER: vs - configuration: Debug - VCPKG_ROOT: C:\Tools\vcpkg - VCPKG_DEFAULT_TRIPLET: x64-windows - USE_CUDA: yes - - platform: Win64 COMPILER: vs configuration: Release VCPKG_ROOT: C:\Tools\vcpkg VCPKG_DEFAULT_TRIPLET: x64-windows - USE_CUDA: no - platform: Win64 + USE_CUDA: no COMPILER: vs - configuration: Debug + configuration: Release VCPKG_ROOT: C:\Tools\vcpkg VCPKG_DEFAULT_TRIPLET: x64-windows - USE_CUDA: no - platform: Win64 COMPILER: vs configuration: Release @@ -71,14 +59,15 @@ install: - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] cd %VCPKG_ROOT% - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] git pull - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] .\bootstrap-vcpkg.bat - - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] if [%USE_CUDA%]==[yes] vcpkg install cuda - - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] vcpkg install stb pthreads - - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] vcpkg install opencv[ffmpeg] ## opencv[ffmpeg,cuda] is too big to build, timing out (>1h). We use plain openCV also for CUDA builds (toolchain can manage this strange situation anyway) + - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] echo set(VCPKG_BUILD_TYPE release) >> triplets\%VCPKG_DEFAULT_TRIPLET%.cmake + - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] if [%USE_CUDA%]==[yes] vcpkg install cuda --recurse + - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] vcpkg install stb pthreads --recurse + - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] vcpkg install ffmpeg --recurse + - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] vcpkg install opencv[ffmpeg] --recurse ## opencv[ffmpeg,cuda] is too big to build, timing out (>1h). We use plain openCV also for CUDA builds (toolchain can manage this strange situation anyway) - cd %WORKSPACE%\darknet\ - - mkdir build_debug && cd build_debug + - if [%COMPILER%]==[cygwin] mkdir build_debug && cd build_debug - if [%COMPILER%]==[cygwin] %CYGSH% 'cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug"' - - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] if [%configuration%]==[Debug] cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=%VCPKG_DEFAULT_TRIPLET%" -DCMAKE_BUILD_TYPE="Debug" .. - - cd .. + - if [%COMPILER%]==[cygwin] cd .. - mkdir build_release && cd build_release - if [%COMPILER%]==[cygwin] %CYGSH% 'cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release"' - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] if [%configuration%]==[Release] cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=%VCPKG_DEFAULT_TRIPLET%" -DCMAKE_BUILD_TYPE="Release" .. @@ -89,7 +78,6 @@ install: build_script: - if [%COMPILER%]==[cygwin] cd build_debug && %CYGSH% 'cmake --build . --target install -- -j8' && cd .. - if [%COMPILER%]==[cygwin] cd build_release && %CYGSH% 'cmake --build . --target install -- -j8' && cd .. - - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] if [%configuration%]==[Debug] cd build_debug && cmake --build . --config Debug --parallel 8 --target install && cd .. - if [%COMPILER%]==[vs] if [%configuration%]==[Release] cd build_release && cmake --build . --config Release --parallel 8 --target install && cd .. artifacts: diff --git a/build.sh b/build.sh index 6c8df676..dfd5446b 100755 --- a/build.sh +++ b/build.sh @@ -16,12 +16,14 @@ then vcpkg_define="-DCMAKE_TOOLCHAIN_FILE=${vcpkg_path}/scripts/buildsystems/vcpkg.cmake" vcpkg_triplet_define="-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" echo "Found vcpkg in VCPKG_ROOT: ${vcpkg_path}" + additional_defines="-DBUILD_SHARED_LIBS=OFF" elif [[ ! -z "${WORKSPACE}" ]] && [ -d ${WORKSPACE}/vcpkg ] && [ ! "$bypass_vcpkg" = true ] then vcpkg_path="${WORKSPACE}/vcpkg" vcpkg_define="-DCMAKE_TOOLCHAIN_FILE=${vcpkg_path}/scripts/buildsystems/vcpkg.cmake" vcpkg_triplet_define="-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" echo "Found vcpkg in WORKSPACE/vcpkg: ${vcpkg_path}" + additional_defines="-DBUILD_SHARED_LIBS=OFF" elif [ ! "$bypass_vcpkg" = true ] then (>&2 echo "darknet is unsupported without vcpkg, use at your own risk!") diff --git a/cmake/Modules/FindCUDNN.cmake b/cmake/Modules/FindCUDNN.cmake index 3aa2aa81..871295fa 100644 --- a/cmake/Modules/FindCUDNN.cmake +++ b/cmake/Modules/FindCUDNN.cmake @@ -34,10 +34,7 @@ if(NOT CUDNN_LIBRARY) PATH_SUFFIXES lib lib64 cuda/lib cuda/lib64 lib/x64) endif() -find_package_handle_standard_args( - CUDNN DEFAULT_MSG CUDNN_INCLUDE_DIR CUDNN_LIBRARY) - -if(CUDNN_FOUND) +if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn.h") file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_HEADER_CONTENTS) string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)" CUDNN_VERSION_MAJOR "${CUDNN_HEADER_CONTENTS}") @@ -60,21 +57,17 @@ endif() set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR}) set(CUDNN_LIBRARIES ${CUDNN_LIBRARY}) -if(CUDNN_FOUND) - message(STATUS "Found cuDNN: v${CUDNN_VERSION} (include: ${CUDNN_INCLUDE_DIR}, library: ${CUDNN_LIBRARY})") -endif() mark_as_advanced(CUDNN_LIBRARY CUDNN_INCLUDE_DIR) -# Register imported libraries: -# 1. If we can find a Windows .dll file (or if we can find both Debug and -# Release libraries), we will set appropriate target properties for these. -# 2. However, for most systems, we will only register the import location and -# include directory. +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") - message(STATUS "CUDNN_DLL_DIR: ${CUDNN_DLL_DIR}") - find_file(CUDNN_LIBRARY_DLL NAMES cudnn64_7.dll PATHS ${CUDNN_DLL_DIR}) + find_file(CUDNN_LIBRARY_DLL NAMES cudnn64_${CUDNN_VERSION_MAJOR}.dll PATHS ${CUDNN_DLL_DIR}) endif() if( CUDNN_FOUND AND NOT TARGET CuDNN::CuDNN )