Should Thrust objects be swapped via thrust::swap, std::swap, cuda::std::swap, or member function swap (if present)? #5328
-
|
What is the intended way of swapping Thrust objects? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thrust should work like any other C++ library. The generic approach to swapping in C++ is the ADL two-step swap: using std::swap;
swap(x, y);This allows any However, CUDA also provides its own standard library that also works in device code, libcu++. So in generic code running on device (and/or host), you should use: using cuda::std::swap;
swap(x, y);Only when you know the concrete types for std::swap(x, y)`in host code, or cuda::std::swap(x, y);in host or device code, or any swapping member function, lile x.swap(y);In general, I would always stick to using cuda::std::swap;
swap(x, y); |
Beta Was this translation helpful? Give feedback.
Thrust should work like any other C++ library. The generic approach to swapping in C++ is the ADL two-step swap:
This allows any
swapoverload to be found and picks upstd::swapas a fallback.However, CUDA also provides its own standard library that also works in device code, libcu++. So in generic code running on device (and/or host), you should use:
Only when you know the concrete types for
xandy(you are outside of generic code), you can use:std::swap(x, y)`in host code, or
cuda::std::swap(…