From fefc7ef80331d3ef860c2fb6a24e33d80390945d Mon Sep 17 00:00:00 2001 From: Stefano Sinigardi Date: Tue, 19 Mar 2019 20:07:02 +0100 Subject: [PATCH] improve CUDA setup instructions and templates in scripts --- CMakeSettings.json | 160 +++++++++++++++++++++++++++++++++++++++++++-- README.md | 4 +- build.ps1 | 42 ++++++++---- 3 files changed, 187 insertions(+), 19 deletions(-) diff --git a/CMakeSettings.json b/CMakeSettings.json index 968e68ba..4df04b61 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -20,9 +20,28 @@ "cmakeCommandArgs": "", "configurationType": "Debug", "generator": "Visual Studio 15 2017 Win64", - "name": "x64-Debug", - "variables": [ + "name": "x64-Debug static", + "variables": [{ + "name": "CMAKE_TOOLCHAIN_FILE", + "value": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" + }, + { + "name": "USE_INTEGRATED_LIBS", + "value": "FALSE" + }, { + "name": "VCPKG_TARGET_TRIPLET", + "value": "${env.VCPKG_DEFAULT_TRIPLET}" + } + ] + }, { + "buildCommandArgs": "-m -v:minimal", + "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "cmakeCommandArgs": "", + "configurationType": "Release", + "generator": "Visual Studio 15 2017 Win64", + "name": "x64-Release static", + "variables": [{ "name": "CMAKE_TOOLCHAIN_FILE", "value": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" }, @@ -35,16 +54,139 @@ "value": "${env.VCPKG_DEFAULT_TRIPLET}" } ] - }, + }, { + "buildCommandArgs": "-m -v:minimal", + "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "cmakeCommandArgs": "", + "configurationType": "Debug", + "generator": "Visual Studio 15 2017 Win64", + "name": "x64-Debug static w/ CUDA", + "variables": [{ + "name": "CMAKE_TOOLCHAIN_FILE", + "value": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" + }, + { + "name": "USE_INTEGRATED_LIBS", + "value": "FALSE" + }, + { + "name": "CUDA_COMPUTE_MODEL", + "value": "30" + }, + { + "name": "VCPKG_TARGET_TRIPLET", + "value": "${env.VCPKG_DEFAULT_TRIPLET}" + } + ] + }, { + "buildCommandArgs": "-m -v:minimal", + "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "cmakeCommandArgs": "", + "configurationType": "Release", + "generator": "Visual Studio 15 2017 Win64", + "name": "x64-Release static w/ CUDA", + "variables": [{ + "name": "CMAKE_TOOLCHAIN_FILE", + "value": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" + }, + { + "name": "USE_INTEGRATED_LIBS", + "value": "FALSE" + }, + { + "name": "CUDA_COMPUTE_MODEL", + "value": "30" + }, + { + "name": "VCPKG_TARGET_TRIPLET", + "value": "${env.VCPKG_DEFAULT_TRIPLET}" + } + ] + } { + "buildCommandArgs": "-m -v:minimal", + "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "cmakeCommandArgs": "", + "configurationType": "Debug", + "generator": "Visual Studio 15 2017 Win64", + "name": "x64-Debug dynamic", + "variables": [{ + "name": "CMAKE_TOOLCHAIN_FILE", + "value": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" + }, + { + "name": "USE_INTEGRATED_LIBS", + "value": "FALSE" + }, + { + "name": "BUILD_SHARED_LIBS", + "value": "TRUE" + }, + { + "name": "VCPKG_TARGET_TRIPLET", + "value": "${env.VCPKG_DEFAULT_TRIPLET}" + } + ] + }, { "buildCommandArgs": "-m -v:minimal", "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", "cmakeCommandArgs": "", "configurationType": "Release", "generator": "Visual Studio 15 2017 Win64", - "name": "x64-Release", - "variables": [ + "name": "x64-Release dynamic", + "variables": [{ + "name": "CMAKE_TOOLCHAIN_FILE", + "value": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" + }, + { + "name": "USE_INTEGRATED_LIBS", + "value": "FALSE" + }, + { + "name": "BUILD_SHARED_LIBS", + "value": "TRUE" + }, + { + "name": "VCPKG_TARGET_TRIPLET", + "value": "${env.VCPKG_DEFAULT_TRIPLET}" + } + ] + }, { + "buildCommandArgs": "-m -v:minimal", + "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "cmakeCommandArgs": "", + "configurationType": "Debug", + "generator": "Visual Studio 15 2017 Win64", + "name": "x64-Debug dynamic w/ CUDA", + "variables": [{ + "name": "CMAKE_TOOLCHAIN_FILE", + "value": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" + }, { + "name": "USE_INTEGRATED_LIBS", + "value": "FALSE" + }, + { + "name": "CUDA_COMPUTE_MODEL", + "value": "30" + }, + { + "name": "BUILD_SHARED_LIBS", + "value": "TRUE" + }, + { + "name": "VCPKG_TARGET_TRIPLET", + "value": "${env.VCPKG_DEFAULT_TRIPLET}" + } + ] + }, { + "buildCommandArgs": "-m -v:minimal", + "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "cmakeCommandArgs": "", + "configurationType": "Release", + "generator": "Visual Studio 15 2017 Win64", + "name": "x64-Release dynamic w/ CUDA", + "variables": [{ "name": "CMAKE_TOOLCHAIN_FILE", "value": "${env.VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake" }, @@ -52,6 +194,14 @@ "name": "USE_INTEGRATED_LIBS", "value": "FALSE" }, + { + "name": "CUDA_COMPUTE_MODEL", + "value": "30" + }, + { + "name": "BUILD_SHARED_LIBS", + "value": "TRUE" + }, { "name": "VCPKG_TARGET_TRIPLET", "value": "${env.VCPKG_DEFAULT_TRIPLET}" diff --git a/README.md b/README.md index 9b740ae2..e04ffe97 100644 --- a/README.md +++ b/README.md @@ -183,9 +183,9 @@ PS \> cd $env:VCPKG_ROOT PS Code\vcpkg> .\vcpkg install pthreads opencv #replace with opencv[cuda] in case you want to use cuda-accelerated openCV ``` -8. [necessary only with CUDA] Customize the CMakeLists.txt with the preferred compute capability +8. [necessary only with CUDA] Customize the `build.ps1` script enabling the appropriate `my_cuda_compute_model` line. If not manually defined, CMake toolchain will automatically use the very low 3.0 CUDA compute model -9. Build with the Powershell script `build.ps1` or use the "Open Folder" functionality of Visual Studio 2017. In the first option, if you want to use Visual Studio, you will find a custom solution created for you by CMake after the build containing all the appropriate config flags for your system. +9. Build with the Powershell script `build.ps1`. If you want to use Visual Studio, you will find a custom solution created for you by CMake after the build containing all the appropriate config flags for your system. ### How to compile on Windows (legacy way) diff --git a/build.ps1 b/build.ps1 index 1dfcc4fd..7063098c 100755 --- a/build.ps1 +++ b/build.ps1 @@ -4,6 +4,18 @@ $number_of_build_workers=8 #$shared_lib="-DBUILD_SHARED_LIBS:BOOL=ON" $force_using_include_libs=$false +#$my_cuda_compute_model=75 #Compute capability for Tesla T4, RTX 2080 +#$my_cuda_compute_model=72 #Compute capability for Jetson Xavier +#$my_cuda_compute_model=70 #Compute capability for Tesla V100 +#$my_cuda_compute_model=62 #Compute capability for Jetson TX2 +#$my_cuda_compute_model=61 #Compute capability for Tesla P40 +#$my_cuda_compute_model=60 #Compute capability for Tesla P100 +#$my_cuda_compute_model=53 #Compute capability for Jetson TX1 +#$my_cuda_compute_model=52 #Compute capability for Tesla M40/M60 +#$my_cuda_compute_model=37 #Compute capability for Tesla K80 +#$my_cuda_compute_model=35 #Compute capability for Tesla K20/K40 +#$my_cuda_compute_model=30 #Compute capability for Tesla K10, Quadro K4000 + if ((Test-Path env:VCPKG_ROOT) -and -not $force_using_include_libs) { $vcpkg_path = "$env:VCPKG_ROOT" Write-Host "Found vcpkg in VCPKG_ROOT: $vcpkg_path" @@ -68,33 +80,39 @@ if (Test-Path env:CUDA_PATH) { } } -if ($vcpkg_path) { - # RELEASE - New-Item -Path .\build_win_release -ItemType directory -Force - Set-Location build_win_release - cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_path\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" "-DCMAKE_BUILD_TYPE=Release" $shared_lib .. - cmake --build . --config Release --parallel ${number_of_build_workers} --target install - Remove-Item DarknetConfig.cmake - Remove-Item DarknetConfigVersion.cmake - Set-Location .. +if($my_cuda_compute_model) { + $additional_build_setup = "-DCUDA_COMPUTE_MODEL=${my_cuda_compute_model}" +} +if ($vcpkg_path) { # DEBUG New-Item -Path .\build_win_debug -ItemType directory -Force Set-Location build_win_debug - cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_path\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" "-DCMAKE_BUILD_TYPE=Debug" $shared_lib .. + cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_path\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" "-DCMAKE_BUILD_TYPE=Debug" $shared_lib $additional_build_setup .. cmake --build . --config Debug --parallel ${number_of_build_workers} --target install Remove-Item DarknetConfig.cmake Remove-Item DarknetConfigVersion.cmake Set-Location .. + + # RELEASE + New-Item -Path .\build_win_release -ItemType directory -Force + Set-Location build_win_release + cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_path\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=$vcpkg_triplet" "-DCMAKE_BUILD_TYPE=Release" $shared_lib $additional_build_setup .. + cmake --build . --config Release --parallel ${number_of_build_workers} --target install + Remove-Item DarknetConfig.cmake + Remove-Item DarknetConfigVersion.cmake + Copy-Item *.dll .. + Set-Location .. } else { - # USE LOCAL PTHREAD LIB, NO VCPKG, ONLY RELEASE + # USE LOCAL PTHREAD LIB AND LOCAL STB HEADER, NO VCPKG, ONLY RELEASE MODE SUPPORTED # if you want to manually force this case, remove VCPKG_ROOT env variable and remember to use "vcpkg integrate remove" in case you had enabled user-wide vcpkg integration New-Item -Path .\build_win_release_novcpkg -ItemType directory -Force Set-Location build_win_release_novcpkg - cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" $shared_lib .. + cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" $shared_lib $additional_build_setup .. cmake --build . --config Release --parallel ${number_of_build_workers} --target install Remove-Item DarknetConfig.cmake Remove-Item DarknetConfigVersion.cmake + Copy-Item ..\3rdparty\pthreads\bin\pthreadVC2.dll .. Set-Location .. }