Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes #8398

Merged
merged 12 commits into from
Mar 6, 2022
8 changes: 4 additions & 4 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ jobs:

- name: 'Build'
shell: pwsh
run: ${{ github.workspace }}/build.ps1 -UseVCPKG -DoNotUpdateVCPKG -DisableInteractive -DoNotUpdateDARKNET
run: ${{ github.workspace }}/build.ps1 -UseVCPKG -DoNotUpdateVCPKG -EnableOPENCV -DisableInteractive -DoNotUpdateDARKNET

- uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -655,9 +655,9 @@ jobs:

- name: 'Build'
env:
CUDA_PATH: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5"
CUDA_TOOLKIT_ROOT_DIR: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5"
CUDACXX: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5\\bin\\nvcc.exe"
CUDA_PATH: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6"
CUDA_TOOLKIT_ROOT_DIR: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6"
CUDACXX: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6\\bin\\nvcc.exe"
shell: pwsh
run: ${{ github.workspace }}/build.ps1 -EnableCUDA -DisableInteractive -DoNotUpdateDARKNET

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ jobs:

- name: 'Build'
shell: pwsh
run: ${{ github.workspace }}/build.ps1 -UseVCPKG -DoNotUpdateVCPKG -DisableInteractive -DoNotUpdateDARKNET
run: ${{ github.workspace }}/build.ps1 -UseVCPKG -DoNotUpdateVCPKG -EnableOPENCV -DisableInteractive -DoNotUpdateDARKNET


osx:
Expand Down Expand Up @@ -408,9 +408,9 @@ jobs:

- name: 'Build'
env:
CUDA_PATH: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5"
CUDA_TOOLKIT_ROOT_DIR: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5"
CUDACXX: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5\\bin\\nvcc.exe"
CUDA_PATH: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6"
CUDA_TOOLKIT_ROOT_DIR: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6"
CUDACXX: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6\\bin\\nvcc.exe"
shell: pwsh
run: ${{ github.workspace }}/build.ps1 -EnableCUDA -DisableInteractive -DoNotUpdateDARKNET

Expand Down
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option(ENABLE_CUDNN "Enable CUDNN" ON)
option(ENABLE_CUDNN_HALF "Enable CUDNN Half precision" ON)
option(ENABLE_ZED_CAMERA "Enable ZED Camera support" ON)
option(ENABLE_VCPKG_INTEGRATION "Enable VCPKG integration" ON)
option(ENABLE_DEPLOY_CUSTOM_CMAKE_MODULES "Copy custom CMake modules for downstream integration" OFF)
option(ENABLE_CSHARP_WRAPPER "Enable building a csharp wrapper" OFF)
option(VCPKG_BUILD_OPENCV_WITH_CUDA "Build OpenCV with CUDA extension integration" ON)
option(VCPKG_USE_OPENCV2 "Use legacy OpenCV 2" OFF)
Expand Down Expand Up @@ -158,8 +159,13 @@ if(ENABLE_CUDA)
message(STATUS "CUDACXX: $ENV{CUDACXX}")
message(FATAL_ERROR "Unsupported CUDA version, please upgrade to CUDA 9+ or disable CUDA with explicitly with -DENABLE_CUDA=OFF")
else()
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.23.0" AND NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES all-major)
endif()
message(STATUS "Selected CMAKE_CUDA_ARCHITECTURES: ${CMAKE_CUDA_ARCHITECTURES}")
if(70 IN_LIST CMAKE_CUDA_ARCHITECTURES OR
if("all-major" IN_LIST CMAKE_CUDA_ARCHITECTURES OR
"all" IN_LIST CMAKE_CUDA_ARCHITECTURES OR
70 IN_LIST CMAKE_CUDA_ARCHITECTURES OR
72 IN_LIST CMAKE_CUDA_ARCHITECTURES OR
75 IN_LIST CMAKE_CUDA_ARCHITECTURES OR
80 IN_LIST CMAKE_CUDA_ARCHITECTURES OR
Expand Down Expand Up @@ -585,6 +591,14 @@ install(FILES
DESTINATION "${INSTALL_CMAKE_DIR}"
)

if (ENABLE_DEPLOY_CUSTOM_CMAKE_MODULES)
install(FILES
"${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/FindCUDNN.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/FindPThreads4W.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}"
)
endif()

if(ENABLE_CSHARP_WRAPPER)
add_subdirectory(src/csharp)
endif()
6 changes: 5 additions & 1 deletion DarknetConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_dependency(Threads)

if(MSVC)
find_dependency(PThreads_windows)
if(@USE_INTEGRATED_LIBS@)
find_dependency(PThreads4W)
else()
find_dependency(pthreads)
endif()
set(CMAKE_CXX_FLAGS "/wd4018 /wd4244 /wd4267 /wd4305 ${CMAKE_CXX_FLAGS}")
endif()

Expand Down
75 changes: 56 additions & 19 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Build darknet using CMake, trying to properly setup the environment around compi
.PARAMETER DisableInteractive
Disable script interactivity (useful for CI runs)

.PARAMETER DisableDLLcopy
Disable automatic DLL deployment through vcpkg at the end

.PARAMETER EnableCUDA
Enable CUDA feature

Expand Down Expand Up @@ -62,8 +65,11 @@ Create darknet library as static instead of the default linking mode of your sys
.PARAMETER ForceVCPKGCacheRemoval
Force clean up of the local vcpkg binary cache before building

.PARAMETER DoNotDeleteBuildtreesFolder
Do not delete vcpkg buildtrees temp folder at the end of the script
.PARAMETER ForceVCPKGBuildtreesRemoval
Force clean up of vcpkg buildtrees temp folder at the end of the script

.PARAMETER ForceVCPKGPackagesRemoval
Force clean up of vcpkg packages folder at the end of the script

.PARAMETER ForceSetupVS
Forces Visual Studio setup, also on systems on which it would not have been enabled automatically
Expand Down Expand Up @@ -93,6 +99,7 @@ Additional setup parameters to manually pass to CMake

param (
[switch]$DisableInteractive = $false,
[switch]$DisableDLLcopy = $false,
[switch]$EnableCUDA = $false,
[switch]$EnableCUDNN = $false,
[switch]$EnableOPENCV = $false,
Expand All @@ -109,7 +116,8 @@ param (
[switch]$ForceCPP = $false,
[switch]$ForceStaticLib = $false,
[switch]$ForceVCPKGCacheRemoval = $false,
[switch]$DoNotDeleteBuildtreesFolder = $false,
[switch]$ForceVCPKGBuildtreesRemoval = $false,
[switch]$ForceVCPKGPackagesRemoval = $false,
[switch]$ForceSetupVS = $false,
[switch]$EnableCSharpWrapper = $false,
[switch]$DownloadWeights = $false,
Expand All @@ -119,7 +127,7 @@ param (
[string]$AdditionalBuildSetup = "" # "-DCMAKE_CUDA_ARCHITECTURES=30"
)

$build_ps1_version = "0.9.8"
$build_ps1_version = "1.9.8"

$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | out-null
Expand Down Expand Up @@ -202,10 +210,10 @@ Function DownloadNinja() {
}


Write-Host "Darknet build script version ${build_ps1_version}"
Write-Host "Build script version ${build_ps1_version}"

if ((-Not $DisableInteractive) -and (-Not $UseVCPKG)) {
$Result = Read-Host "Enable vcpkg to install darknet dependencies (yes/no)"
$Result = Read-Host "Enable vcpkg to install dependencies (yes/no)"
if (($Result -eq 'Yes') -or ($Result -eq 'Y') -or ($Result -eq 'yes') -or ($Result -eq 'y')) {
$UseVCPKG = $true
}
Expand Down Expand Up @@ -431,7 +439,7 @@ if (-Not $DoNotUseNinja) {
$NINJA_EXE = Get-Command "ninja" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $NINJA_EXE) {
DownloadNinja
$env:PATH += ";${PSScriptRoot}/ninja"
$env:PATH = '{0}{1}{2}' -f $env:PATH, [IO.Path]::PathSeparator, "${PSScriptRoot}/ninja"
$NINJA_EXE = Get-Command "ninja" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $NINJA_EXE) {
$DoNotUseNinja = $true
Expand Down Expand Up @@ -555,7 +563,7 @@ elseif ((Test-Path "${env:WORKSPACE}/vcpkg") -and $UseVCPKG) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_VCPKG_INTEGRATION:BOOL=ON"
}
elseif (-not($null -eq ${RUNVCPKG_VCPKG_ROOT_OUT})) {
if ((Test-Path "${RUNVCPKG_VCPKG_ROOT_OUT}") -and $UseVCPKG) {
if((Test-Path "${RUNVCPKG_VCPKG_ROOT_OUT}") -and $UseVCPKG) {
$vcpkg_path = "${RUNVCPKG_VCPKG_ROOT_OUT}"
$env:VCPKG_ROOT = "${RUNVCPKG_VCPKG_ROOT_OUT}"
$vcpkg_root_set_by_this_script = $true
Expand Down Expand Up @@ -619,7 +627,7 @@ if ($ForceVCPKGCacheRemoval -and (-Not $UseVCPKG)) {
Write-Host "VCPKG is not enabled, so local vcpkg binary cache will not be deleted even if requested" -ForegroundColor Yellow
}

if ($UseVCPKG -and (-Not $DoNotDeleteBuildtreesFolder)) {
if ($UseVCPKG -and $ForceVCPKGBuildtreesRemoval) {
Write-Host "Cleaning folder buildtrees inside vcpkg" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue "$env:VCPKG_ROOT/buildtrees"
}
Expand Down Expand Up @@ -706,7 +714,7 @@ if (-Not $IsMacOS -and $EnableCUDA) {
$NVCC_EXE = Get-Command "nvcc" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
if (-Not $NVCC_EXE) {
if (Test-Path env:CUDA_PATH) {
$env:PATH += ";${env:CUDA_PATH}/bin"
$env:PATH = '{0}{1}{2}' -f $env:PATH, [IO.Path]::PathSeparator, "${env:CUDA_PATH}/bin"
Write-Host "Found cuda in ${env:CUDA_PATH}"
}
else {
Expand All @@ -726,6 +734,10 @@ if (-Not $IsMacOS -and $EnableCUDA) {
}
}

if (-Not $DisableDLLcopy) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DX_VCPKG_APPLOCAL_DEPS_INSTALL=ON"
}

if ($ForceCPP) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DBUILD_AS_CPP:BOOL=ON"
}
Expand All @@ -750,6 +762,10 @@ if ($EnableCSharpWrapper) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_CSHARP_WRAPPER:BOOL=ON"
}

if (-Not $InstallDARKNETthroughVCPKG) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_DEPLOY_CUSTOM_CMAKE_MODULES:BOOL=ON"
}

if ($InstallDARKNETthroughVCPKG) {
if ($ForceVCPKGDarknetHEAD) {
$headMode = " --head "
Expand Down Expand Up @@ -811,7 +827,6 @@ if ($InstallDARKNETthroughVCPKG) {
if (-Not ($exitCode -eq 0)) {
MyThrow("Installing darknet dependencies through vcpkg failed! Exited with error code $exitCode.")
}
Pop-Location
}
}
else {
Expand Down Expand Up @@ -842,21 +857,43 @@ else {
}
Remove-Item -Force -ErrorAction SilentlyContinue DarknetConfig.cmake
Remove-Item -Force -ErrorAction SilentlyContinue DarknetConfigVersion.cmake
$dllfiles = Get-ChildItem ./${dllfolder}/*.dll
if ($dllfiles) {
Copy-Item $dllfiles ..
if (-Not $UseVCPKG -And -Not $DisableDLLcopy) {
$dllfiles = Get-ChildItem ./${dllfolder}/*.dll
if ($dllfiles) {
Copy-Item $dllfiles ..
}
}
Set-Location ..
Copy-Item cmake/Modules/*.cmake share/darknet/
Pop-Location
}

if ($UseVCPKG -and (-Not $DoNotDeleteBuildtreesFolder)) {
Write-Host "Cleaning folder buildtrees inside vcpkg" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue "$env:VCPKG_ROOT/buildtrees"

if (-Not $DoNotDeleteBuildFolder) {
Write-Host "Removing folder $build_folder" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $build_folder
}

Write-Host "Build complete!" -ForegroundColor Green
Pop-Location

if ($ForceVCPKGBuildtreesRemoval -and (-Not $UseVCPKG)) {
Write-Host "VCPKG is not enabled, so local vcpkg buildtrees folder will not be deleted even if requested" -ForegroundColor Yellow
}

if ($UseVCPKG -and $ForceVCPKGBuildtreesRemoval) {
$vcpkgbuildtreespath = "$vcpkg_path/buildtrees"
Write-Host "Removing local vcpkg buildtrees folder from $vcpkgbuildtreespath" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $vcpkgbuildtreespath
}

if ($ForceVCPKGPackagesRemoval -and (-Not $UseVCPKG)) {
Write-Host "VCPKG is not enabled, so local vcpkg packages folder will not be deleted even if requested" -ForegroundColor Yellow
}

if ($UseVCPKG -and $ForceVCPKGPackagesRemoval) {
$vcpkgpackagespath = "$vcpkg_path/packages"
Write-Host "Removing local vcpkg packages folder from $vcpkgpackagespath" -ForegroundColor Yellow
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $vcpkgpackagespath
}

if ($DownloadWeights) {
Write-Host "Downloading weights..." -ForegroundColor Yellow
Expand Down
34 changes: 26 additions & 8 deletions scripts/deploy-cuda.ps1
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
#!/usr/bin/env pwsh

$url = 'https://developer.download.nvidia.com/compute/cuda/11.5.0/network_installers/cuda_11.5.0_win10_network.exe'
param (
[switch]$DisableVisualStudioFeatures = $false,
[switch]$DisableSilentMode = $false
)

$CudaFeatures = 'nvcc_11.5 cuobjdump_11.5 nvprune_11.5 cupti_11.5 memcheck_11.5 nvdisasm_11.5 nvprof_11.5 ' + `
'visual_studio_integration_11.5 visual_profiler_11.5 visual_profiler_11.5 cublas_11.5 cublas_dev_11.5 ' + `
'cudart_11.5 cufft_11.5 cufft_dev_11.5 curand_11.5 curand_dev_11.5 cusolver_11.5 cusolver_dev_11.5 ' + `
'cusparse_11.5 cusparse_dev_11.5 npp_11.5 npp_dev_11.5 nvrtc_11.5 nvrtc_dev_11.5 nvml_dev_11.5 ' + `
'occupancy_calculator_11.5 '
$url = 'https://developer.download.nvidia.com/compute/cuda/11.6.1/network_installers/cuda_11.6.1_windows_network.exe'

$CudaFeatures = 'nvcc_11.6 cuobjdump_11.6 nvprune_11.6 cupti_11.6 memcheck_11.6 nvdisasm_11.6 nvprof_11.6 ' + `
'cublas_11.6 cublas_dev_11.6 nvjpeg_11.6 nvjpeg_dev_11.6 nvtx_11.6 cuxxfilt_11.6 sanitizer_11.6 ' + `
'cudart_11.6 cufft_11.6 cufft_dev_11.6 curand_11.6 curand_dev_11.6 cusolver_11.6 cusolver_dev_11.6 ' + `
'cusparse_11.6 cusparse_dev_11.6 npp_11.6 npp_dev_11.6 nvrtc_11.6 nvrtc_dev_11.6 nvml_dev_11.6 ' + `
'occupancy_calculator_11.6 documentation_11.6 '

if (-Not $DisableVisualStudioFeatures) {
$CudaFeatures = $CudaFeatures + 'visual_studio_integration_11.6 visual_profiler_11.6 '
}

if ($DisableSilentMode) {
$SilentFlag = ' '
}
else {
$SilentFlag = '-s '
}

try {
Push-Location $PSScriptRoot
Write-Host 'Downloading CUDA...'
Invoke-WebRequest -Uri $url -OutFile "cuda_11.5.0_win10_network.exe"
Invoke-WebRequest -Uri $url -OutFile "cuda_11.6.1_windows_network.exe"
Write-Host 'Installing CUDA...'
$proc = Start-Process -PassThru -FilePath "./cuda_11.5.0_win10_network.exe" -ArgumentList @('-s ' + $CudaFeatures)
$proc = Start-Process -PassThru -FilePath "./cuda_11.6.1_windows_network.exe" -ArgumentList @($SilentFlag + $CudaFeatures)
$proc.WaitForExit()
$exitCode = $proc.ExitCode
Pop-Location
if ($exitCode -eq 0) {
Write-Host 'Installation successful!'
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/requested_cuda_version.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

export CUDA_VERSION="11.5"
export CUDA_VERSION="11.6"
export CUDA_VERSION_DASHED="${CUDA_VERSION//./-}"
8 changes: 4 additions & 4 deletions scripts/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ if ($null -eq (Get-Command "choco.exe" -ErrorAction SilentlyContinue)) {
}

Start-Process -FilePath "choco" -Verb runAs -ArgumentList " install -y cmake ninja powershell git vscode"
Start-Process -FilePath "choco" -Verb runAs -ArgumentList " install -y visualstudio2019buildtools --package-parameters `"--add Microsoft.VisualStudio.Component.VC.CoreBuildTools --includeRecommended --includeOptional --passive --locale en-US --lang en-US`""
Start-Process -FilePath "choco" -Verb runAs -ArgumentList " install -y visualstudio2022buildtools --package-parameters `"--add Microsoft.VisualStudio.Component.VC.CoreBuildTools --includeRecommended --includeOptional --passive --locale en-US --lang en-US`""
Push-Location $PSScriptRoot

if ($InstallCUDA) {
& $PSScriptRoot/deploy-cuda.ps1
$env:CUDA_PATH="C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5"
$env:CUDA_TOOLKIT_ROOT_DIR="C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5"
$env:CUDACXX="C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5\\bin\\nvcc.exe"
$env:CUDA_PATH="C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6"
$env:CUDA_TOOLKIT_ROOT_DIR="C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6"
$env:CUDACXX="C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6\\bin\\nvcc.exe"
$CUDAisAvailable = $true
}
else {
Expand Down