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

CUDA < 12.4.1 bug affects use of openPMD-api in C++20 projects #1720

Open
franzpoeschel opened this issue Feb 20, 2025 · 1 comment
Open
Labels
bug install third party third party libraries that are shipped and/or linked wontfix workaround

Comments

@franzpoeschel
Copy link
Contributor

Describe the bug
This bug basically makes std::variant unusable in the affected CUDA versions.

To Reproduce
I've seen this issue when trying to compile the latest dev branch of PIConGPU (2981b07a7160e64d057b5653f3d26410d54a8135) against the openPMD-api (version does not really matter, I used a4d66cc).

The error affects multiple usages of std::variant, e.g.:

/nix/store/6vclfnmcqpm1k5bbh5syf89f21gip2v3-gcc-12.3.0/include/c++/12.3.0/variant(391): error: function "std::__detail::__variant::_Variadic_union<_First, _Rest...>::~_Variadic_union() [with
 _First=unsigned int, _Rest=<unsigned long, unsigned long long, float, double, long double, std::complex<float>, std::complex<double>, std::complex<long double>, std::string, std::vector<cha
r, std::allocator<char>>, std::vector<short, std::allocator<short>>, std::vector<int, std::allocator<int>>, std::vector<long, std::allocator<long>>, std::vector<long long, std::allocator<lon
g long>>, std::vector<unsigned char, std::allocator<unsigned char>>, std::vector<unsigned short, std::allocator<unsigned short>>, std::vector<std::seed_seq::result_type, std::allocator<std::
seed_seq::result_type>>, std::vector<std::size_t, std::allocator<std::size_t>>, std::vector<unsigned long long, std::allocator<unsigned long long>>, std::vector<float, std::allocator<float>>
, std::vector<double, std::allocator<double>>, std::vector<long double, std::allocator<long double>>, std::vector<std::complex<float>, std::allocator<std::complex<float>>>, std::vector<std::
complex<double>, std::allocator<std::complex<double>>>, std::vector<std::complex<long double>, std::allocator<std::complex<long double>>>, std::vector<signed char, std::allocator<signed char
>>, std::vector<std::string, std::allocator<std::string>>, openpmd_array_double_7, bool>]" (declared at line 400) cannot be referenced -- it is a deleted function                            
   : _M_rest(in_place_index<_Np-1>, std::forward<_Args>(__args)...)                                                                                                                           
            ^                                                                                                                                                                                 
          detected during:
…
…
…
            instantiation of "std::__detail::__variant::_Move_ctor_base<<unnamed>, _Types...>::_Move_ctor_base(std::__detail::__variant::_Move_ctor_base<<unnamed>, _Types...> &&) [with <unna
med>=false, _Types=<char, unsigned char, signed char, short, int, long, long long, unsigned short, unsigned int, unsigned long, unsigned long long, float, double, long double, std::complex<f
loat>, std::complex<double>, std::complex<long double>, std::string, std::vector<char, std::allocator<char>>, std::vector<short, std::allocator<short>>, std::vector<int, std::allocator<int>>
, std::vector<long, std::allocator<long>>, std::vector<long long, std::allocator<long long>>, std::vector<unsigned char, std::allocator<unsigned char>>, std::vector<unsigned short, std::allo
cator<unsigned short>>, std::vector<std::seed_seq::result_type, std::allocator<std::seed_seq::result_type>>, std::vector<std::size_t, std::allocator<std::size_t>>, std::vector<unsigned long 
long, std::allocator<unsigned long long>>, std::vector<float, std::allocator<float>>, std::vector<double, std::allocator<double>>, std::vector<long double, std::allocator<long double>>, std:
:vector<std::complex<float>, std::allocator<std::complex<float>>>, std::vector<std::complex<double>, std::allocator<std::complex<double>>>, std::vector<std::complex<long double>, std::alloca
tor<std::complex<long double>>>, std::vector<signed char, std::allocator<signed char>>, std::vector<std::string, std::allocator<std::string>>, openpmd_array_double_7, bool>]" at line 59 of /
home/franzpoeschel/picongpu_env/env/include/openPMD/backend/Attribute.hpp

Line:

class Attribute : public auxiliary::Variant<Datatype, attribute_types>

or

/nix/store/6vclfnmcqpm1k5bbh5syf89f21gip2v3-gcc-12.3.0/include/c++/12.3.0/variant(391): error: function "std::__detail::__variant::_Variadic_union<_First, _Rest...>::~_Variadic_union() [with
 _First=openPMD::UniquePtrWithLambda<void>, _Rest=<>]" (declared at line 400) cannot be referenced -- it is a deleted function                                                                
   : _M_rest(in_place_index<_Np-1>, std::forward<_Args>(__args)...)                                                                                                                           
            ^                                                                                                                                                                                 
          detected during:  
…
…
…
            instantiation of "std::variant<_Types...>::variant(_Tp &&) [with _Types=<std::shared_ptr<const void>, openPMD::UniquePtrWithLambda<void>>, _Tp=openPMD::UniquePtrWithLambda<void>,
 <unnamed>=void, <unnamed>=void, _Tj=openPMD::UniquePtrWithLambda<void>, <unnamed>=void]" at line 181 of /home/franzpoeschel/picongpu_env/env/include/openPMD/auxiliary/Memory.hpp

Line:

EligibleTypes m_buffer;

What should we do

I don't see an easy way out of this. Looking at the linked bug report, even trivial use of std::variant seems to be impossible. In openPMD::Attribute, std::variant is part of our public API, so we can't easily replace it with something else.

  • Option 1: Check the affected CUDA versions, add some include guard to cancel compilation with the note that the CUDA version is broken and something else should be used.
  • Option 2: Reintroduce mpark::variant? It seems to be unmaintained though
@ax3l ax3l added affects latest release install third party third party libraries that are shipped and/or linked labels Feb 20, 2025
@ax3l
Copy link
Member

ax3l commented Feb 20, 2025

Thanks for documenting this C++20 issue with CUDA compilers! I encounter no problems with C++17 and std::variant in my projects.

It looks to me like using CUDA 12.4.1+ fixes this for C++20:
https://forums.developer.nvidia.com/t/nvcc-c-20-std-variant-complie-failed/270162/5

So I think there are two solutions for people:

  • If you want to use C++20 with Nvidia compilers, use the latest compilers only for now. They already fixed this issue and we should keep reporting other bugs we find to https://developer.nvidia.com This is what we usually do when new standards are supported in vendor compilers and bugs are being shaken out still.
  • If you want to use std::variant and older Nvidia compilers, only require C++17 for now in downstream projects. (openPMD-api only needs C++17 currently)

@ax3l ax3l changed the title CUDA bug affects use of openPMD-api in C++20 projects CUDA < 12.4.1 bug affects use of openPMD-api in C++20 projects Feb 20, 2025
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug install third party third party libraries that are shipped and/or linked wontfix workaround
Projects
None yet
Development

No branches or pull requests

2 participants