Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lpisha opened this issue Jan 21, 2023 · 4 comments
Open

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

lpisha opened this issue Jan 21, 2023 · 4 comments
Labels
libcu++ For all items related to libcu++

Comments

@lpisha
Copy link

lpisha commented Jan 21, 2023

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
Copy link
Member

wmaxey commented Jan 21, 2023

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
Copy link
Member

wmaxey commented Jan 21, 2023

NVIDIA/libcudacxx#340 has changes that seem relevant.

@lpisha
Copy link
Author

lpisha commented Jan 23, 2023

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:

  • The <cuda/std/atomic> issue is now fixed, it was indeed fixed in Add tests for host only TUs and fix several found issues. libcudacxx#340 , thank you!
  • The <cuda/std/limits> issue remains in VS 2022. Compilation will fail when TEST_LIMITS is set (in the reproducer) and succeed again when TEST_FIX_LIMITS is also set.
  • The <cuda/std/functional> issue remains in VS 2022. Compilation will fail when TEST_FUNCTIONAL is set (in the reproducer).
  • A new issue has emerged in <cuda/std/type_traits> in VS 2017 (<cuda/std/detail/libcxx/include/__type_traits/disjunction.h>: line 47, "error C2210: '_First': pack expansions cannot be used as arguments to non-packed parameters in alias templates"). This header is also included by <cuda/std/limits>, which is in turn included by <cuda/std/atomic> and <cuda/std/functional>, so all the tests now fail in VS 2017.

Summary of fixes needed by version:

  • VS 2022: incorporate TEST_FIX_LIMITS fix (or something equivalent); find a fix for <cuda/std/functional> issue
  • VS 2019: no issues
  • VS 2017: find a fix for <cuda/std/type_traits> issue

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 #968 and #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 referenced this issue in miscco/libcudacxx Jan 24, 2023
miscco referenced this issue in NVIDIA/libcudacxx Feb 8, 2023
@jrhemstad jrhemstad added thrust For all items related to Thrust. libcu++ For all items related to libcu++ and removed thrust For all items related to Thrust. labels Feb 22, 2023
miscco referenced this issue in miscco/libcudacxx Feb 23, 2023
`_D1` and `_D2` are macros defined in MSVC xmath.hpp

#fixes Missing symbols in MSVC C++ compilation, many headers fail to compile #354
@miscco
Copy link
Collaborator

miscco commented Feb 23, 2023

@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>

miscco referenced this issue in miscco/libcudacxx Feb 28, 2023
`_D1` and `_D2` are macros defined in MSVC xmath.hpp

#fixes Missing symbols in MSVC C++ compilation, many headers fail to compile #354
miscco referenced this issue in miscco/libcudacxx Feb 28, 2023
`_D1` and `_D2` are macros defined in MSVC xmath.hpp

#fixes Missing symbols in MSVC C++ compilation, many headers fail to compile #354
wmaxey referenced this issue in NVIDIA/libcudacxx Mar 1, 2023
* Move functors like `plus` into their own file

* Move `unary_negate` into its own file

* Move `binary_negate` into its own file

* Move `binder1st` into its own file

* Move `binder2nd` into its own file

* Move `pointer_to_unary_function` into its own file

* Move `pointer_to_binary_function` into its own file

* Move `mem_fun_ref` into its own file

* Move `mem_fn` into its own file

* Move `bind` to its own file

* Add `perfect_forward` helper struct to <functional>

* Move `not_fn` into its own file

* Move `__is_transparent` helper to its own file

* Implement C++20 `bind_front`

also backport it to C++17 as we will need it for ranges

* Add `__bind_back` helper method to functional

* Add `__compose` helper method to functional

* Move `default_searcher` to its own file

* Move `function` to its own file

* Fix compilation issues with MSVC

`_D1` and `_D2` are macros defined in MSVC xmath.hpp

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

* Fix missing abort in unreachable.h

---------

Co-authored-by: Wesley Maxey <wesley.maxey@gmail.com>
@jrhemstad jrhemstad removed their assignment Mar 7, 2023
@github-project-automation github-project-automation bot moved this to Todo in CCCL Nov 8, 2023
@jarmak-nv jarmak-nv transferred this issue from NVIDIA/libcudacxx Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libcu++ For all items related to libcu++
Projects
Status: Todo
Development

No branches or pull requests

4 participants