Content-Length: 465008 | pFad | http://github.com/opencv/opencv/pull/26966/files

17 add MATCH_CUDA_MINOR_VERSION, resolve #26965 by braindevices · Pull Request #26966 · opencv/opencv · GitHub
Skip to content

add MATCH_CUDA_MINOR_VERSION, resolve #26965 #26966

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

Open
wants to merge 5 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module ei
OCV_OPTION(WITH_CUDA "Include NVidia Cuda Runtime support" OFF
VISIBLE_IF NOT IOS AND NOT XROS AND NOT WINRT
VERIFY HAVE_CUDA)
OCV_OPTION(MATCH_CUDA_MINOR_VERSION "Require match the cuda minor version to link against produced libraries." ON
VISIBLE_IF WITH_CUDA)
OCV_OPTION(WITH_CUFFT "Include NVidia Cuda Fast Fourier Transform (FFT) library support" WITH_CUDA
VISIBLE_IF WITH_CUDA
VERIFY HAVE_CUFFT)
Expand Down
29 changes: 29 additions & 0 deletions cmake/OpenCVFindLibsPerf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ if(WITH_IPP)
endif()

# --- CUDA ---
# Function to calculate the version range based on match_minor flag
function(get_version_range version match_minor lower_bound upper_bound)
# Split the version into components
string(REPLACE "." ";" version_list ${version})
list(LENGTH version_list version_length)

# Extract major and minor components
list(GET version_list 0 major)
if(version_length GREATER 1)
list(GET version_list 1 minor)
else()
set(minor 0) # Default minor to 0 if not provided
endif()

# Determine the range based on match_minor flag
if(match_minor)
# Match minor: range is [major.minor, major.<minor + 1>)
math(EXPR new_minor "${minor} + 1")
set(${lower_bound} "${major}.${minor}" PARENT_SCOPE)
set(${upper_bound} "${major}.${new_minor}" PARENT_SCOPE)
else()
# Do not match minor: range is [major, <major + 1>)
math(EXPR new_major "${major} + 1")
set(${lower_bound} "${major}" PARENT_SCOPE)
set(${upper_bound} "${new_major}" PARENT_SCOPE)
endif()
Comment on lines +62 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

I propose for the case when match_minor is off use range major.minor...major+1.0. NVidia may introduce backward compatible change, but not forward compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is why the match_minor by default is ON. But the user can choose to ignore minor version.

Personally, I never encounter API incompatibility during minor version update. The case the application breaks due to cuda toolkit update is the PTX, which is actually a problem of system maintenance: you simply should not update cuda toolkit without update driver.

Other kind of breakage is due to bugs introduced in each minor version, but then it is not API breakage, the library still be able to link to whatever minor version. If one knows some version give out wrong executing result they on should just choose a different version when he compile his code, as library provider we should not care.

endfunction()

if(WITH_CUDA)
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVDetectCUDALanguage.cmake")
Expand All @@ -51,6 +79,7 @@ CUDA support will be disabled in OpenCV build.
To eliminate this warning remove WITH_CUDA=ON CMake configuration option.
")
endif()
get_version_range(${CUDA_VERSION_STRING} ${MATCH_CUDA_MINOR_VERSION} CUDA_VERSION_MIN CUDA_VERSION_MAX)
endif(WITH_CUDA)

# --- Eigen ---
Expand Down
8 changes: 5 additions & 3 deletions cmake/templates/OpenCVConfig-CUDA.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
set(OpenCV_COMPUTE_CAPABILITIES "@OpenCV_CUDA_CC@")

set(OpenCV_CUDA_VERSION "@CUDA_VERSION_STRING@")
set(OpenCV_CUDA_VERSION_MIN "@CUDA_VERSION_MIN@")
set(OpenCV_CUDA_VERSION_MAX "@CUDA_VERSION_MAX@")
set(OpenCV_USE_CUBLAS "@HAVE_CUBLAS@")
set(OpenCV_USE_CUFFT "@HAVE_CUFFT@")
set(OpenCV_USE_NVCUVID "@HAVE_NVCUVID@")
Expand All @@ -10,10 +12,10 @@ set(OpenCV_CUDNN_VERSION "@CUDNN_VERSION@")
set(OpenCV_USE_CUDNN "@HAVE_CUDNN@")

if(NOT CUDA_FOUND)
find_host_package(CUDA ${OpenCV_CUDA_VERSION} EXACT REQUIRED)
find_host_package(CUDA ${OpenCV_CUDA_VERSION_MIN} EXACT REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

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

From CMake documentation:

The EXACT option requests that the version be matched exactly. This option is incompatible with the specification of a version range.

The option is redundant for the case with softer case, if minor version is included.

Copy link
Contributor Author

@braindevices braindevices Feb 24, 2025

Choose a reason for hiding this comment

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

as I tested: find_host_package(CUDA 12 EXACT REQUIRED) find whatever 12.x, it does not care the minor
find_host_package(CUDA 12.6 EXACT REQUIRED) find whatever 12.6 it does not care the patch version.
the newly introduced get_version_range does not give you minor version if match_minor==OFF, and give you the exact minor version the CUDA_VERSION_STRING give out if match_minor==ON.

else()
if(NOT CUDA_VERSION_STRING VERSION_EQUAL OpenCV_CUDA_VERSION)
message(FATAL_ERROR "OpenCV static library was compiled with CUDA ${OpenCV_CUDA_VERSION} support. Please, use the same version or rebuild OpenCV with CUDA ${CUDA_VERSION_STRING}")
if(CUDA_VERSION_STRING VERSION_GREATER_EQUAL OpenCV_CUDA_VERSION_MAX OR CUDA_VERSION_STRING VERSION_LESS OpenCV_CUDA_VERSION_MIN)
message(FATAL_ERROR "OpenCV static library was compiled with CUDA ${OpenCV_CUDA_VERSION} support. Please, use the version >=${OpenCV_CUDA_VERSION_MIN} <{OpenCV_CUDA_VERSION_MAX} or rebuild OpenCV with CUDA ${CUDA_VERSION_STRING}")
endif()
endif()

Expand Down
8 changes: 5 additions & 3 deletions cmake/templates/OpenCVConfig-CUDALanguage.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
set(OpenCV_COMPUTE_CAPABILITIES "@OpenCV_CUDA_CC@")

set(OpenCV_CUDA_VERSION "@CUDA_VERSION_STRING@")
set(OpenCV_CUDA_VERSION_MIN "@CUDA_VERSION_MIN@")
set(OpenCV_CUDA_VERSION_MAX "@CUDA_VERSION_MAX@")
set(OpenCV_USE_CUBLAS "@HAVE_CUBLAS@")
set(OpenCV_USE_CUFFT "@HAVE_CUFFT@")
set(OpenCV_USE_NVCUVID "@HAVE_NVCUVID@")
Expand All @@ -17,15 +19,15 @@ if(NOT CUDAToolkit_FOUND)
set(CUDA_PATH "/usr/local/cuda" CACHE INTERNAL "")
set(ENV{CUDA_PATH} ${CUDA_PATH})
endif()
find_package(CUDAToolkit ${OpenCV_CUDA_VERSION} EXACT REQUIRED)
find_package(CUDAToolkit ${OpenCV_CUDA_VERSION_MIN} EXACT REQUIRED)
else()
message(FATAL_ERROR "Using OpenCV compiled with CUDA as first class language requires CMake \>= 3.18.")
endif()
else()
if(CUDAToolkit_FOUND)
set(CUDA_VERSION_STRING ${CUDAToolkit_VERSION})
endif()
if(NOT CUDA_VERSION_STRING VERSION_EQUAL OpenCV_CUDA_VERSION)
message(FATAL_ERROR "OpenCV library was compiled with CUDA ${OpenCV_CUDA_VERSION} support. Please, use the same version or rebuild OpenCV with CUDA ${CUDA_VERSION_STRING}")
if(CUDA_VERSION_STRING VERSION_GREATER_EQUAL OpenCV_CUDA_VERSION_MAX OR CUDA_VERSION_STRING VERSION_LESS OpenCV_CUDA_VERSION_MIN)
message(FATAL_ERROR "OpenCV library was compiled with CUDA ${OpenCV_CUDA_VERSION} support. Please, use the version >=${OpenCV_CUDA_VERSION_MIN} <{OpenCV_CUDA_VERSION_MAX} or rebuild OpenCV with CUDA ${CUDA_VERSION_STRING}")
endif()
endif()
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/opencv/opencv/pull/26966/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy