Skip to content

Replace thrust::raw_pointer_cast with cuda::std::to_address#7439

Open
miscco wants to merge 6 commits intoNVIDIA:mainfrom
miscco:pointer_traits_address_of
Open

Replace thrust::raw_pointer_cast with cuda::std::to_address#7439
miscco wants to merge 6 commits intoNVIDIA:mainfrom
miscco:pointer_traits_address_of

Conversation

@miscco
Copy link
Contributor

@miscco miscco commented Jan 30, 2026

This replaces thrust::raw_pointer_cast with the standard conforming cuda::std::to_address

We enable usage of that by specializing cuda::std::pointer_traits for the thrust smart pointers.

NOTE: I did not yet deprecate thrust::raw_pointer_cast because we should give users, e.g rapids a way to update and its not yet available. I plan on deprecating it in the 3.4 time frame

@miscco miscco requested review from a team as code owners January 30, 2026 10:55
@miscco miscco requested a review from wmaxey January 30, 2026 10:55
@miscco miscco requested a review from davebayer January 30, 2026 10:55
@github-project-automation github-project-automation bot moved this to Todo in CCCL Jan 30, 2026
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Jan 30, 2026
@miscco miscco force-pushed the pointer_traits_address_of branch from c7fab2a to 0403ea8 Compare January 30, 2026 11:08
Copy link
Contributor

@bernhardmgruber bernhardmgruber left a comment

Choose a reason for hiding this comment

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

LGTM, just some questions.

@github-actions

This comment has been minimized.

@miscco miscco force-pushed the pointer_traits_address_of branch 2 times, most recently from 138f219 to 1a5c52d Compare March 6, 2026 12:49
@github-actions

This comment has been minimized.


// Specialize pointer traits for everything that has the raw_pointer alias
template <typename Pointer>
struct ::cuda::std::pointer_traits<Pointer, ::cuda::std::void_t<typename Pointer::raw_pointer>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider specializing std::pointer_traits as well here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am a bit on the fence, because the standard does not know about execution spaces, but with that I am fine

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be useful for downstream users. In my experience it is common for downstream projects to use thrust fancy pointers, but not yet cuda::std:: utilities. I myself have (carefully) rolled my own specializations for std::pointer_traits for thrust fancy pointers, simply to have generic code that needs to introspect pointers Just Work(TM).


// Specialize pointer traits for everything that has the raw_pointer alias
template <class T>
struct ::cuda::std::pointer_traits<THRUST_NS_QUALIFIER::device_ptr<T>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here for std::pointer_traits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely do not want to do that because that is a device pointer and the std traits have no dealing with that

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I follow, what would be the danger here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

device only sequences should work with cuda::std:: types and not std::types

@miscco miscco force-pushed the pointer_traits_address_of branch from 1a5c52d to 6597b5f Compare March 19, 2026 13:33
@miscco miscco requested review from a team as code owners March 19, 2026 13:33
@miscco miscco force-pushed the pointer_traits_address_of branch from 6597b5f to b9668c9 Compare March 19, 2026 13:46
@bernhardmgruber
Copy link
Contributor

I have the feeling this PR massively grew in size after I approved. Why was this necessary and why can't we ship the changes added later in a separate PR?

@miscco
Copy link
Contributor Author

miscco commented Mar 19, 2026

Actually it is much smaller.

It introduces pointer_traits specializations for the contiguous thrust iterators.

It then replaces raw_pointer_cast with cuda::std::to_address because that is the standard interface to retrieve a pointer from a smart pointer

The issue is that we use raw_pointer_cast a lot

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Contributor

@pauleonix pauleonix left a comment

Choose a reason for hiding this comment

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

Everything in cub/ looks fine to me.

@miscco miscco force-pushed the pointer_traits_address_of branch 3 times, most recently from 5e21068 to da7abeb Compare March 20, 2026 09:13
@miscco miscco changed the title Cleanup some of thrust pointer traits Replace thrust::raw_pointer_cast with cuda::std::to_address Mar 20, 2026
@miscco miscco force-pushed the pointer_traits_address_of branch from da7abeb to eeda680 Compare March 20, 2026 10:27
@miscco
Copy link
Contributor Author

miscco commented Mar 20, 2026

Not to reviewers. all relevant product code changes are in f87d697

The rest is only search & replace

@miscco miscco force-pushed the pointer_traits_address_of branch from eeda680 to fc0439a Compare March 20, 2026 10:30
@github-actions
Copy link
Contributor

🥳 CI Workflow Results

🟩 Finished in 3h 14m: Pass: 100%/398 | Total: 7d 06h | Max: 3h 03m | Hits: 90%/511025

See results here.

Copy link
Contributor

@bernhardmgruber bernhardmgruber left a comment

Choose a reason for hiding this comment

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

If there are no uses of thrust::raw_pointer_cast remaining, can we deprecate it?

#include <thrust/partition.h>

#include "thrust/detail/raw_pointer_cast.h"
#include "cuda/std/memory"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include "cuda/std/memory"
#include <cuda/std/memory>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

6 participants