Skip to content

cuda: Force C++17 Standard for CUDA targets when CUDA Toolkit >=12.8#27112

Merged
asmorkalov merged 2 commits intoopencv:4.xfrom
cudawarped:add_cuda_c++17
Mar 21, 2025
Merged

cuda: Force C++17 Standard for CUDA targets when CUDA Toolkit >=12.8#27112
asmorkalov merged 2 commits intoopencv:4.xfrom
cudawarped:add_cuda_c++17

Conversation

@cudawarped
Copy link
Copy Markdown
Contributor

Fix #27095.

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 asmorkalov added this to the 4.12.0 milestone Mar 20, 2025
@cudawarped cudawarped changed the title cuda: Force C++17 Standard for CUDA targets when CUDA Toolkit >=12.8 cuda: Force C++17 Standard for CUDA targets when CUDA Toolkit >=12.8 Mar 20, 2025
Comment on lines +162 to +164
if(CUDA_VERSION VERSION_GREATER_EQUAL "12.8")
list(APPEND CUDA_NVCC_FLAGS "--std=c++17")
endif()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why --std=c++11 and --std=c++14 are set for UNIX or APPLE, but --std=c++17 - for all platforms. Most probably it's a mistake.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When @opencv-alalek first introduced the additional check it was for these two platforms. I couldn't determine a reason why it wasn't required for Windows. In the end to avoid having to test/install many versions of the Tookit on both platforms and because this is the depreciated FindCuda approach I decided to leave the existing checks as they are to be 100% that it wouldn't break any existing user code.

I can simply apply the condition to all platforms if you want?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps Windows requires other flags (of there is similar problem - need Windows configuration to check that first).

BTW, We use CMAKE_CXX_STANDARD variable for general C++ code:

https://github.com/opencv/opencv/blob/4.11.0/cmake/OpenCVDetectCXXCompiler.cmake#L211

May be we should have proper try_compile() check for nvcc?

Perhaps CMAKE_CXX_STANDARD should be tuned (or checked/forced) instead of manual flags

@asmorkalov asmorkalov self-assigned this Mar 21, 2025
@asmorkalov asmorkalov merged commit 1d9dda3 into opencv:4.x Mar 21, 2025
27 of 28 checks passed
@cudawarped
Copy link
Copy Markdown
Contributor Author

@asmorkalov The original issue was for builds on Windows. Your additional changes prevent this from working on Windows?

@asmorkalov
Copy link
Copy Markdown
Contributor

Sorry, I missed that. Looking on it now.

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.

Compiling with CMAKE_CXX_STANDARD=17 results in CUDA/Thrust "C++17 is not enabled" compiler warnings

3 participants