-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
opencv: misc CUDA-related updates and fixes; add enableLto #221370
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
Merged
samuela
merged 2 commits into
NixOS:staging
from
ConnorBaker:feat/opencv-use-cudaPackages-staging-reland
Mar 30, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,9 +37,14 @@ | |
| , enableContrib ? true | ||
|
|
||
| , enableCuda ? (config.cudaSupport or false) && stdenv.hostPlatform.isx86_64 | ||
| , cudaPackages ? { } | ||
| , enableCublas ? enableCuda | ||
| , enableCudnn ? false # NOTE: CUDNN has a large impact on closure size so we disable it by default | ||
| , enableCufft ? enableCuda | ||
| , cudaPackages ? {} | ||
| , symlinkJoin | ||
| , nvidia-optical-flow-sdk | ||
|
|
||
| , enableLto ? true | ||
| , enableUnfree ? false | ||
| , enableIpp ? false | ||
| , enablePython ? false | ||
|
|
@@ -79,9 +84,6 @@ | |
| }: | ||
|
|
||
| let | ||
| inherit (cudaPackages) cudatoolkit; | ||
| inherit (cudaPackages.cudaFlags) cudaCapabilities; | ||
|
|
||
| version = "4.7.0"; | ||
|
|
||
| src = fetchFromGitHub { | ||
|
|
@@ -227,6 +229,33 @@ let | |
| #multithreaded openblas conflicts with opencv multithreading, which manifest itself in hung tests | ||
| #https://github.com/xianyi/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded | ||
| openblas_ = blas.provider.override { singleThreaded = true; }; | ||
|
|
||
| inherit (cudaPackages) backendStdenv cudaFlags cudaVersion; | ||
| inherit (cudaFlags) cudaCapabilities; | ||
|
|
||
| cuda-common-redist = with cudaPackages; [ | ||
| cuda_cccl # <thrust/*> | ||
| libnpp # npp.h | ||
| ] ++ lib.optionals enableCublas [ | ||
| libcublas # cublas_v2.h | ||
| ] ++ lib.optionals enableCudnn [ | ||
| cudnn # cudnn.h | ||
| ] ++ lib.optionals enableCufft [ | ||
| libcufft # cufft.h | ||
| ]; | ||
|
|
||
| cuda-native-redist = symlinkJoin { | ||
| name = "cuda-native-redist-${cudaVersion}"; | ||
| paths = with cudaPackages; [ | ||
| cuda_cudart # cuda_runtime.h | ||
| cuda_nvcc | ||
| ] ++ cuda-common-redist; | ||
| }; | ||
|
|
||
| cuda-redist = symlinkJoin { | ||
| name = "cuda-redist-${cudaVersion}"; | ||
| paths = cuda-common-redist; | ||
| }; | ||
| in | ||
|
|
||
| stdenv.mkDerivation { | ||
|
|
@@ -298,17 +327,18 @@ stdenv.mkDerivation { | |
| ++ lib.optionals enableTesseract [ tesseract leptonica ] | ||
| ++ lib.optional enableTbb tbb | ||
| ++ lib.optionals stdenv.isDarwin [ bzip2 AVFoundation Cocoa VideoDecodeAcceleration CoreMedia MediaToolbox ] | ||
| ++ lib.optionals enableDocs [ doxygen graphviz-nox ]; | ||
| ++ lib.optionals enableDocs [ doxygen graphviz-nox ] | ||
| ++ lib.optionals enableCuda [ cuda-redist ]; | ||
|
|
||
| propagatedBuildInputs = lib.optional enablePython pythonPackages.numpy | ||
| ++ lib.optionals enableCuda [ cudatoolkit nvidia-optical-flow-sdk ]; | ||
| ++ lib.optionals enableCuda [ nvidia-optical-flow-sdk ]; | ||
|
|
||
| nativeBuildInputs = [ cmake pkg-config unzip ] | ||
| ++ lib.optionals enablePython [ | ||
| pythonPackages.pip | ||
| pythonPackages.wheel | ||
| pythonPackages.setuptools | ||
| ]; | ||
| ] ++ lib.optionals enableCuda [ cuda-native-redist ]; | ||
|
|
||
| env.NIX_CFLAGS_COMPILE = lib.optionalString enableEXR "-I${ilmbase.dev}/include/OpenEXR"; | ||
|
|
||
|
|
@@ -338,12 +368,30 @@ stdenv.mkDerivation { | |
| (opencvFlag "OPENEXR" enableEXR) | ||
| (opencvFlag "OPENJPEG" enableJPEG2000) | ||
| "-DWITH_JASPER=OFF" # OpenCV falls back to a vendored copy of Jasper when OpenJPEG is disabled | ||
| (opencvFlag "CUDA" enableCuda) | ||
| (opencvFlag "CUBLAS" enableCuda) | ||
| (opencvFlag "TBB" enableTbb) | ||
|
|
||
| # CUDA options | ||
| (opencvFlag "CUDA" enableCuda) | ||
| (opencvFlag "CUDA_FAST_MATH" enableCuda) | ||
| (opencvFlag "CUBLAS" enableCublas) | ||
| (opencvFlag "CUDNN" enableCudnn) | ||
| (opencvFlag "CUFFT" enableCufft) | ||
|
|
||
| # LTO options | ||
| (opencvFlag "ENABLE_LTO" enableLto) | ||
| (opencvFlag "ENABLE_THIN_LTO" ( | ||
| enableLto && ( | ||
| # Only clang supports thin LTO, so we must either be using clang through the stdenv, | ||
| stdenv.cc.isClang || | ||
| # or through the backend stdenv. | ||
| (enableCuda && backendStdenv.cc.isClang) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we currently can't test this as we hard-wire cuda to gcc. H'm |
||
| ) | ||
| )) | ||
| ] ++ lib.optionals enableCuda [ | ||
| "-DCUDA_FAST_MATH=ON" | ||
| "-DCUDA_HOST_COMPILER=${cudatoolkit.cc}/bin/cc" | ||
| # We need to set the C and C++ host compilers for CUDA to the same compiler. | ||
| "-DCMAKE_C_COMPILER=${backendStdenv.cc}/bin/cc" | ||
| "-DCMAKE_CXX_COMPILER=${backendStdenv.cc}/bin/c++" | ||
| "-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr" | ||
|
|
||
| # OpenCV respects at least three variables: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.