NVIDIA / cccl

CUDA Core Compute Libraries
https://nvidia.github.io/cccl/
Other
1.21k stars 152 forks source link

Missing symbols in MSVC C++ compilation, many headers fail to compile #1006

Open lpisha opened 1 year ago

lpisha commented 1 year ago

Simple reproducer and more info at this repo: https://github.com/lpisha/test_cudastd_msvc

This is in the context of projects which contain both C++ and CUDA source files, where the C++ files are compiled with MSVC and the CUDA files with nvcc. The project uses the CUDA Standard Library across host and device code, so common headers which get included by both .cpp and .cu files include parts of the CUDA Standard Library.

During C++ compilation, two headers in the CUDA Standard Library, <cuda/std/limits> and <cuda/std/atomic>, expect that MSVC will have declared / defined certain symbols, but it has not, causing compilation errors. About half of the headers in the CUDA Standard Library include these two headers, making much of the library unusable.

This bug does not arise in the compilation of .cu files with nvcc, only in the compilation of .cpp files with MSVC.

The issues with <cuda/std/limits> were introduced between VS 2019 and VS 2022 due to changes to the MSVC headers. The issues with <cuda/std/atomic> do not appear to be version-related; it appears that the libcudacxx code could never have worked on MSVC in the C++ context.

Please see the README at https://github.com/lpisha/test_cudastd_msvc for more info.

wmaxey commented 1 year ago

Thanks for the report! We very recently made efforts to catch issues where libcu++ breaks when NVCC is not present. I'll follow up with your reproducer to see what we may have missed.

I distinctly remember fixing a similar sounding atomic macro that was missing...

wmaxey commented 1 year ago

NVIDIA/libcudacxx#340 has changes that seem relevant.

lpisha commented 1 year ago

Thanks for the reply!

Having moved from the version of libcudacxx included with CUDA 12.0 to top-of-tree, here are the new results:

Summary of fixes needed by version:

I apologize for not trying top-of-tree initially; I looked to see if the code relating to the <cuda/std/limits> issue had been changed compared to 12.0, and it had not, so I just went ahead and opened the issue without checking the atomic stuff.

I also saw NVIDIA/cccl#968 and NVIDIA/cccl#940 after posting the issue (only looked back two pages in the issues, not three 🙃 ), but I'm glad things have changed since then. The value of a library which works across host and device is substantially limited if the host code can't be compiled with a normal host compiler. If there were fundamental incompatibilities that would be one thing, but these are just a few missing symbols and tweaks to a few templates.

miscco commented 1 year ago

@lpisha thanks alot for the detailed description and reproducer. AFAIK we fixed the <limits> and <type_traits> issue and I have a PR open that addresses the issues found in <functional>