GeezerVison is showing github.com — CUDA < 12.4.1 bug affects use of openPMD-api in C++20 projects · Issue #1720 · openPMD/openPMD-api
CUDA < 12.4.1 bug affects use of openPMD-api in C++20 projects #1720DescriptionDescribe 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:
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
Reproducer:
nix build gitlab:franzpoeschel/mynixpkgs/issue-1720#picongpu_LaserWakefield Activityax3l commented on 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)
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[/+] on Feb 20, 2025franzpoeschel commented on May 7, 2025 ContributorAuthor More actions This seems to particularly affect gcc 12.3.0, other versions (even within this minor release range) seem to work. Need to investigate again and maybe narrow down the error check. franzpoeschel commented on Sep 1, 2025 ContributorAuthor More actions There is a chance that this was fixed by #1774, since that replaces public use of std::variant with std::any. Will need to check. franzpoeschel commented on Nov 14, 2025 ContributorAuthor More actions
There is a chance that this was fixed by #1774, since that replaces public use of std::variant with std::any. Will need to check.
Not entirely, but the fix is now in reach, ref. #1807
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|