summary refs log tree commit diff
path: root/pkgs/development/libraries/opencv
diff options
context:
space:
mode:
authorSomeone Serge <sergei.kozlukov@aalto.fi>2023-02-27 14:58:14 +0200
committerSomeone Serge <sergei.kozlukov@aalto.fi>2023-03-04 00:59:21 +0200
commitd378cc6fb23d67f3d9f86c39051f810c563789ca (patch)
tree90b88b4fdcae4c21bf912cff6452317d039812ee /pkgs/development/libraries/opencv
parente305011223c940a8dd661f64eb5cd5384c15ddbe (diff)
downloadnixpkgs-d378cc6fb23d67f3d9f86c39051f810c563789ca.tar
nixpkgs-d378cc6fb23d67f3d9f86c39051f810c563789ca.tar.gz
nixpkgs-d378cc6fb23d67f3d9f86c39051f810c563789ca.tar.bz2
nixpkgs-d378cc6fb23d67f3d9f86c39051f810c563789ca.tar.lz
nixpkgs-d378cc6fb23d67f3d9f86c39051f810c563789ca.tar.xz
nixpkgs-d378cc6fb23d67f3d9f86c39051f810c563789ca.tar.zst
nixpkgs-d378cc6fb23d67f3d9f86c39051f810c563789ca.zip
opencv4: respect config.cudaCapabilities
This is needed for faster builds when debugging the opencv derivation,
and it's more consistent with other cuda-enabled packages

-DCUDA_GENERATION seems to expect architecture names, so we refactor
cudaFlags to facilitate easier extraction of the configured archnames
Diffstat (limited to 'pkgs/development/libraries/opencv')
-rw-r--r--pkgs/development/libraries/opencv/4.x.nix13
1 files changed, 12 insertions, 1 deletions
diff --git a/pkgs/development/libraries/opencv/4.x.nix b/pkgs/development/libraries/opencv/4.x.nix
index ac021c2b610..a9f7b0304e8 100644
--- a/pkgs/development/libraries/opencv/4.x.nix
+++ b/pkgs/development/libraries/opencv/4.x.nix
@@ -37,7 +37,7 @@
 , enableContrib ? true
 
 , enableCuda ? (config.cudaSupport or false) && stdenv.hostPlatform.isx86_64
-, cudatoolkit
+, cudaPackages ? { }
 , nvidia-optical-flow-sdk
 
 , enableUnfree ? false
@@ -79,6 +79,9 @@
 }:
 
 let
+  inherit (cudaPackages) cudatoolkit;
+  inherit (cudaPackages.cudaFlags) cudaCapabilities;
+
   version = "4.7.0";
 
   src = fetchFromGitHub {
@@ -342,6 +345,14 @@ stdenv.mkDerivation {
     "-DCUDA_FAST_MATH=ON"
     "-DCUDA_HOST_COMPILER=${cudatoolkit.cc}/bin/cc"
     "-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr"
+
+    # OpenCV respects at least three variables:
+    # -DCUDA_GENERATION takes a single arch name, e.g. Volta
+    # -DCUDA_ARCH_BIN takes a semi-colon separated list of real arches, e.g. "8.0;8.6"
+    # -DCUDA_ARCH_PTX takes the virtual arch, e.g. "8.6"
+    "-DCUDA_ARCH_BIN=${lib.concatStringsSep ";" cudaCapabilities}"
+    "-DCUDA_ARCH_PTX=${lib.last cudaCapabilities}"
+
     "-DNVIDIA_OPTICAL_FLOW_2_0_HEADERS_PATH=${nvidia-optical-flow-sdk}"
   ] ++ lib.optionals stdenv.isDarwin [
     "-DWITH_OPENCL=OFF"