Skip to content

[BUG]: device_reference assignement operator should be const #4621

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

Closed
1 task done
plietar opened this issue May 2, 2025 · 1 comment · Fixed by #4740
Closed
1 task done

[BUG]: device_reference assignement operator should be const #4621

plietar opened this issue May 2, 2025 · 1 comment · Fixed by #4740
Assignees
Labels
bug Something isn't working right.

Comments

@plietar
Copy link

plietar commented May 2, 2025

Is this a duplicate?

Type of Bug

Compile-time Error

Component

Thrust

Describe the bug

The device_reference<T> type acts as a transparent proxy for an object that resides in device memory.

It has an assignment operator declared as follows:

_CCCL_HOST_DEVICE device_reference& operator=(const value_type& x);

I believe the signature of this operator should be relaxed as marked as const. A constant memory location can still be represented as a device_reference<const T>.

The motivation for this comes from the indirectly_writable concept. This concept requires that the iterator's "reference" type be assignable to, even when const-qualified. See the cppreference page for more details and rationale on this requirement.

This in turn prevents std::output_iterator from being satisfied, which is needed by many STL ranges algorithms.

How to Reproduce

static_assert(std::indirectly_writable<uint8_t*, uint8_t>); // This succeeds
static_assert(std::indirectly_writable<thrust::device_ptr<uint8_t>, uint8_t>); // This fails

https://godbolt.org/z/bMd9Yaa5h

Expected behavior

std::indirectly_writable<thrust::device_ptr<uint8_t>, uint8_t> should be satisfied.

Reproduction link

https://godbolt.org/z/bMd9Yaa5h

Operating System

No response

nvidia-smi output

No response

NVCC version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0

Same results with 12.5.1 on Godbolt.

@plietar plietar added the bug Something isn't working right. label May 2, 2025
@github-project-automation github-project-automation bot moved this to Todo in CCCL May 2, 2025
@bernhardmgruber bernhardmgruber self-assigned this May 19, 2025
bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue May 19, 2025
This is in line with device_reference being a proxy reference, where assigning to a proxy reference does not change the reference itself, but the referred object (the const is shallow).

This also makes device_ptr satisfy std::indirectly_writable

Fixes: NVIDIA#4621
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL May 19, 2025
@bernhardmgruber
Copy link
Contributor

Thanks a lot for the detailed bug description! This made it easy to provide a fix, see #4740.

bernhardmgruber added a commit to bernhardmgruber/cccl that referenced this issue May 19, 2025
This is in line with device_reference being a proxy reference, where assigning to a proxy reference does not change the reference itself, but the referred object (the const is shallow).

This also makes device_ptr satisfy std::indirectly_writable

Fixes: NVIDIA#4621
bernhardmgruber added a commit that referenced this issue May 20, 2025
This is in line with device_reference being a proxy reference, where assigning to a proxy reference does not change the reference itself, but the referred object (the const is shallow).

This also makes device_ptr satisfy std::indirectly_writable

Fixes: #4621

Co-authored-by: Michael Schellenberger Costa <miscco@nvidia.com>
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL May 20, 2025
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
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants