[fix] CMake 3.31+ breaks OpenMP detection in CUDA projects (issue #333)#415
Open
edenfunf wants to merge 1 commit intoNVIDIA:masterfrom
Open
[fix] CMake 3.31+ breaks OpenMP detection in CUDA projects (issue #333)#415edenfunf wants to merge 1 commit intoNVIDIA:masterfrom
edenfunf wants to merge 1 commit intoNVIDIA:masterfrom
Conversation
CMake 3.31 added support for finding OpenMP in CUDA projects. When find_package(OpenMP) or find_package(OpenMP REQUIRED) is called inside a project declared with LANGUAGES C CXX CUDA, CMake now also attempts to find OpenMP for the CUDA language. This fails on most toolchains since nvcc does not support OpenMP in the same way, causing: Could NOT find OpenMP_CUDA (missing: OpenMP_CUDA_FLAGS OpenMP_CUDA_LIB_NAMES) Fix by explicitly restricting the OpenMP search to C and CXX languages in both affected samples (UnifiedMemoryStreams and cudaOpenMP). This matches the existing behavior on pre-3.31 CMake and avoids the spurious CUDA component detection. Fixes NVIDIA#333
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the problem
CMake 3.31 added support for finding OpenMP in the CUDA language. When
find_package(OpenMP)(orfind_package(OpenMP REQUIRED)) is called inside a project that declaresLANGUAGES C CXX CUDA, CMake now also tries to find OpenMP for CUDA. That lookup fails on most setups because nvcc doesn't expose OpenMP the same way GCC/Clang does:This hits anyone on CMake >= 3.31 building
UnifiedMemoryStreams(and potentiallycudaOpenMP) on Linux.Steps to reproduce
Error appears when CMake processes
Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt.What I changed
Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txtThe Visual Studio branch already had
find_package(OpenMP REQUIRED C CXX)— the non-VS branch was missing the language restriction. Since both cases want the same thing, I collapsed theif/elseinto a single call withC CXXspecified:Samples/0_Introduction/cudaOpenMP/CMakeLists.txtSame root cause.
find_package(OpenMP)without components in a CUDA project will attempt CUDA OpenMP detection on CMake 3.31+. AddedC CXXhere too:Why this is safe
Specifying
C CXXexplicitly tells CMake "only look for OpenMP for these two languages." This is exactly what these samples need — they link againstOpenMP::OpenMP_CXXand never use CUDA OpenMP. The behavior is identical on CMake < 3.31 since CUDA was not a recognized OpenMP language before that version.Impact
Only affects the two sample CMakeLists files. No source code changes, no behavior change at runtime. Doesn't touch any other samples.
Fixes #333