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

[BUG]: cuda::std::swap cannot ADL-two-step-swap a type from std #2984

Closed
1 task done
bernhardmgruber opened this issue Nov 28, 2024 · 2 comments · Fixed by #2985
Closed
1 task done

[BUG]: cuda::std::swap cannot ADL-two-step-swap a type from std #2984

bernhardmgruber opened this issue Nov 28, 2024 · 2 comments · Fixed by #2985
Labels
bug Something isn't working right.

Comments

@bernhardmgruber
Copy link
Contributor

bernhardmgruber commented Nov 28, 2024

Is this a duplicate?

Type of Bug

Compile-time Error

Component

libcu++

Describe the bug

While trying to write a function in Thrust that needs to swap allocators from std and thrust, I ran into the issue that cuda::std::swap fails to swap them.

How to Reproduce

#include <thrust/device_vector.h>
#include <utility>

void swap_allocators(auto& a, auto& b) {
    using cuda::std::swap;
    swap(a, b);
}

int main() {
    thrust::device_vector<int>::allocator_type a, b;
    swap_allocators(a, b); // works

    std::allocator<int> c, d;
    swap_allocators(c, d); // /fails
}

https://godbolt.org/z/Ea1d1TWdo

Errors with:

<source>(6): error: more than one instance of overloaded function "swap" matches the argument list:
... 

I think this should work, since the ADL-two-step call is required to pick up any user-provided swap overload.

Expected behavior

Compile successfully.

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

@miscco
Copy link
Collaborator

miscco commented Nov 29, 2024

There is nothing we can do here.

The issue is that ADL will always pull in std::swap. If you tell it to also pull in cuda::std::swap that will always be ambiguous.

Nothing we can do here the moment something pulls in namespace std

@bernhardmgruber
Copy link
Contributor Author

There is nothing we can do here.

So, how do we swap two objects in a generic context? Like swapping two allocators which could come from std::, thrust::, cuda::std::, or cuda::? How do I utter the call to swap (and to which one)?

bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue Dec 3, 2024
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Progress in CCCL Dec 3, 2024
@cccl-authenticator-app cccl-authenticator-app bot moved this from In Progress to In Review in CCCL Dec 3, 2024
bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue Dec 3, 2024
bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue Dec 3, 2024
@cccl-authenticator-app cccl-authenticator-app bot moved this from In Review to In Progress in CCCL Dec 4, 2024
bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue Dec 4, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in CCCL Dec 4, 2024
bernhardmgruber added a commit that referenced this issue Dec 4, 2024
* Fix swapping types from namespace std
* Replace thrust::swap by cuda::std::swap

Fixes: #2984
Fixes: #2948

Co-authored-by: Michael Schellenberger Costa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right.
Projects
Archived in project
2 participants