From b9d296e3080beb022ced7c3faddfb7836b57a265 Mon Sep 17 00:00:00 2001 From: Stefano Sinigardi Date: Sat, 20 Feb 2021 09:28:07 +0100 Subject: [PATCH] improve manifest mode --- .github/workflows/ccpp.yml | 115 ++++++++++++++++--------------------- .gitignore | 2 + CMakeLists.txt | 16 ++++-- build.ps1 | 5 +- scripts/setup.ps1 | 29 ++++------ vcpkg.json | 111 +++++++++++++++++++++++++++++++---- 6 files changed, 177 insertions(+), 101 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index c6930d9141b..29e2df1fbdf 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -376,73 +376,54 @@ jobs: buildWithCMakeArgs: '--target install' -# win-vcpkg-cuda-ninja: -# runs-on: windows-latest -# steps: -# - uses: actions/checkout@v2 -# - name: 'Install CUDA' -# run: | -# choco install cuda --version=10.2.89.20191206 -y -# $env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." -# Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" -# refreshenv -# echo "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append -# refreshenv -# echo $env:PATH -# -# - uses: lukka/get-cmake@latest -# -# - name: Restore from cache and run vcpkg -# env: -# CUDA_PATH: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2" -# CUDA_PATH_V10_2: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2" -# CUDA_TOOLKIT_ROOT_DIR: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2" -# CUDACXX: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2\\bin\\nvcc.exe" -# uses: lukka/run-vcpkg@v6 -# with: -# setupOnly: true -# vcpkgDirectory: '${{ github.workspace }}/vcpkg' -# vcpkgGitCommitId: '865de0c130f3d34174ac7a410789df3c44a27fd2' -# appendedCacheKey: ${{ hashFiles( '**/vcpkg.json' ) }} -# vcpkgTriplet: 'x64-windows' -# additionalCachedPaths: ${{ env.buildDir }}/vcpkg_installed -# -# - name: 'Build with CMake and Ninja' -# env: -# CUDA_PATH: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2" -# CUDA_PATH_V10_2: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2" -# CUDA_TOOLKIT_ROOT_DIR: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2" -# CUDACXX: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.2\\bin\\nvcc.exe" -# uses: lukka/run-cmake@v3 -# with: -# cmakeListsOrSettingsJson: CMakeListsTxtAdvanced -# cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' -# useVcpkgToolchainFile: true -# buildDirectory: '${{ runner.workspace }}/buildDirectory' -# cmakeAppendedArgs: "-GNinja -DCMAKE_BUILD_TYPE=Release -DSELECT_OPENCV_MODULES=ON" -# cmakeBuildType: 'Release' -# buildWithCMakeArgs: '--config Release --target install' -# -# - uses: actions/upload-artifact@v2 -# with: -# name: darknet-vcpkg-cuda-${{ runner.os }} -# path: cfg -# - uses: actions/upload-artifact@v2 -# with: -# name: darknet-vcpkg-cuda-${{ runner.os }} -# path: data -# - uses: actions/upload-artifact@v2 -# with: -# name: darknet-vcpkg-cuda-${{ runner.os }} -# path: ${{ github.workspace }}/*dark* -# - uses: actions/upload-artifact@v2 -# with: -# name: darknet-vcpkg-cuda-${{ runner.os }} -# path: ${{ runner.workspace }}/buildDirectory/Release/*.dll -# - uses: actions/upload-artifact@v2 -# with: -# name: darknet-vcpkg-cuda-${{ runner.os }} -# path: ${{ github.workspace }}/uselib* + win-vcpkg-ninja: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + + - uses: lukka/get-cmake@latest + + - name: Restore from cache and run vcpkg + uses: lukka/run-vcpkg@v6 + with: + setupOnly: true + vcpkgDirectory: '${{ github.workspace }}/vcpkg' + vcpkgGitCommitId: '865de0c130f3d34174ac7a410789df3c44a27fd2' + appendedCacheKey: ${{ hashFiles( '**/vcpkg.json' ) }} + vcpkgTriplet: 'x64-windows' + additionalCachedPaths: ${{ env.buildDir }}/vcpkg_installed + + - name: 'Build with CMake and Ninja' + uses: lukka/run-cmake@v3 + with: + cmakeListsOrSettingsJson: CMakeListsTxtAdvanced + cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' + useVcpkgToolchainFile: true + buildDirectory: '${{ runner.workspace }}/buildDirectory' + cmakeAppendedArgs: "-GNinja -DCMAKE_BUILD_TYPE=Release -DSELECT_OPENCV_MODULES=ON -DENABLE_CUDA=OFF" + cmakeBuildType: 'Release' + buildWithCMakeArgs: '--config Release --target install' + + - uses: actions/upload-artifact@v2 + with: + name: darknet-vcpkg-${{ runner.os }} + path: cfg + - uses: actions/upload-artifact@v2 + with: + name: darknet-vcpkg-${{ runner.os }} + path: data + - uses: actions/upload-artifact@v2 + with: + name: darknet-vcpkg-${{ runner.os }} + path: ${{ github.workspace }}/*dark* + - uses: actions/upload-artifact@v2 + with: + name: darknet-vcpkg-${{ runner.os }} + path: ${{ runner.workspace }}/buildDirectory/Release/*.dll + - uses: actions/upload-artifact@v2 + with: + name: darknet-vcpkg-${{ runner.os }} + path: ${{ github.workspace }}/uselib* win-intlibs: diff --git a/.gitignore b/.gitignore index dabf6a771e3..386c5583ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ submission/ cfg/ build/darknet/* build_*/ +vcpkg_installed/ !build/darknet/YoloWrapper.cs .fuse* *.weights @@ -33,6 +34,7 @@ build/detect_cuda_compute_capabilities.cu build/.ninja_deps build/.ninja_log build/Makefile +*/vcpkg-manifest-install.log # OS Generated # .DS_Store* diff --git a/CMakeLists.txt b/CMakeLists.txt index 05496258a46..25d41f46fcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,17 @@ 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) +if(ENABLE_OPENCV AND ENABLE_CUDA AND NOT APPLE) + list(APPEND VCPKG_MANIFEST_FEATURES "opencv-cuda") +elseif(ENABLE_CUDA AND NOT APPLE) + list(APPEND VCPKG_MANIFEST_FEATURES "cuda") +elseif(ENABLE_OPENCV) + list(APPEND VCPKG_MANIFEST_FEATURES "opencv-base") +endif() +if(ENABLE_CUDNN AND NOT APPLE) + list(APPEND VCPKG_MANIFEST_FEATURES "cudnn") +endif() + if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_COMPILER_IS_GNUCC_OR_CLANG TRUE) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") @@ -49,6 +60,7 @@ if(ENABLE_VCPKG_INTEGRATION AND DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TO #set(_VCPKG_INSTALLED_DIR ${CMAKE_CURRENT_LIST_DIR}/vcpkg CACHE STRING "") #folder for manifest-installed dependencies message(STATUS "VCPKG found: $ENV{VCPKG_ROOT}") message(STATUS "Using VCPKG integration") + message(STATUS "VCPKG_MANIFEST_FEATURES: ${VCPKG_MANIFEST_FEATURES}") set(USE_INTEGRATED_LIBS "FALSE" CACHE BOOL "Use libs distributed with this repo") elseif(DEFINED CMAKE_TOOLCHAIN_FILE) message(STATUS "Using toolchain: ${CMAKE_TOOLCHAIN_FILE}") @@ -92,17 +104,13 @@ if(ENABLE_CUDA) include(CheckLanguage) check_language(CUDA) if(NOT CMAKE_CUDA_COMPILER) - message(STATUS "PATH: $ENV{PATH}") message(STATUS "CUDA_PATH: $ENV{CUDA_PATH}") - message(STATUS "CUDA_TOOLKIT_ROOT_DIR: $ENV{CUDA_TOOLKIT_ROOT_DIR}") message(STATUS "CUDACXX: $ENV{CUDACXX}") message(FATAL_ERROR "CUDA not found, please build explicitly with -DENABLE_CUDA=OFF if you do not want CUDA.") else() enable_language(CUDA) if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "9.0") - message(STATUS "PATH: $ENV{PATH}") message(STATUS "CUDA_PATH: $ENV{CUDA_PATH}") - message(STATUS "CUDA_TOOLKIT_ROOT_DIR: $ENV{CUDA_TOOLKIT_ROOT_DIR}") 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() diff --git a/build.ps1 b/build.ps1 index ab17585c84c..a213bbe48a8 100755 --- a/build.ps1 +++ b/build.ps1 @@ -3,7 +3,7 @@ $number_of_build_workers = 8 $enable_cuda = $true $use_vcpkg = $true -$use_ninja = $false +$use_ninja = $true $force_cpp_build = $false #$additional_build_setup = " -DCMAKE_CUDA_ARCHITECTURES=30" @@ -20,7 +20,8 @@ else { if ($use_ninja) { $NINJA_EXE = Get-Command ninja | Select-Object -ExpandProperty Definition if (-Not $NINJA_EXE) { - throw "Could not find Ninja, please install it" + $use_ninja = $false + Write-Host "Could not find Ninja, using msbuild as a fallback" -ForegroundColor Yellow } else { Write-Host "Using Ninja from ${NINJA_EXE}" diff --git a/scripts/setup.ps1 b/scripts/setup.ps1 index 4de939bae92..acc29458b62 100755 --- a/scripts/setup.ps1 +++ b/scripts/setup.ps1 @@ -1,24 +1,20 @@ -## enable or disable installed components +#!/usr/bin/env pwsh -$install_choco = $true -$install_cuda = $true +$install_cuda = $false -if ($install_cuda -and -not $install_choco) { - Write-Host "If you want to install cuda without letting the script install also choco, be sure Chocolatey is already installed" -} - -########################### - -# Download and install Chocolatey -Set-ExecutionPolicy unrestricted -if ($install_choco) { +if ($null -eq (Get-Command "choco.exe" -ErrorAction SilentlyContinue)) { + # Download and install Chocolatey + Set-ExecutionPolicy unrestricted -Scope CurrentUser Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) + Write-Host "Please close and re-open powershell and then re-run setup.ps1 script" + Break } -choco.exe install -y cmake ninja powershell git vscode -choco-exe 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 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`"" if ($install_cuda) { - choco-exe install -y cuda + Start-Process -FilePath "choco" -Verb runAs -ArgumentList " install -y cuda" $features = "full" } else { @@ -30,9 +26,6 @@ else { } } -Remove-Item -r $temp_folder -Set-Location .. -Set-Location $vcpkg_folder\ git.exe clone https://github.com/microsoft/vcpkg Set-Location vcpkg .\bootstrap-vcpkg.bat -disableMetrics diff --git a/vcpkg.json b/vcpkg.json index 7f55c4d9f5a..fa593c6c083 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,19 +1,110 @@ { "name": "darknet", "version-string": "0.2.5.4", - "port-version": 1, + "port-version": 2, "homepage": "https://github.com/alexeyab/darknet", - "description": "Neural networks for object detection", + "description": "Darknet is an open source neural network framework written in C and CUDA. You only look once (YOLO) is a state-of-the-art, real-time object detection system, best example of darknet functionalities.", "dependencies": [ "stb", - "pthreads", - { - "name": "opencv", - "features": [ "ffmpeg" ] + "pthreads" + ], + "features": { + "cuda": { + "description": "Build darknet with support for CUDA", + "dependencies": [ + "cuda" + ] }, - { - "name": "cudnn", - "platform": "!osx" + "cudnn": { + "description": "Build darknet with support for cuDNN", + "dependencies": [ + "cuda", + "cudnn" + ] + }, + "opencv-base": { + "description": "Build darknet with support for latest version of OpenCV", + "dependencies": [ + { + "name": "opencv", + "features": [ + "ffmpeg" + ] + } + ] + }, + "opencv-cuda": { + "description": "Build darknet with support for latest version of CUDA-enabled OpenCV", + "dependencies": [ + { + "name": "opencv", + "features": [ + "ffmpeg" + ] + }, + { + "name": "opencv", + "features": [ + "cuda" + ] + } + ] + }, + "opencv2-base": { + "description": "Build darknet with support for OpenCV2", + "dependencies": [ + { + "name": "opencv2", + "features": [ + "ffmpeg" + ] + } + ] + }, + "opencv2-cuda": { + "description": "Build darknet with support for CUDA-enabled OpenCV2", + "dependencies": [ + { + "name": "opencv2", + "features": [ + "ffmpeg" + ] + }, + { + "name": "opencv2", + "features": [ + "cuda" + ] + } + ] + }, + "opencv3-base": { + "description": "Build darknet with support for OpenCV3", + "dependencies": [ + { + "name": "opencv3", + "features": [ + "ffmpeg" + ] + } + ] + }, + "opencv3-cuda": { + "description": "Build darknet with support for CUDA-enabled OpenCV3", + "dependencies": [ + { + "name": "opencv3", + "features": [ + "ffmpeg" + ] + }, + { + "name": "opencv3", + "features": [ + "cuda" + ] + } + ] } - ] + } }