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

Enable nvidia-optical-flow-sdk when building opencv4 with cuda #81922

Merged
merged 2 commits into from Mar 22, 2020

Conversation

mjlbach
Copy link
Contributor

@mjlbach mjlbach commented Mar 6, 2020

Motivation for this change

fixes #81103

This adds and enables nvidia's optical flow sdk which causes cuda 4 to fail to build when cuda is enabled.

Things done

Patched CMakeLists.txt in opencv contrib to avoid trying to download opencv headers.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@mjlbach
Copy link
Contributor Author

mjlbach commented Mar 6, 2020

@tbenst

@tbenst
Copy link
Contributor

tbenst commented Mar 7, 2020

Thanks for the pull-request! I got an error at the end of the build:

In file included from /build/source/modules/core/include/opencv2/core.hpp:54,
                 from /build/source/modules/core/include/opencv2/core/cuda.hpp:51,
                 from /build/source/opencv_contrib/cudaoptflow/include/opencv2/cudaoptflow.hpp:50,
                 from /build/source/opencv_contrib/cudaoptflow/src/precomp.hpp:48,
                 from /build/source/opencv_contrib/cudaoptflow/src/nvidiaOpticalFlow.cpp:7:
/build/source/modules/core/include/opencv2/core/base.hpp:320:40: error: expected constructor, destructor, or type conversion before '(' token
  320 | #define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
      |                                        ^
/build/source/opencv_contrib/cudaoptflow/src/nvidiaOpticalFlow.cpp:15:1: note: in expansion of macro 'CV_Error'
   15 | CV_Error(cv::Error::HeaderIsNull, "Nvidia Optical Flow headers not found. Make sure cmake downloads it properly");
      | ^~~~~~~~
make[2]: *** [modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/build.make:110: modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/src/nvidiaOpticalFlow.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:5679: modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
builder for '/nix/store/7wqh2c7wfpgwknafi114kh382z5lsfw5-opencv-4.1.2.drv' failed with exit code 2
error: build of '/nix/store/7wqh2c7wfpgwknafi114kh382z5lsfw5-opencv-4.1.2.drv' failed

Full output here: https://gist.github.com/tbenst/7d53ace5b6533d7d1225429caddcc95c.

Also, could you please split into two commits? e.g. nvidia-optical-flow-sdk: init at 79c6cee80a2df9a196f20afd6b598a9810964c32 and opencv4: Enable nvidia-optical-flow-sdk when building with cuda

@mjlbach mjlbach changed the title Enable nvidia-optical-flow-sdk when building opencv4 wih cuda Enable nvidia-optical-flow-sdk when building opencv4 with cuda Mar 8, 2020
@mjlbach mjlbach changed the title Enable nvidia-optical-flow-sdk when building opencv4 with cuda Enable nvidia-optical-flow-sdk when building opencv3/4 with cuda Mar 8, 2020
@mjlbach mjlbach changed the title Enable nvidia-optical-flow-sdk when building opencv3/4 with cuda Enable nvidia-optical-flow-sdk when building opencv4 with cuda Mar 8, 2020
@tbenst
Copy link
Contributor

tbenst commented Mar 8, 2020

Build now succeeds. LGTM

@mjlbach
Copy link
Contributor Author

mjlbach commented Mar 8, 2020

@mdaiter @basvandijk would one of you be able to review? This fixes compiling opencv4 when cuda is enabled.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review-may-2019/3032/125

Copy link
Member

@veprbl veprbl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor formatting comments

pkgs/development/libraries/opencv/4.x.nix Outdated Show resolved Hide resolved
pkgs/development/libraries/opencv/4.x.nix Outdated Show resolved Hide resolved
@mjlbach
Copy link
Contributor Author

mjlbach commented Mar 21, 2020

@veprbl I think I fixed everything you mentioned except what is in the comments. Please see my latest commit for the diff, after which I'll squash.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-already-reviewed/2617/122

@veprbl veprbl merged commit 54a0e26 into NixOS:master Mar 22, 2020
@averelld
Copy link
Contributor

Could someone pick this to 20.03? The build's broken there too, and this applies cleanly and works.

@mjlbach
Copy link
Contributor Author

mjlbach commented Mar 30, 2020

@averelld done. #83733

@veprbl veprbl added the 8.has: port to stable A PR already has a backport to the stable release. label Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenCV 4 fails to build with cuda enabled due to missing NVIDIA optical flow sdk
5 participants