From d21dc00c6eef8fff2f048d153b8bad4e15e8005d Mon Sep 17 00:00:00 2001 From: Stefano Sinigardi Date: Mon, 13 May 2019 18:51:01 +0200 Subject: [PATCH] move towards using only modern cmake - part 3 --- CMakeLists.txt | 83 +++++++++++++----------------------------- DarknetConfig.cmake.in | 11 +----- 2 files changed, 27 insertions(+), 67 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3334bcfe..8d0384b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,34 +51,16 @@ else() message(STATUS "Unsupported CUDA version, please upgrade to CUDA 9+. Disabling CUDA support") else() set(ENABLE_CUDA "TRUE" CACHE BOOL "Enable CUDA support" FORCE) + cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS "Auto") + message(STATUS "Building with CUDA flags: " "${CUDA_ARCH_FLAGS}") + if ("arch=compute_75,code=sm_75" IN_LIST CUDA_ARCH_FLAGS) + set(ENABLE_CUDNN_HALF "TRUE" CACHE BOOL "Enable CUDNN Half precision" FORCE) + message(STATUS "Your setup supports half precision!") + endif() endif() endif() endif() -set(CUDA_COMPUTE_MODEL_75 "75") #Compute capability for Tesla T4, RTX 2080 -set(CUDA_COMPUTE_MODEL_72 "72") #Compute capability for Jetson Xavier -set(CUDA_COMPUTE_MODEL_70 "70") #Compute capability for Tesla V100 -set(CUDA_COMPUTE_MODEL_62 "62") #Compute capability for Jetson TX2 -set(CUDA_COMPUTE_MODEL_61 "61") #Compute capability for Tesla P40 -set(CUDA_COMPUTE_MODEL_60 "60") #Compute capability for Tesla P100 -set(CUDA_COMPUTE_MODEL_53 "53") #Compute capability for Jetson TX1 -set(CUDA_COMPUTE_MODEL_52 "52") #Compute capability for Tesla M40/M60 -set(CUDA_COMPUTE_MODEL_37 "37") #Compute capability for Tesla K80 -set(CUDA_COMPUTE_MODEL_35 "35") #Compute capability for Tesla K20/K40 -set(CUDA_COMPUTE_MODEL_30 "30") #Compute capability for Tesla K10, Quadro K4000 - -set(default_cuda_compute_model ${CUDA_COMPUTE_MODEL_30}) -if(ENABLE_CUDA AND NOT CUDA_COMPUTE_MODEL) - message(STATUS "Setting the compute model to ${default_cuda_compute_model} as none was specified.") - set(CUDA_COMPUTE_MODEL "${default_cuda_compute_model}" CACHE - STRING "Choose the best compute model supported by your GPU" FORCE) - set_property(CACHE CUDA_COMPUTE_MODEL PROPERTY STRINGS ${CUDA_COMPUTE_MODEL_75} ${CUDA_COMPUTE_MODEL_72} ${CUDA_COMPUTE_MODEL_70} ${CUDA_COMPUTE_MODEL_62} ${CUDA_COMPUTE_MODEL_61} ${CUDA_COMPUTE_MODEL_60} ${CUDA_COMPUTE_MODEL_53} ${CUDA_COMPUTE_MODEL_52} ${CUDA_COMPUTE_MODEL_37} ${CUDA_COMPUTE_MODEL_35} ${CUDA_COMPUTE_MODEL_30}) -endif() - -if(NOT ENABLE_CUDA) - set(CUDA_COMPUTE_MODEL "0" CACHE STRING "CUDA Compute Model set to 0 because CUDA is missing" FORCE) -endif() - if(USE_INTEGRATED_LIBS) set(PThreads_windows_DIR ${CMAKE_CURRENT_LIST_DIR}/3rdparty/pthreads CACHE PATH "Path where pthreads for windows can be located") endif() @@ -127,8 +109,6 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ffp-contract=fast -mavx -mavx2 -msse3 -msse4.1 -msse4.2 -msse4a") endif() -string(REPLACE " " "," ADDITIONAL_CXX_FLAGS_COMMA_SEPARATED "${ADDITIONAL_CXX_FLAGS}") - set(SKIP_USELIB_TRACK "FALSE" CACHE BOOL "Skip building uselib_track" FORCE) if(OpenCV_FOUND) if(ENABLE_CUDA AND NOT OpenCV_CUDA_VERSION) @@ -139,48 +119,37 @@ if(OpenCV_FOUND) endif() if(ENABLE_CUDA) - if(CUDA_COMPUTE_MODEL VERSION_GREATER_EQUAL ${CUDA_COMPUTE_MODEL_75} AND CUDA_VERSION VERSION_LESS_EQUAL "9.2") - message(STATUS "CUDA 10 is required for Compute Model 7.5 - Lowering settings to 7.2") - set(CUDA_COMPUTE_MODEL ${CUDA_COMPUTE_MODEL_72}) - endif() find_package(CUDNN) if(CUDNN_FOUND) set(ENABLE_CUDNN "TRUE" CACHE BOOL "Enable CUDNN" FORCE) - if(CUDA_COMPUTE_MODEL VERSION_GREATER_EQUAL ${CUDA_COMPUTE_MODEL_70}) - set(ENABLE_CUDNN_HALF "TRUE" CACHE BOOL "Enable CUDNN Half precision" FORCE) - message(STATUS "Enabled CUDNN_HALF") - endif() endif() - set(CUDA_COMPUTECAPABILITY_FLAGS "-gencode arch=compute_${CUDA_COMPUTE_MODEL},code=[sm_${CUDA_COMPUTE_MODEL},compute_${CUDA_COMPUTE_MODEL}]") +endif() + +if(ENABLE_CUDA) if (MSVC) + set(ADDITIONAL_CXX_FLAGS "${ADDITIONAL_CXX_FLAGS} /DGPU") if(CUDNN_FOUND) - if(OpenCV_FOUND) - set(CMAKE_CUDA_FLAGS "${CUDA_COMPUTECAPABILITY_FLAGS} -Wno-deprecated-declarations -Xcompiler=\"${ADDITIONAL_CXX_FLAGS_COMMA_SEPARATED},/DGPU,/DCUDNN,/DOPENCV\" ${CMAKE_CUDA_FLAGS}") - else() - set(CMAKE_CUDA_FLAGS "${CUDA_COMPUTECAPABILITY_FLAGS} -Wno-deprecated-declarations -Xcompiler=\"${ADDITIONAL_CXX_FLAGS_COMMA_SEPARATED},/DGPU,/DCUDNN\" ${CMAKE_CUDA_FLAGS}") - endif() - else() - if(OpenCV_FOUND) - set(CMAKE_CUDA_FLAGS "${CUDA_COMPUTECAPABILITY_FLAGS} -Wno-deprecated-declarations -Xcompiler=\"${ADDITIONAL_CXX_FLAGS_COMMA_SEPARATED},/DGPU,/DOPENCV\" ${CMAKE_CUDA_FLAGS}") - else() - set(CMAKE_CUDA_FLAGS "${CUDA_COMPUTECAPABILITY_FLAGS} -Wno-deprecated-declarations -Xcompiler=\"${ADDITIONAL_CXX_FLAGS_COMMA_SEPARATED},/DGPU\" ${CMAKE_CUDA_FLAGS}") - endif() + set(ADDITIONAL_CXX_FLAGS "${ADDITIONAL_CXX_FLAGS} /DCUDNN") endif() + if(OpenCV_FOUND) + set(ADDITIONAL_CXX_FLAGS "${ADDITIONAL_CXX_FLAGS} /DOPENCV") + endif() + string(REPLACE " " "," ADDITIONAL_CXX_FLAGS_COMMA_SEPARATED "${ADDITIONAL_CXX_FLAGS}") + set(CUDA_HOST_COMPILER_FLAGS "-Wno-deprecated-declarations -Xcompiler=\"${ADDITIONAL_CXX_FLAGS_COMMA_SEPARATED}\"") else() + set(ADDITIONAL_CXX_FLAGS "${ADDITIONAL_CXX_FLAGS} -DGPU") if(CUDNN_FOUND) - if(OpenCV_FOUND) - set(CMAKE_CUDA_FLAGS "${CUDA_COMPUTECAPABILITY_FLAGS} --compiler-options \"${ADDITIONAL_CXX_FLAGS} -fPIC -fopenmp -Ofast -DOPENCV -DGPU -DCUDNN \" ${CMAKE_CUDA_FLAGS}") - else() - set(CMAKE_CUDA_FLAGS "${CUDA_COMPUTECAPABILITY_FLAGS} --compiler-options \"${ADDITIONAL_CXX_FLAGS} -fPIC -fopenmp -Ofast -DGPU -DCUDNN \" ${CMAKE_CUDA_FLAGS}") - endif() - else() - if(OpenCV_FOUND) - set(CMAKE_CUDA_FLAGS "${CUDA_COMPUTECAPABILITY_FLAGS} --compiler-options \"${ADDITIONAL_CXX_FLAGS} -fPIC -fopenmp -Ofast -DOPENCV -DGPU \" ${CMAKE_CUDA_FLAGS}") - else() - set(CMAKE_CUDA_FLAGS "${CUDA_COMPUTECAPABILITY_FLAGS} --compiler-options \"${ADDITIONAL_CXX_FLAGS} -fPIC -fopenmp -Ofast -DGPU \" ${CMAKE_CUDA_FLAGS}") - endif() + set(ADDITIONAL_CXX_FLAGS "${ADDITIONAL_CXX_FLAGS} -DCUDNN") endif() + if(OpenCV_FOUND) + set(ADDITIONAL_CXX_FLAGS "${ADDITIONAL_CXX_FLAGS} -DOPENCV") + endif() + set(CUDA_HOST_COMPILER_FLAGS "--compiler-options \" ${ADDITIONAL_CXX_FLAGS} -fPIC -fopenmp -Ofast \"") endif() + + string (REPLACE ";" " " CUDA_ARCH_FLAGS_SPACE_SEPARATED "${CUDA_ARCH_FLAGS}") + set(CMAKE_CUDA_FLAGS "${CUDA_ARCH_FLAGS_SPACE_SEPARATED} ${CUDA_HOST_COMPILER_FLAGS} ${CMAKE_CUDA_FLAGS}") + message(STATUS "CMAKE_CUDA_FLAGS: ${CMAKE_CUDA_FLAGS}") endif() set(ENABLE_ZED_CAMERA "TRUE" CACHE BOOL "Enable ZED Camera support") diff --git a/DarknetConfig.cmake.in b/DarknetConfig.cmake.in index dbd22112..d0f47132 100644 --- a/DarknetConfig.cmake.in +++ b/DarknetConfig.cmake.in @@ -7,30 +7,21 @@ include(CMakeFindDependencyMacro) if(@ENABLE_OPENCV@) find_dependency(OpenCV) - add_definitions(-DOPENCV) endif() find_dependency(Stb) if(@ENABLE_CUDA@) - add_definitions(-DGPU) if(@ENABLE_CUDNN@) find_dependency(CUDNN) - add_definitions(-DCUDNN) - if(@CUDA_COMPUTE_MODEL@ VERSION_GREATER_EQUAL @CUDA_COMPUTE_MODEL_70@) - add_definitions(-DCUDNN_HALF) - message(STATUS "Enabled CUDNN_HALF") - endif() endif() endif() set(CMAKE_THREAD_PREFER_PTHREAD ON) find_dependency(Threads) -if(MSVC) +if(@MSVC@) find_dependency(PThreads_windows) - #add_definitions(-D_CRT_SECURE_NO_WARNINGS) - #set(CMAKE_CXX_FLAGS "/wd4018 /wd4244 /wd4267 /wd4305 ${CMAKE_CXX_FLAGS}") endif() if(@ENABLE_OPENMP@)