Skip to content
Discussion options

You must be logged in to vote

What is the intended way of swapping Thrust objects?

1. std::swap(x,y)
2. cuda::std::swap(x,y)
3. thrust::swap(x,y)
4. x.swap(y)

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 swap overload to be found and picks up std::swap as 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:

using cuda::std::swap;
swap(x, y);

Only when you know the concrete types for x and y (you are outside of generic code), you can use:

std::swap(x, y)`

in host code, or

cuda::std::swap(…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fkallen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Thrust
Labels
None yet
2 participants