Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
/thrustPublic archive

Enable swap(...) for temporaries and between different reference types#1646

Open
upsj wants to merge1 commit intoNVIDIA:main
base:main
Choose a base branch
Loading
fromupsj:reference_swap

Conversation

@upsj
Copy link
Contributor

An attempt at resolving the issues surrounding swap(...) between temporary device references and between different reference(-like) types

ClosesNVIDIA/cccl#802

@GPUtester
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Collaborator

@ericnieblerericniebler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

All the thrust reference-like types inherit fromthrust::reference. We could simplify a lot of this by just defining some hiddenswap friend functions there.

And that makes me wonder if we want to support arbitrary mixing of reference-like types (e.g., swapping adevice_reference with kinds oftagged_reference). Maybe@jrhemstad could comment on that?


// test thrust::swap()
thrust::swap(ref1, ref2);
swap(ref1, ref2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think the point of this code is to testthrust::swap, no?

The existence ofthrust::swap is a bit unfortunate. If you try toswap a type that has bothstd:: andthrust:: as associated namespace, the compiler has no way to pick betweenstd::swap andthrust::swap. We could consider definingthrust::swap as a global functionobject that dispatches to (unqualified)swap in a context that has broughtstd::swap in with ausing declaration. Then a simple call tothrust::swap will do the ADL lookup internally, and the potential ambiguity betweenstd::swap andthrust::swap goes away. I think that's a change that is unlikely to break anybody.

@allisonvacanti thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good catch, your proposed fix sounds good to me so long as nothing is specializingthrust::swap.

TheTHRUST_INLINE_CONSTANT macro may be needed when defining the function object, seehttps://github.com/NVIDIA/thrust/blob/main/thrust/detail/config/cpp_compatibility.h#L47-L74

@ericnieblerericniebler added type: enhancementNew feature or request. P2: nice to haveDesired, but not necessary. labelsMar 28, 2022
@alliepiperalliepiper added this to the1.17.0 milestoneApr 4, 2022
@alliepiperalliepiper modified the milestones:1.17.0,2.0.0Apr 25, 2022
@alliepiperalliepiper modified the milestones:2.0.0,2.1.0Jul 25, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

2 more reviewers

@alliepiperalliepiperalliepiper left review comments

@ericnieblerericnieblerericniebler left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

P2: nice to haveDesired, but not necessary.type: enhancementNew feature or request.

Projects

None yet

Milestone

2.1.0

Development

Successfully merging this pull request may close these issues.

swap is unnecessarily constrained on reference-like objects

4 participants

@upsj@GPUtester@alliepiper@ericniebler

[8]ページ先頭

©2009-2025 Movatter.jp