Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VS2019 Pro have compile errors with xutility, xmemory, and atomic when creating a CUDA project via CMake?

I'm trying to create a simple CUDA project via CMake and getting strange compilation errors. I'm following this tutorial. Originally, I was using Visual Studio 2019 Community, CMake 3.18.3, and CUDA 11.3 and everything worked fine. Then, I updated to Visual Studio 2019 Professional and CMake 3.20.3, and it failed to compile the same exact same source code.

Here's my entire CMakeLists file:

cmake_minimum_required(VERSION 3.18.3)

project(hello_world LANGUAGES CXX CUDA)

add_executable(hello_world_target main.cu)

target_compile_features(hello_world_target PUBLIC cxx_std_11)
set_target_properties(hello_world_target PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(hello_world_target PROPERTIES CUDA_ARCHITECTURES "52")

Here's my only source file, main.cu:

#include <iostream>

int main(){
  std::cout << "Hello, world!" << std::endl;
  return 0;
}

When I try to compile, I get the following errors:

1>Compiling CUDA source file ..\main.cu...
1>
1>C:\Users\[username]\Documents\hello_cmake\build>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\bin\nvcc.exe" -gencode=arch=compute_52,code=\"compute_52,compute_52\" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\bin\HostX64\x64" -x cu -rdc=true   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include"     --keep-dir x64\Debug  -maxrregcount=0  --machine 64 --compile -cudart static -std=c++14 -Xcompiler="/EHsc -Zi -Ob0" -g  -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\"" -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /Od /Fdhello_world_target.dir\Debug\vc142.pdb /FS /Zi /RTC1 /MDd /GR" -o hello_world_target.dir\Debug\main.obj "C:\Users\[username]\Documents\hello_cmake\main.cu"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1>          detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=const char *, _Sentinel=const char *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(1990): here
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1>          detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=__wchar_t *, _Sentinel=__wchar_t *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(1991): here
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1>          detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=const __wchar_t *, _Sentinel=const __wchar_t *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(2026): here

.....etc., etc., etc.....

31 errors detected in the compilation of "C:/Users/[username]/Documents/hello_cmake/main.cu".
1>main.cu
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 11.3.targets(785,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\bin\nvcc.exe" -gencode=arch=compute_52,code=\"compute_52,compute_52\" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\bin\HostX64\x64" -x cu -rdc=true   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include"     --keep-dir x64\Debug  -maxrregcount=0  --machine 64 --compile -cudart static -std=c++14 -Xcompiler="/EHsc -Zi -Ob0" -g  -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\"" -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /Od /Fdhello_world_target.dir\Debug\vc142.pdb /FS /Zi /RTC1 /MDd /GR" -o hello_world_target.dir\Debug\main.obj "C:\Users\[username]\Documents\hello_cmake\main.cu"" exited with code 1.
1>Done building project "hello_world_target.vcxproj" -- FAILED.

What's perplexing is that this worked fine with the different versions of Visual Studio and CMake. Also, if I rewrite the CMakeLists.txt file to remove CUDA from the LANGUAGES list, and change main.cu to main.cpp, everything works fine.

It's also confusing that the compiler would complain about the xutility, xmemory, and atomic files. That sounds like a red herring, though.

What could be causing this issue?

UPDATE 10/20/2021: For me, VS2019 16.11.5 works fine with CUDA 11.4.120 and CMake 3.21.3, no modifications needed.

like image 496
Justin Avatar asked May 28 '21 02:05

Justin


People also ask

Will Visual Studio 2019 work with CUDA and CMake?

UPDATE 10/20/2021: For me, VS2019 16.11.5 works fine with CUDA 11.4.120 and CMake 3.21.3, no modifications needed. Show activity on this post. I ran into basically the same problem after upgrading from Visual Studio 2019 16.9.6 to 16.10.

How to compile CUDA project with MSVC v142-vs2019?

MSVC v142 - VS2019 C++ x64/x86 build tools (14.28-16.9) To compile the CUDA CMake project the MSVC toolset version needs to be set explicitly. This can be done by entering in "Optional toolset to use (argument to -T) in the CMake GUI (CMake cache needs to be deleted). Show activity on this post.

What version of MSVC do I need to compile the CMake project?

MSVC v142 - VS2019 C++ x64/x86 build tools (14.28-16.9) To compile the CUDA CMake project the MSVC toolset version needs to be set explicitly.

Does Visual Studio support CMake_CUDA_host_compiler?

Also Windows Visual Studio does not support specifying CUDAHOSTCXX or CMAKE_CUDA_HOST_COMPILER env settings and gives problems like this. I used cmake version 3.20.3 and win-build 3.20.20210609-g5e26887 to test.


2 Answers

I ran into basically the same problem after upgrading from Visual Studio 2019 16.9.6 to 16.10. The problem seems to be caused by changes in xutility, xmemory etc. in the version of the MSVC v142 build tools 14.29.30037 delivered with Visual Studio 2019 16.10.

I could not solve the problem for the new version of the build tools, but I found a workaround. It is possible to install the v142 build tools from VS2019 16.9 with VS2019 16.10:

In VS the installer, "Visual Studio 2019->Modify->Individual components" add

  • MSVC v142 - VS2019 C++ x64/x86 build tools (14.28-16.9)
  • C++ v14.28 (16.9) ATL for v142 build tools (x86 & x64)
  • optionally: MFC, commandline tools, etc.

To compile the CUDA CMake project the MSVC toolset version needs to be set explicitly. This can be done by entering

version=14.28.29910

in "Optional toolset to use (argument to -T) in the CMake GUI (CMake cache needs to be deleted).

like image 175
AlexB Avatar answered Oct 24 '22 08:10

AlexB


Nothing wrong with the program and with the MSVC compiler and libs. You can use the latest release (now 16.10.1) cmake generated this (chaotic) compiler command in the vs 2019 IDE: "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\bin\nvcc.exe" -gencode=arch=compute_75,code="compute_75,compute_75" -gencode=arch=compute_75,code="sm_75,compute_75" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30037\bin\HostX64\x64" -x cu -rdc=true -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include" --keep-dir x64\Release -maxrregcount=0 --machine 64 --compile -cudart static -std=c++14 -Xcompiler="/EHsc -Ob2" -D_WINDOWS -DNDEBUG -D"CMAKE_INTDIR="Release"" -D_MBCS -D"CMAKE_INTDIR="Release"" -Xcompiler "/EHsc /W1 /nologo /O2 /Fdhello_world_target.dir\Release\vc142.pdb /FS /MD /GR" -o hello_world_target.dir\Release\main.obj "D:\projects\test\main.cu"

remove additional option: -std=c++14 in this command and it works

Why: With cuda 11.3 and MSVC 19.29.++ MSVC arranges itself the setting for the host compiler icw NVCC, so using this option gives problems. It must be edited in the CMAKE release. Module compiler(NVIDIA-CUDA.cmake) I think. I'm not an expert on that, but you can see there a lot of hocus-pocus around this option.

Also Windows Visual Studio does not support specifying CUDAHOSTCXX or CMAKE_CUDA_HOST_COMPILER env settings and gives problems like this. I used cmake version 3.20.3 and win-build 3.20.20210609-g5e26887 to test.

like image 25
Ted_Jonker Avatar answered Oct 24 '22 07:10

Ted_Jonker