NVIDIA / NVIDIA/cccl

pointer rebind not working with thrust pointers in thrust 11.5

Open
#797 6 comments 0 reactions 1 assignee Claimed by @ericniebler View on GitHub
thrust
Dominant language
C++
Stars
2.5k
Forks
487
Avg merge
2d 7h
Merged PRs (30d)
296

Description

In thrust 11.3, type `thrust::cuda::allocator::pointer` yields `thrust::cuda_cub::pointer`.

This pointer can be rebinded to the const version, `std::pointer_traits>::rebind` yields `thrust::cuda_cub::pointer`. Maybe this works well because that is the default behavior of rebind even if the class `cuda_cub::pointer` doesn't have a rebind typedef.

However this is broken in 11.5, where `thrust::cuda::allocator::pointer` yields a more complicated type `thrust::pointer, thrust::use_default>`.

The same rebind yields

(1) `thrust::pointer, thrust::use_default>`

instead of the expected

(2) `thrust::pointer, thrust::use_default>`

I know (2) is the expected one because (1) doesn't work as a _source_ of `thrust::copy`.

What is the correct way to obtain the const version of a cuda pointer? I think `std::pointer_triats<...>::rebind` should work.

My guess is that the class `thrust::cuda_cub::pointer` is missing an internal `rebind` typedef.

(cross posted here: https://stackoverflow.com/questions/71453884/what-is-the-correct-way-to-rebind-a-thrust-pointer-in-thrust-11-5)

EDIT: I did a few more experiments and I think this can be solved by adding a `rebind` type to `thrust::cuda_cub::pointer` that doesn't exists now. (for example, now, `thrust::cuda::allocator::pointer::rebind` doesn't work).

EDIT2: I just found that there is a `thrust::detail::pointer_traits::rebind::other` that does the correct thing, however one needs a single metafunction to obtain the const version of a pointer from generic code, presumably `std::pointer_traits`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.