Skip to content

cmake/OpenCVDetectCUDAUtils.cmake: use IN_LIST to avoid regex matching valid capabilities#26920

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
ConnorBaker:fix/cmake-matches-uses-regex
Feb 14, 2025
Merged

cmake/OpenCVDetectCUDAUtils.cmake: use IN_LIST to avoid regex matching valid capabilities#26920
asmorkalov merged 1 commit intoopencv:4.xfrom
ConnorBaker:fix/cmake-matches-uses-regex

Conversation

@ConnorBaker
Copy link
Copy Markdown
Contributor

@ConnorBaker ConnorBaker commented Feb 13, 2025

Continuing the work started in #26820, this corrects a bug in checking for deprecated capabilities: CMake's MATCHES operator accepts a regex and the value provided was not properly escaped. This results in configuration failing when specifying CUDA_ARCH_BIN containing the capability 100 (that's 10.0), since the . in the regex 1.0 will match the middle zero in 100. Example failure:

opencv> -- CUDA: Using CUDA_ARCH_BIN=100
opencv> CMake Error at cmake/OpenCVDetectCUDAUtils.cmake:314 (message):
opencv>   CUDA: 1.0 compute capability is not supported - exclude it from ARCH/PTX
opencv>   list and re-run CMake
opencv> Call Stack (most recent call first):
opencv>   cmake/OpenCVDetectCUDAUtils.cmake:317 (ocv_wipeout_deprecated_cc)
opencv>   cmake/OpenCVDetectCUDALanguage.cmake:78 (ocv_set_cuda_arch_bin_and_ptx)
opencv>   cmake/OpenCVFindLibsPerf.cmake:44 (include)
opencv>   CMakeLists.txt:800 (include)

This PR rewrites the relevant check to use CMake's IN_LIST operator, and additionally checks against normalized versions of the capabilities with dots removed.

Although, perhaps those capabilities are old enough now that this check can be removed entirely?

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

@asmorkalov
Copy link
Copy Markdown
Contributor

CC @johnnynunez

@cudawarped
Copy link
Copy Markdown
Contributor

cudawarped commented Feb 14, 2025

@asmorkalov This is a nice feature enhancement as the current behaviour is confusing. According to the outdated documentation the compute capability should be specified with a dot. e.g. -DCUDA_ARCH_BIN=10.0, which still works, however

  1. This is confusing because the output from CMake is

    -- NVIDIA GPU arch: 100

  2. This does not work when CUDA is a first class language, i.e. -DCMAKE_CUDA_ARCHITECTURES=10.0 fails.

I've tested this fix with the depreciated FindCUDA (-DCUDA_ARCH_BIN=100) and with CUDA as a first class language (both -DCUDA_ARCH_BIN=100 and -DCMAKE_CUDA_ARCHITECTURES=100) and the configuration works.

Note: This routine to wipeout compute capabilities 10 and 21 is outdated and highly dependant on the CUDA toolkit used.

@asmorkalov asmorkalov self-requested a review February 14, 2025 08:46
@asmorkalov asmorkalov self-assigned this Feb 14, 2025
@asmorkalov asmorkalov added this to the 4.12.0 milestone Feb 14, 2025
@asmorkalov asmorkalov merged commit e4b23cf into opencv:4.x Feb 14, 2025
25 of 29 checks passed
@asmorkalov asmorkalov mentioned this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants