Skip to content

Commit f609976

Browse files
Fix logic for adding -allow-unsupported-compiler to nvcc (#7337)
The previous logic would always add -allow-unsupported-compiler and -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH, even when it was not needed. The revised logic only adds the flags if MSVC>=1940 and CUDA<=12.4. The new code also uses CMAKE_CUDA_FLAGS for the define, which makes CMake's try_compile work reliably if a CMake version >=3.29.4 is used. --------- Co-authored-by: Patrik Huber <[email protected]> Co-authored-by: Sameer Sheorey <[email protected]>
1 parent bdd0fb1 commit f609976

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
- Exposed `get_plotly_fig` and modified `draw_plotly` to return the `Figure` it creates. (PR #7258)
6464
- Fix build with librealsense v2.44.0 and upcoming VS 2022 17.13 (PR #7074)
6565
- Fix `deprecated-declarations` warnings when compiling code with C++20 standard (PR #7303)
66+
- Fix logic for adding -allow-unsupported-compiler to nvcc (PR #7337)
6667
- Fix linker error "library limit of 65535 objects exceeded" with Ninja generator on MSVC (PR #7335)
6768

6869
## 0.13

CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,22 @@ cmake_language(EVAL CODE "cmake_language(DEFER CALL open3d_patch_findthreads_mod
395395

396396
# Build CUDA module by default if CUDA is available
397397
if(BUILD_CUDA_MODULE)
398-
# Suppress nvcc unsupported compiler error for MSVC 2022 with CUDA 11.7 to 12.4
399-
# https://forums.developer.nvidia.com/t/problems-with-latest-vs2022-update/294150/12
400-
if (MSVC AND MSVC_VERSION VERSION_LESS_EQUAL "1949")
401-
# Set this before any CUDA checks
402-
add_compile_definitions(_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH)
403-
set(CMAKE_CUDA_FLAGS "--allow-unsupported-compiler" CACHE STRING "Additional flags for nvcc" FORCE)
404-
message(WARNING "Using --allow-unsupported-compiler flag for nvcc with MSVC 2022. "
405-
"Set $Env:NVCC_PREPEND_FLAGS='--allow-unsupported-compiler' if nvcc still fails.")
398+
if(MSVC)
399+
# Handle/suppress nvcc unsupported compiler error for MSVC>=1940 with CUDA 11.7 to 12.4:
400+
# (https://forums.developer.nvidia.com/t/problems-with-latest-vs2022-update/294150/12)
401+
# Find CUDAToolkit first to get CUDAToolkit_VERSION:
402+
find_package(CUDAToolkit REQUIRED)
403+
if (CUDAToolkit_VERSION VERSION_LESS "12.5" AND MSVC_VERSION GREATER_EQUAL 1940)
404+
# Set required nvcc flags before enable_language(CUDA).
405+
# Note: CMake >=3.29.4 might be needed for CMAKE_CUDA_FLAGS to be passed correctly to
406+
# CMake's try_compile environment.
407+
set(CMAKE_CUDA_FLAGS
408+
"${CMAKE_CUDA_FLAGS} -allow-unsupported-compiler -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH"
409+
CACHE STRING "Flags for NVCC" FORCE)
410+
endif()
411+
message(WARNING "Using --allow-unsupported-compiler flag and -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH for nvcc<=12.4 with MSVC>=1940. "
412+
"Set $Env:NVCC_PREPEND_FLAGS='--allow-unsupported-compiler' if nvcc still fails.")
413+
endif()
406414
endif()
407415
if (CMAKE_CUDA_ARCHITECTURES)
408416
message(STATUS "Building with user-provided CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")

0 commit comments

Comments
 (0)