libcudacxx
libcudacxx copied to clipboard
`std::unique_ptr<cuda::atomic<T>>` move assignment fails to compile due to ambiguous swap overloads
Simple repro: https://godbolt.org/z/z6d1MqzoG
This is present in nvcc 11.0.2/11.0.3 and disappears as an error until it reappears in nvcc 11.4.
/opt/compiler-explorer/gcc-9.3.0/include/c++/9.3.0/bits/unique_ptr.h(400): error: more than one instance of overloaded function "swap" matches the argument list:
function template "cuda::std::__4::enable_if<<expression>, void>::type cuda::std::__4::swap(_Tp &, _Tp &)"
function template "std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<_Tp>>, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp>>::value, void>::type std::swap(_Tp &, _Tp &)"
argument types are: (cuda::std::__4::atomic<int> *, cuda::std::__4::atomic<int> *)
detected during:
instantiation of "void std::unique_ptr<_Tp, _Dp>::reset(std::unique_ptr<_Tp, _Dp>::pointer) noexcept [with _Tp=cuda::std::__4::atomic<int>, _Dp=std::default_delete<cuda::std::__4::atomic<int>>]"
(307): here
instantiation of "std::unique_ptr<_Tp, _Dp> &std::unique_ptr<_Tp, _Dp>::operator=(std::unique_ptr<_Tp, _Dp> &&) noexcept [with _Tp=cuda::std::__4::atomic<int>, _Dp=std::default_delete<cuda::std::__4::atomic<int>>]"
<source>(7): here
This looks like it was fixed for 11.4+, but is still present in 11.0.2 and 11.0.3.
https://godbolt.org/z/9zvb71vzx
The issue is still relevant since the error disappeared in nvcc/11.5.0 (see https://godbolt.org/z/P9h9jnsen) but comes back again with newer versions (V11.5.50
and V11.5.119
):
(base) yunsongw@yunsongw-dt:~/Work/toto-cuda/test$ make
nvcc -std=c++17 -arch=sm_75 --compiler-options -Wall --expt-extended-lambda simpleAtomic.cu -o simpleAtomic
/usr/include/c++/9/bits/unique_ptr.h(400): error: more than one instance of overloaded function "swap" matches the argument list:
function template "cuda::std::__4::enable_if<<expression>, void>::type cuda::std::__4::swap(_Tp &, _Tp &)"
/usr/local/cuda/include/cuda/std/detail/libcxx/include/type_traits(4488): here
function template "std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<_Tp>>, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp>>::value, void>::type std::swap(_Tp &, _Tp &)"
/usr/include/c++/9/bits/move.h(182): here
argument types are: (cuda::std::__4::atomic<int> *, cuda::std::__4::atomic<int> *)
detected during:
instantiation of "void std::unique_ptr<_Tp, _Dp>::reset(std::unique_ptr<_Tp, _Dp>::pointer) noexcept [with _Tp=cuda::std::__4::atomic<int>, _Dp=map<cuda_allocator<char>>::deleter]"
(307): here
instantiation of "std::unique_ptr<_Tp, _Dp> &std::unique_ptr<_Tp, _Dp>::operator=(std::unique_ptr<_Tp, _Dp> &&) noexcept [with _Tp=cuda::std::__4::atomic<int>, _Dp=map<cuda_allocator<char>>::deleter]"
simpleAtomic.cu(72): here
1 error detected in the compilation of "simpleAtomic.cu".
make: *** [Makefile:11: simpleAtomic] Error 1
(base) yunsongw@yunsongw-dt:~/Work/toto-cuda/test$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0
@PointKernel did you test the latest libcu++ from GH against nvcc 11.5.50 and 11.5.119? Or were you testing the libcu++ version that was alongside 11.5.50 and 11.5.119?
To clarify, I was testing the libcu++ version alongside 11.5.0
and 11.5.119
.
Can you verify if the issue persists with the current libcu++ in GH against those compiler versions?
I checked both compiler versions with libcu++ main
branch and 1.7.0
release. The error is consistent.
@wmaxey I thought this would have gone away with the atomic
refactor, but it seems to still be around.
I went through the godbolt and verified that the reproducer compiles fine with all SDK versions since 15.0.
So for now I am closing this