diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index f9d1788b..fa6e74c2 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -655,9 +655,9 @@ jobs: - name: 'Build' env: - 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" + CUDA_PATH: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.7" + CUDA_TOOLKIT_ROOT_DIR: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.7" + CUDACXX: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.7\\bin\\nvcc.exe" shell: pwsh run: ${{ github.workspace }}/build.ps1 -EnableCUDA -DisableInteractive -DoNotUpdateDARKNET diff --git a/.github/workflows/on_pr.yml b/.github/workflows/on_pr.yml index e8bafb17..b777d315 100644 --- a/.github/workflows/on_pr.yml +++ b/.github/workflows/on_pr.yml @@ -408,9 +408,9 @@ jobs: - name: 'Build' env: - 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" + CUDA_PATH: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.7" + CUDA_TOOLKIT_ROOT_DIR: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.7" + CUDACXX: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.7\\bin\\nvcc.exe" shell: pwsh run: ${{ github.workspace }}/build.ps1 -EnableCUDA -DisableInteractive -DoNotUpdateDARKNET diff --git a/CMakeLists.txt b/CMakeLists.txt index d34b8f80..128415cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ elseif(WIN32) set(USE_INTEGRATED_LIBS "TRUE" CACHE BOOL "Use libs distributed with this repo") else() message(WARNING "vcpkg not found, toolchain not defined, system not win32 so build might fail") - set(USE_INTEGRATED_LIBS "FALSE" CACHE BOOL "Use libs distributed with this repo") + set(USE_INTEGRATED_LIBS "TRUE" CACHE BOOL "Use libs distributed with this repo") endif() project(Darknet VERSION ${Darknet_VERSION}) @@ -112,7 +112,9 @@ enable_language(C) enable_language(CXX) set(CMAKE_CXX_STANDARD 11) -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH}) +if(USE_INTEGRATED_LIBS) + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH}) +endif() if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_COMPILER_IS_GNUCC_OR_CLANG TRUE) @@ -193,16 +195,14 @@ endif() if(USE_INTEGRATED_LIBS) set(PThreads4W_ROOT ${CMAKE_CURRENT_LIST_DIR}/3rdparty/pthreads CACHE PATH "Path where pthreads for windows can be located") + set(Stb_DIR ${CMAKE_CURRENT_LIST_DIR}/3rdparty/stb CACHE PATH "Path where Stb image library can be located") endif() -set(Stb_DIR ${CMAKE_CURRENT_LIST_DIR}/3rdparty/stb CACHE PATH "Path where Stb image library can be located") set(CMAKE_DEBUG_POSTFIX d) set(CMAKE_THREAD_PREFER_PTHREAD ON) find_package(Threads REQUIRED) -if(MSVC AND USE_INTEGRATED_LIBS) +if(MSVC) find_package(PThreads4W REQUIRED) -elseif(MSVC) - find_package(pthreads REQUIRED) endif() if(ENABLE_OPENCV) find_package(OpenCV REQUIRED) @@ -476,11 +476,11 @@ if(CMAKE_COMPILER_IS_GNUCC) endif() if(MSVC) - target_link_libraries(darknet PRIVATE PThreads_windows::PThreads_windows) + target_link_libraries(darknet PRIVATE PThreads4W::PThreads4W) target_link_libraries(darknet PRIVATE wsock32) - target_link_libraries(dark PUBLIC PThreads_windows::PThreads_windows) + target_link_libraries(dark PUBLIC PThreads4W::PThreads4W) target_link_libraries(dark PUBLIC wsock32) - target_link_libraries(uselib PRIVATE PThreads_windows::PThreads_windows) + target_link_libraries(uselib PRIVATE PThreads4W::PThreads4W) target_compile_definitions(darknet PRIVATE -D_CRT_RAND_S -DNOMINMAX -D_USE_MATH_DEFINES) target_compile_definitions(dark PRIVATE -D_CRT_RAND_S -DNOMINMAX -D_USE_MATH_DEFINES) target_compile_definitions(dark PUBLIC -D_CRT_SECURE_NO_WARNINGS) @@ -515,7 +515,7 @@ if(ENABLE_CUDA) target_compile_definitions(dark PUBLIC -DGPU) endif() -if(USE_INTEGRATED_LIBS) +if(USE_INTEGRATED_LIBS AND WIN32) target_compile_definitions(darknet PRIVATE -D_TIMESPEC_DEFINED) target_compile_definitions(dark PRIVATE -D_TIMESPEC_DEFINED) endif() @@ -535,7 +535,7 @@ if(OpenCV_FOUND AND OpenCV_VERSION VERSION_GREATER "3.0" AND BUILD_USELIB_TRACK) target_compile_definitions(uselib_track PRIVATE -DZED_STEREO) endif() if(MSVC) - target_link_libraries(uselib_track PRIVATE PThreads_windows::PThreads_windows) + target_link_libraries(uselib_track PRIVATE PThreads4W::PThreads4W) target_compile_definitions(uselib_track PRIVATE -D_CRT_RAND_S -DNOMINMAX -D_USE_MATH_DEFINES) endif() target_link_libraries(uselib_track PRIVATE Threads::Threads) diff --git a/DarknetConfig.cmake.in b/DarknetConfig.cmake.in index 12212069..ffd34098 100644 --- a/DarknetConfig.cmake.in +++ b/DarknetConfig.cmake.in @@ -24,11 +24,7 @@ set(CMAKE_THREAD_PREFER_PTHREAD ON) find_dependency(Threads) if(MSVC) - if(@USE_INTEGRATED_LIBS@) - find_dependency(PThreads4W) - else() - find_dependency(pthreads) - endif() + find_dependency(PThreads4W) set(CMAKE_CXX_FLAGS "/wd4018 /wd4244 /wd4267 /wd4305 ${CMAKE_CXX_FLAGS}") endif() diff --git a/build.ps1 b/build.ps1 index 9b774aa8..c9efaddd 100755 --- a/build.ps1 +++ b/build.ps1 @@ -127,90 +127,15 @@ param ( [string]$AdditionalBuildSetup = "" # "-DCMAKE_CUDA_ARCHITECTURES=30" ) -$build_ps1_version = "1.9.8" +$build_ps1_version = "2.0.0" +Import-Module -Name $PSScriptRoot/scripts/utils.psm1 -Force $ErrorActionPreference = "SilentlyContinue" Stop-Transcript | out-null $ErrorActionPreference = "Continue" Start-Transcript -Path $PSScriptRoot/build.log -Function MyThrow ($Message) { - if ($DisableInteractive) { - Write-Host $Message -ForegroundColor Red - throw - } - else { - # Check if running in PowerShell ISE - if ($psISE) { - # "ReadKey" not supported in PowerShell ISE. - # Show MessageBox UI - $Shell = New-Object -ComObject "WScript.Shell" - $Shell.Popup($Message, 0, "OK", 0) - throw - } - - $Ignore = - 16, # Shift (left or right) - 17, # Ctrl (left or right) - 18, # Alt (left or right) - 20, # Caps lock - 91, # Windows key (left) - 92, # Windows key (right) - 93, # Menu key - 144, # Num lock - 145, # Scroll lock - 166, # Back - 167, # Forward - 168, # Refresh - 169, # Stop - 170, # Search - 171, # Favorites - 172, # Start/Home - 173, # Mute - 174, # Volume Down - 175, # Volume Up - 176, # Next Track - 177, # Previous Track - 178, # Stop Media - 179, # Play - 180, # Mail - 181, # Select Media - 182, # Application 1 - 183 # Application 2 - - Write-Host $Message -ForegroundColor Red - Write-Host -NoNewline "Press any key to continue..." - while (($null -eq $KeyInfo.VirtualKeyCode) -or ($Ignore -contains $KeyInfo.VirtualKeyCode)) { - $KeyInfo = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown") - } - Write-Host "" - throw - } -} - -Function DownloadNinja() { - Write-Host "Unable to find Ninja, downloading a portable version on-the-fly" -ForegroundColor Yellow - Remove-Item -Force -Recurse -ErrorAction SilentlyContinue ninja - Remove-Item -Force -ErrorAction SilentlyContinue ninja.zip - if ($IsWindows -or $IsWindowsPowerShell) { - $url = "https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip" - } - elseif ($IsLinux) { - $url = "https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-linux.zip" - } - elseif ($IsMacOS) { - $url = "https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-mac.zip" - } - else { - MyThrow("Unknown OS, unsupported") - } - Invoke-RestMethod -Uri $url -Method Get -ContentType application/zip -OutFile "ninja.zip" - Expand-Archive -Path ninja.zip - Remove-Item -Force -ErrorAction SilentlyContinue ninja.zip -} - - -Write-Host "Build script version ${build_ps1_version}" +Write-Host "Build script version ${build_ps1_version}, utils module version ${utils_psm1_version}" if ((-Not $DisableInteractive) -and (-Not $UseVCPKG)) { $Result = Read-Host "Enable vcpkg to install dependencies (yes/no)" @@ -464,90 +389,6 @@ if (-Not $DoNotUseNinja) { } } -function getProgramFiles32bit() { - $out = ${env:PROGRAMFILES(X86)} - if ($null -eq $out) { - $out = ${env:PROGRAMFILES} - } - - if ($null -eq $out) { - MyThrow("Could not find [Program Files 32-bit]") - } - - return $out -} - -function getLatestVisualStudioWithDesktopWorkloadPath() { - $programFiles = getProgramFiles32bit - $vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe" - if (Test-Path $vswhereExe) { - $output = & $vswhereExe -products * -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -format xml - [xml]$asXml = $output - foreach ($instance in $asXml.instances.instance) { - $installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash - } - if (!$installationPath) { - Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also partial installations" -ForegroundColor Yellow - $output = & $vswhereExe -products * -latest -format xml - [xml]$asXml = $output - foreach ($instance in $asXml.instances.instance) { - $installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash - } - } - if (!$installationPath) { - Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also pre-release installations" -ForegroundColor Yellow - $output = & $vswhereExe -prerelease -products * -latest -format xml - [xml]$asXml = $output - foreach ($instance in $asXml.instances.instance) { - $installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash - } - } - if (!$installationPath) { - MyThrow("Could not locate any installation of Visual Studio") - } - } - else { - MyThrow("Could not locate vswhere at $vswhereExe") - } - return $installationPath -} - - -function getLatestVisualStudioWithDesktopWorkloadVersion() { - $programFiles = getProgramFiles32bit - $vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe" - if (Test-Path $vswhereExe) { - $output = & $vswhereExe -products * -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -format xml - [xml]$asXml = $output - foreach ($instance in $asXml.instances.instance) { - $installationVersion = $instance.InstallationVersion - } - if (!$installationVersion) { - Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also partial installations" -ForegroundColor Yellow - $output = & $vswhereExe -products * -latest -format xml - [xml]$asXml = $output - foreach ($instance in $asXml.instances.instance) { - $installationVersion = $instance.installationVersion - } - } - if (!$installationVersion) { - Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also pre-release installations" -ForegroundColor Yellow - $output = & $vswhereExe -prerelease -products * -latest -format xml - [xml]$asXml = $output - foreach ($instance in $asXml.instances.instance) { - $installationVersion = $instance.installationVersion - } - } - if (!$installationVersion) { - MyThrow("Could not locate any installation of Visual Studio") - } - } - else { - MyThrow("Could not locate vswhere at $vswhereExe") - } - return $installationVersion -} - $vcpkg_root_set_by_this_script = $false if ((Test-Path env:VCPKG_ROOT) -and $UseVCPKG) { diff --git a/cmake/Modules/FindPThreads4W.cmake b/cmake/Modules/FindPThreads4W.cmake index 18e2b77c..ef20cc2c 100644 --- a/cmake/Modules/FindPThreads4W.cmake +++ b/cmake/Modules/FindPThreads4W.cmake @@ -24,12 +24,6 @@ # ``PThreads4W_LIBRARY`` # List of libraries to link with when using PThreads4W (no exception handling) # -# ``PThreads4W_CXXEXC_LIBRARY`` -# List of libraries to link with when using PThreads4W (C++ exception handling) -# -# ``PThreads4W_STRUCTEXC_LIBRARY`` -# List of libraries to link with when using PThreads4W (struct exception handling) -# # Result Targets # ^^^^^^^^^^^^^^^^ # @@ -38,12 +32,6 @@ # ``PThreads4W::PThreads4W`` # Target to use PThreads4W (no exception handling) # -# ``PThreads4W::PThreads4W_CXXEXC`` -# Target to use PThreads4W (C++ exception handling) -# -# ``PThreads4W::PThreads4W_STRUCTEXC`` -# Target to use PThreads4W (struct exception handling) -# include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake) @@ -60,170 +48,32 @@ set(PThreads4W_VERSION "${PThreads4W_MAJOR_VERSION}.${PThreads4W_MINOR_VERSION}. # Allow libraries to be set manually if(NOT PThreads4W_LIBRARY) find_library(PThreads4W_LIBRARY NAMES pthreadVC${PThreads4W_MAJOR_VERSION}) - find_library(PThreads4W_LIBRARY_RELEASE NAMES pthreadVC${PThreads4W_MAJOR_VERSION}) -endif() -if(NOT PThreads4W_CXXEXC_LIBRARY) - find_library(PThreads4W_CXXEXC_LIBRARY_RELEASE NAMES pthreadVCE${PThreads4W_MAJOR_VERSION}) - find_library(PThreads4W_CXXEXC_LIBRARY_DEBUG NAMES pthreadVCE${PThreads4W_MAJOR_VERSION}d) - select_library_configurations(PThreads4W_CXXEXC) -endif() -if(NOT PThreads4W_STRUCTEXC_LIBRARY) - find_library(PThreads4W_STRUCTEXC_LIBRARY_RELEASE NAMES pthreadVSE${PThreads4W_MAJOR_VERSION}) - find_library(PThreads4W_STRUCTEXC_LIBRARY_DEBUG NAMES pthreadVSE${PThreads4W_MAJOR_VERSION}d) - select_library_configurations(PThreads4W_STRUCTEXC) endif() find_package_handle_standard_args(PThreads4W DEFAULT_MSG PThreads4W_LIBRARY PThreads4W_INCLUDE_DIR) -mark_as_advanced(PThreads4W_INCLUDE_DIR PThreads4W_LIBRARY) +mark_as_advanced(PThreads4W_INCLUDE_DIR PThreads4W_LIBRARY ) set(PThreads4W_DLL_DIR ${PThreads4W_INCLUDE_DIR}) list(TRANSFORM PThreads4W_DLL_DIR APPEND "/../bin") message(STATUS "PThreads4W_DLL_DIR: ${PThreads4W_DLL_DIR}") -set(PThreads4W_DEBUG_DLL_DIR ${PThreads4W_INCLUDE_DIR}) -list(TRANSFORM PThreads4W_DEBUG_DLL_DIR APPEND "/../debug/bin") -message(STATUS "PThreads4W_DEBUG_DLL_DIR: ${PThreads4W_DEBUG_DLL_DIR}") -find_file(PThreads4W_LIBRARY_RELEASE_DLL NAMES pthreadVC${PThreads4W_MAJOR_VERSION}.dll PATHS ${PThreads4W_DLL_DIR}) -find_file(PThreads4W_LIBRARY_DEBUG_DLL NAMES pthreadVC${PThreads4W_MAJOR_VERSION}d.dll PATHS ${PThreads4W_DEBUG_DLL_DIR}) -find_file(PThreads4W_CXXEXC_LIBRARY_RELEASE_DLL NAMES pthreadVCE${PThreads4W_MAJOR_VERSION}.dll PATHS ${PThreads4W_DLL_DIR}) -find_file(PThreads4W_CXXEXC_LIBRARY_DEBUG_DLL NAMES pthreadVCE${PThreads4W_MAJOR_VERSION}d.dll PATHS ${PThreads4W_DEBUG_DLL_DIR}) -find_file(PThreads4W_STRUCTEXC_LIBRARY_RELEASE_DLL NAMES pthreadVSE${PThreads4W_MAJOR_VERSION}.dll PATHS ${PThreads4W_DLL_DIR}) -find_file(PThreads4W_STRUCTEXC_LIBRARY_DEBUG_DLL NAMES pthreadVSE${PThreads4W_MAJOR_VERSION}d.dll PATHS ${PThreads4W_DEBUG_DLL_DIR}) - -#Compatibility definitions, deprecated -set(PTHREAD_INCLUDE_DIR ${PThreads4W_INCLUDE_DIR} CACHE PATH "") -set(PTHREADS_INCLUDE_DIR ${PThreads4W_INCLUDE_DIR} CACHE PATH "") -set(PThreads_windows_INCLUDE_DIR ${PThreads4W_INCLUDE_DIR} CACHE PATH "") -set(PTHREAD_LIBRARIES ${PThreads4W_LIBRARY} CACHE STRING "") -set(PTHREADS_LIBRARIES ${PThreads4W_LIBRARY} CACHE STRING "") -set(PTHREAD_LIBRARY ${PThreads4W_LIBRARY} CACHE STRING "") -set(PTHREADS_LIBRARY ${PThreads4W_LIBRARY} CACHE STRING "") -set(LIBPTHREAD ${PThreads4W_LIBRARY} CACHE STRING "") -set(LIBPTHREADS ${PThreads4W_LIBRARY} CACHE STRING "") -set(PThreads_windows_LIBRARY ${PThreads4W_LIBRARY} CACHE STRING "") -set(PThreads_VERSION "${PThreads4W_VERSION}") -if(PThreads4W_FOUND) - set(PThreads_windows_FOUND TRUE) -endif() - -#TARGETS -if( PThreads4W_FOUND AND NOT TARGET PThreads4W::PThreads4W_CXXEXC ) - if( EXISTS "${PThreads4W_CXXEXC_LIBRARY_RELEASE_DLL}" ) - add_library( PThreads4W::PThreads4W_CXXEXC SHARED IMPORTED ) - set_target_properties( PThreads4W::PThreads4W_CXXEXC PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads4W_CXXEXC_LIBRARY_RELEASE_DLL}" - IMPORTED_IMPLIB "${PThreads4W_CXXEXC_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads4W_CXXEXC_LIBRARY_DEBUG_DLL}" ) - set_property( TARGET PThreads4W::PThreads4W_CXXEXC APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads4W::PThreads4W_CXXEXC PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads4W_CXXEXC_LIBRARY_DEBUG_DLL}" - IMPORTED_IMPLIB_DEBUG "${PThreads4W_CXXEXC_LIBRARY_DEBUG}" ) - endif() - else() - add_library( PThreads4W::PThreads4W_CXXEXC UNKNOWN IMPORTED ) - set_target_properties( PThreads4W::PThreads4W_CXXEXC PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads4W_CXXEXC_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads4W_CXXEXC_LIBRARY_DEBUG}" ) - set_property( TARGET PThreads4W::PThreads4W_CXXEXC APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads4W::PThreads4W_CXXEXC PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads4W_CXXEXC_LIBRARY_DEBUG}" ) - endif() - endif() -endif() - -if( PThreads4W_FOUND AND NOT TARGET PThreads4W::PThreads4W_STRUCTEXC ) - if( EXISTS "${PThreads4W_STRUCTEXC_LIBRARY_RELEASE_DLL}" ) - add_library( PThreads4W::PThreads4W_STRUCTEXC SHARED IMPORTED ) - set_target_properties( PThreads4W::PThreads4W_STRUCTEXC PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads4W_STRUCTEXC_LIBRARY_RELEASE_DLL}" - IMPORTED_IMPLIB "${PThreads4W_STRUCTEXC_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG_DLL}" ) - set_property( TARGET PThreads4W::PThreads4W_STRUCTEXC APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads4W::PThreads4W_STRUCTEXC PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG_DLL}" - IMPORTED_IMPLIB_DEBUG "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG}" ) - endif() - else() - add_library( PThreads4W::PThreads4W_STRUCTEXC UNKNOWN IMPORTED ) - set_target_properties( PThreads4W::PThreads4W_STRUCTEXC PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads4W_STRUCTEXC_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG}" ) - set_property( TARGET PThreads4W::PThreads4W_STRUCTEXC APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads4W::PThreads4W_STRUCTEXC PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG}" ) - endif() - endif() -endif() +find_file(PThreads4W_LIBRARY_DLL NAMES pthreadVC${PThreads4W_MAJOR_VERSION}.dll PATHS ${PThreads4W_DLL_DIR}) if( PThreads4W_FOUND AND NOT TARGET PThreads4W::PThreads4W ) if( EXISTS "${PThreads4W_LIBRARY_RELEASE_DLL}" ) add_library( PThreads4W::PThreads4W SHARED IMPORTED ) set_target_properties( PThreads4W::PThreads4W PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE_DLL}" - IMPORTED_IMPLIB "${PThreads4W_LIBRARY_RELEASE}" + IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_DLL}" + IMPORTED_IMPLIB "${PThreads4W_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" IMPORTED_CONFIGURATIONS Release IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads4W_LIBRARY_DEBUG_DLL}" ) - set_property( TARGET PThreads4W::PThreads4W APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads4W::PThreads4W PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG_DLL}" - IMPORTED_IMPLIB_DEBUG "${PThreads4W_LIBRARY_DEBUG}" ) - endif() else() add_library( PThreads4W::PThreads4W UNKNOWN IMPORTED ) set_target_properties( PThreads4W::PThreads4W PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE}" + IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" IMPORTED_CONFIGURATIONS Release IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads4W_LIBRARY_DEBUG}" ) - set_property( TARGET PThreads4W::PThreads4W APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads4W::PThreads4W PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG}" ) - endif() - endif() -endif() - -#Compatibility targets, deprecated -if( PThreads4W_FOUND AND NOT TARGET PThreads_windows::PThreads_windows ) - if( EXISTS "${PThreads4W_LIBRARY_RELEASE_DLL}" ) - add_library( PThreads_windows::PThreads_windows SHARED IMPORTED ) - set_target_properties( PThreads_windows::PThreads_windows PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE_DLL}" - IMPORTED_IMPLIB "${PThreads4W_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads4W_LIBRARY_DEBUG_DLL}" ) - set_property( TARGET PThreads_windows::PThreads_windows APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads_windows::PThreads_windows PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG_DLL}" - IMPORTED_IMPLIB_DEBUG "${PThreads4W_LIBRARY_DEBUG}" ) - endif() - else() - add_library( PThreads_windows::PThreads_windows UNKNOWN IMPORTED ) - set_target_properties( PThreads_windows::PThreads_windows PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads4W_LIBRARY_DEBUG}" ) - set_property( TARGET PThreads_windows::PThreads_windows APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads_windows::PThreads_windows PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG}" ) - endif() endif() endif() diff --git a/scripts/deploy-cuda.ps1 b/scripts/deploy-cuda.ps1 index a460e8b3..769b0974 100644 --- a/scripts/deploy-cuda.ps1 +++ b/scripts/deploy-cuda.ps1 @@ -5,16 +5,22 @@ param ( [switch]$DisableSilentMode = $false ) -$url = 'https://developer.download.nvidia.com/compute/cuda/11.6.1/network_installers/cuda_11.6.1_windows_network.exe' +Import-Module -Name $PSScriptRoot/utils.psm1 -Force -$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 ' +$url = "https://developer.download.nvidia.com/compute/cuda/${cuda_version_full}/network_installers/cuda_${cuda_version_full}_windows_network.exe" + +$CudaFeatures = "nvcc_${cuda_version_short} cuobjdump_${cuda_version_short} nvprune_${cuda_version_short} " + ` + " cupti_${cuda_version_short} memcheck_${cuda_version_short} nvdisasm_${cuda_version_short} nvprof_${cuda_version_short} " + ` + " cublas_${cuda_version_short} cublas_dev_${cuda_version_short} nvjpeg_${cuda_version_short} nvjpeg_dev_${cuda_version_short} " + ` + " nvtx_${cuda_version_short} cuxxfilt_${cuda_version_short} sanitizer_${cuda_version_short} " + ` + " cudart_${cuda_version_short} cufft_${cuda_version_short} cufft_dev_${cuda_version_short} curand_${cuda_version_short} " + ` + " curand_dev_${cuda_version_short} cusolver_${cuda_version_short} cusolver_dev_${cuda_version_short} " + ` + " cusparse_${cuda_version_short} cusparse_dev_${cuda_version_short} npp_${cuda_version_short} npp_dev_${cuda_version_short} " + ` + " nvrtc_${cuda_version_short} nvrtc_dev_${cuda_version_short} nvml_dev_${cuda_version_short} " + ` + " occupancy_calculator_${cuda_version_short} documentation_${cuda_version_short} " if (-Not $DisableVisualStudioFeatures) { - $CudaFeatures = $CudaFeatures + 'visual_studio_integration_11.6 visual_profiler_11.6 ' + $CudaFeatures = $CudaFeatures + "visual_studio_integration_${cuda_version_short} visual_profiler_${cuda_version_short} " } if ($DisableSilentMode) { @@ -26,10 +32,10 @@ else { try { Push-Location $PSScriptRoot - Write-Host 'Downloading CUDA...' - Invoke-WebRequest -Uri $url -OutFile "cuda_11.6.1_windows_network.exe" + Write-Host "Downloading CUDA from $url..." + Invoke-WebRequest -Uri $url -OutFile "cuda_${cuda_version_full}_windows_network.exe" Write-Host 'Installing CUDA...' - $proc = Start-Process -PassThru -FilePath "./cuda_11.6.1_windows_network.exe" -ArgumentList @($SilentFlag + $CudaFeatures) + $proc = Start-Process -PassThru -FilePath "./cuda_${cuda_version_full}_windows_network.exe" -ArgumentList @($SilentFlag + $CudaFeatures) $proc.WaitForExit() $exitCode = $proc.ExitCode Pop-Location diff --git a/scripts/deploy-cuda.sh b/scripts/deploy-cuda.sh index 267e3270..1370dd55 100755 --- a/scripts/deploy-cuda.sh +++ b/scripts/deploy-cuda.sh @@ -19,16 +19,25 @@ else exit 1 fi +sudo apt-key del 7fa2af80 +wget https://developer.download.nvidia.com/compute/cuda/repos/$distr_name/x86_64/cuda-keyring_1.0-1_all.deb +sudo dpkg -i cuda-keyring_1.0-1_all.deb +sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/$distr_name/x86_64/ /" +sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/machine-learning/repos/$distr_name/x86_64/ /" +wget https://developer.download.nvidia.com/compute/cuda/repos/$distr_name/x86_64/cuda-$distr_name.pin +sudo mv cuda-${OS}.pin /etc/apt/preferences.d/cuda-repository-pin-600 +sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/$distr_name/x86_64/7fa2af80.pub +sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/$distr_name/x86_64/ /" sudo apt-get update sudo apt-get install build-essential g++ sudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget -sudo wget -O /etc/apt/preferences.d/cuda-repository-pin-600 https://developer.download.nvidia.com/compute/cuda/repos/$distr_name/x86_64/cuda-$distr_name.pin -sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/$distr_name/x86_64/7fa2af80.pub -sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/$distr_name/x86_64/ /" -sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/machine-learning/repos/$distr_name/x86_64/ /" -sudo apt-get update +sudo apt-get install zlib1g sudo apt-get dist-upgrade -y -sudo apt-get install -y --no-install-recommends cuda-compiler-${CUDA_VERSION_DASHED} cuda-libraries-dev-${CUDA_VERSION_DASHED} cuda-driver-dev-${CUDA_VERSION_DASHED} cuda-cudart-dev-${CUDA_VERSION_DASHED} -sudo apt-get install -y --no-install-recommends libcudnn8-dev +sudo apt-get install -y --no-install-recommends cuda-${CUDA_VERSION_DASHED} +#sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version} +#sudo apt-get install libcudnn8-dev=${cudnn_version}-1+cuda${CUDA_VERSION} +sudo apt-get install libcudnn8 +sudo apt-get install libcudnn8-dev + sudo rm -rf /usr/local/cuda sudo ln -s /usr/local/cuda-${CUDA_VERSION} /usr/local/cuda diff --git a/scripts/requested_cuda_version.sh b/scripts/requested_cuda_version.sh index 90f54b25..6c95e056 100755 --- a/scripts/requested_cuda_version.sh +++ b/scripts/requested_cuda_version.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash -export CUDA_VERSION="11.6" +export CUDA_VERSION="11.7" export CUDA_VERSION_DASHED="${CUDA_VERSION//./-}" +export CUDNN_VERSION="8.4.1" +export CUDNN_VERSION_DASHED="${CUDNN_VERSION//./-}" diff --git a/scripts/setup.ps1 b/scripts/setup.ps1 index 86508038..52622191 100755 --- a/scripts/setup.ps1 +++ b/scripts/setup.ps1 @@ -4,6 +4,8 @@ param ( [switch]$InstallCUDA = $false ) +Import-Module -Name $PSScriptRoot/utils.psm1 -Force + if ($null -eq (Get-Command "choco.exe" -ErrorAction SilentlyContinue)) { # Download and install Chocolatey Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) @@ -16,9 +18,9 @@ Push-Location $PSScriptRoot if ($InstallCUDA) { & $PSScriptRoot/deploy-cuda.ps1 - $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" + $env:CUDA_PATH = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v${cuda_version_short}" + $env:CUDA_TOOLKIT_ROOT_DIR = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v${cuda_version_short}" + $env:CUDACXX = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v${cuda_version_short}\\bin\\nvcc.exe" $CUDAisAvailable = $true } else { diff --git a/scripts/utils.psm1 b/scripts/utils.psm1 new file mode 100644 index 00000000..87a57d8e --- /dev/null +++ b/scripts/utils.psm1 @@ -0,0 +1,200 @@ +<# +Copyright (c) Stefano Sinigardi + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +#> + +$utils_psm1_version = "0.0.2" +$cuda_version_full = "11.7.0" +$cuda_version_short = "11.7" +$cuda_version_full_dashed = $cuda_version_full.replace('.', '-') +$cuda_version_short_dashed = $cuda_version_short.replace('.', '-') + +function getProgramFiles32bit() { + $out = ${env:PROGRAMFILES(X86)} + if ($null -eq $out) { + $out = ${env:PROGRAMFILES} + } + + if ($null -eq $out) { + MyThrow("Could not find [Program Files 32-bit]") + } + + return $out +} + +function getLatestVisualStudioWithDesktopWorkloadPath() { + $programFiles = getProgramFiles32bit + $vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe" + if (Test-Path $vswhereExe) { + $output = & $vswhereExe -products * -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -format xml + [xml]$asXml = $output + foreach ($instance in $asXml.instances.instance) { + $installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash + } + if (!$installationPath) { + Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also partial installations" -ForegroundColor Yellow + $output = & $vswhereExe -products * -latest -format xml + [xml]$asXml = $output + foreach ($instance in $asXml.instances.instance) { + $installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash + } + } + if (!$installationPath) { + Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also pre-release installations" -ForegroundColor Yellow + $output = & $vswhereExe -prerelease -products * -latest -format xml + [xml]$asXml = $output + foreach ($instance in $asXml.instances.instance) { + $installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash + } + } + if (!$installationPath) { + MyThrow("Could not locate any installation of Visual Studio") + } + } + else { + MyThrow("Could not locate vswhere at $vswhereExe") + } + return $installationPath +} + +function getLatestVisualStudioWithDesktopWorkloadVersion() { + $programFiles = getProgramFiles32bit + $vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe" + if (Test-Path $vswhereExe) { + $output = & $vswhereExe -products * -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -format xml + [xml]$asXml = $output + foreach ($instance in $asXml.instances.instance) { + $installationVersion = $instance.InstallationVersion + } + if (!$installationVersion) { + Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also partial installations" -ForegroundColor Yellow + $output = & $vswhereExe -products * -latest -format xml + [xml]$asXml = $output + foreach ($instance in $asXml.instances.instance) { + $installationVersion = $instance.installationVersion + } + } + if (!$installationVersion) { + Write-Host "Warning: no full Visual Studio setup has been found, extending search to include also pre-release installations" -ForegroundColor Yellow + $output = & $vswhereExe -prerelease -products * -latest -format xml + [xml]$asXml = $output + foreach ($instance in $asXml.instances.instance) { + $installationVersion = $instance.installationVersion + } + } + if (!$installationVersion) { + MyThrow("Could not locate any installation of Visual Studio") + } + } + else { + MyThrow("Could not locate vswhere at $vswhereExe") + } + return $installationVersion +} + +function DownloadNinja() { + Write-Host "Unable to find Ninja, downloading a portable version on-the-fly" -ForegroundColor Yellow + Remove-Item -Force -Recurse -ErrorAction SilentlyContinue ninja + Remove-Item -Force -ErrorAction SilentlyContinue ninja.zip + if ($IsWindows -or $IsWindowsPowerShell) { + $url = "https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip" + } + elseif ($IsLinux) { + $url = "https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-linux.zip" + } + elseif ($IsMacOS) { + $url = "https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-mac.zip" + } + else { + MyThrow("Unknown OS, unsupported") + } + Invoke-RestMethod -Uri $url -Method Get -ContentType application/zip -OutFile "ninja.zip" + Expand-Archive -Path ninja.zip + Remove-Item -Force -ErrorAction SilentlyContinue ninja.zip +} + +Function MyThrow ($Message) { + if ($DisableInteractive) { + Write-Host $Message -ForegroundColor Red + throw + } + else { + # Check if running in PowerShell ISE + if ($psISE) { + # "ReadKey" not supported in PowerShell ISE. + # Show MessageBox UI + $Shell = New-Object -ComObject "WScript.Shell" + $Shell.Popup($Message, 0, "OK", 0) + throw + } + + $Ignore = + 16, # Shift (left or right) + 17, # Ctrl (left or right) + 18, # Alt (left or right) + 20, # Caps lock + 91, # Windows key (left) + 92, # Windows key (right) + 93, # Menu key + 144, # Num lock + 145, # Scroll lock + 166, # Back + 167, # Forward + 168, # Refresh + 169, # Stop + 170, # Search + 171, # Favorites + 172, # Start/Home + 173, # Mute + 174, # Volume Down + 175, # Volume Up + 176, # Next Track + 177, # Previous Track + 178, # Stop Media + 179, # Play + 180, # Mail + 181, # Select Media + 182, # Application 1 + 183 # Application 2 + + Write-Host $Message -ForegroundColor Red + Write-Host -NoNewline "Press any key to continue..." + while (($null -eq $KeyInfo.VirtualKeyCode) -or ($Ignore -contains $KeyInfo.VirtualKeyCode)) { + $KeyInfo = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown") + } + Write-Host "" + throw + } +} + +Export-ModuleMember -Variable utils_psm1_version +Export-ModuleMember -Variable cuda_version_full +Export-ModuleMember -Variable cuda_version_short +Export-ModuleMember -Variable cuda_version_full_dashed +Export-ModuleMember -Variable cuda_version_short_dashed + +Export-ModuleMember -Function getProgramFiles32bit +Export-ModuleMember -Function getLatestVisualStudioWithDesktopWorkloadPath +Export-ModuleMember -Function getLatestVisualStudioWithDesktopWorkloadVersion +Export-ModuleMember -Function DownloadNinja +Export-ModuleMember -Function MyThrow +Export-ModuleMember -Function CopyTexFile