Skip to content

Update haveCUDA() to detect CUDA support at runtime#26164

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
CSBVision:patch-7
Dec 26, 2024
Merged

Update haveCUDA() to detect CUDA support at runtime#26164
asmorkalov merged 1 commit intoopencv:4.xfrom
CSBVision:patch-7

Conversation

@CSBVision
Copy link
Copy Markdown
Contributor

A minor improvement regarding the CUDA support is required. Currently, haveCUDA() is equivalent to using the HAVE_CUDA define. However, existing code combines both checks, which implies that it is intended to do a runtime instead of a compile time check. For example:

if (preferableBackend == DNN_BACKEND_CUDA && !haveCUDA())

Instead, we should use a runtime check in haveCUDA(), similar to haveVulkan(). Doing so, we can use CUDA by default whenever available by setting OPENCV_DNN_BACKEND_DEFAULT = DNN_BACKEND_CUDA, cf. #25112. The feature is implemented by simply checking for a valid CUDA device using cudaGetDevice() and saving its return value such that this function is only called once.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@CSBVision CSBVision force-pushed the patch-7 branch 2 times, most recently from 6e99bd0 to 0cf42b0 Compare September 20, 2024 09:58
@asmorkalov asmorkalov added the category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib label Sep 20, 2024
@CSBVision
Copy link
Copy Markdown
Contributor Author

Is there any comment regarding this PR? We would like to work on some follow-up improvements, still this makes not too much sense as long as this patch isn't merged...

@asmorkalov asmorkalov added this to the 4.11.0 milestone Dec 19, 2024
@asmorkalov asmorkalov self-requested a review December 26, 2024 12:55
@asmorkalov asmorkalov self-assigned this Dec 26, 2024
@asmorkalov asmorkalov merged commit 707ab39 into opencv:4.x Dec 26, 2024
@asmorkalov asmorkalov mentioned this pull request Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: gpu/cuda (contrib) OpenCV 4.0+: moved to opencv_contrib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants