VS: CUDA_ARCHITECTURES set to OFF still passes architectures
Even if setting CUDA_ARCHITECTURES
to OFF
, CMake always passes architecture flags to the compiler when using a Visual Studio generator. This is in conflict with the documentation, which states that when setting CUDA_ARCHITECTURES
to OFF
, CMake will not pass any architecture flags to the compiler. It seems that this feature has been broken since it was introduced in CMake 3.18, at least with CUDA 11.6.
However, CUDA_ARCHITECTURES
behaves as expected with other generators like Ninja and on Linux as well.
CMake versions tested: 3.23.1, 3.22.4, 3.19.8, 3.18.6, 3.18.0
Generator: Visual Studio 17 2022 / Visual Studio 16 2019
CUDA Toolkit: 11.6.2
Here's a simple reproducer:
cmake_minimum_required(VERSION 3.18)
project(example LANGUAGES CUDA)
set(src "${CMAKE_CURRENT_BINARY_DIR}/main.cu")
file(CONFIGURE OUTPUT ${src} CONTENT "int main() {return 0;}")
add_executable(test ${src})
set_target_properties(test PROPERTIES CUDA_ARCHITECTURES OFF)
This is the resulting compiler invocation:
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\nvcc.exe" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include" --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -Xcompiler="/EHsc -Ob2" -D_WINDOWS -DNDEBUG -D"CMAKE_INTDIR=\"Release\"" -D_MBCS -D"CMAKE_INTDIR=\"Release\"" -Xcompiler "/EHsc /W1 /nologo /O2 /Fdtest.dir\Release\vc143.pdb /FS /MD /GR" -o test.dir\Release\main.obj "C:\Dev\cmake-cuda-bug\build\main.cu"
CMake incorrectly adds the -gencode=arch=compute_52,code=\"sm_52,compute_52\"
flag. However, it does not add any architecture flags using Ninja and the same version of CUDA.