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]: cudax uninitialized_buffer::get_resource returns a resource_ref that can dangle #2430

Closed
1 task done
ericniebler opened this issue Sep 18, 2024 · 0 comments · Fixed by #2431
Closed
1 task done
Labels
bug Something isn't working right.

Comments

@ericniebler
Copy link
Collaborator

Is this a duplicate?

Type of Bug

Runtime Error

Component

libcu++

Describe the bug

cudax uninitialized_buffer::get_resource returns a resource_ref that refers (in a non-owning way) to the memory resource owned by the buffer. if the returned resource_ref is then used to construct another uninitialized_buffer, the new buffer will be left with a dangling reference once the first is destroyed.

for instance, the following test fails (test_device_memory_resource::count is the number of test_device_memory_resource objects alive):

cudax::uninitialized_buffer<int, ::cuda::mr::device_accessible> buffer{
    cuda::mr::device_memory_resource{}, 0};

{
  CHECK(test_device_memory_resource::count == 0);

  cudax::uninitialized_buffer<int, ::cuda::mr::device_accessible> src_buffer{
      test_device_memory_resource{}, 1024};

  CHECK(test_device_memory_resource::count == 1);

  // `dst_buffer` is constructed with a reference to the memory resource owned
  // by `src_buffer`.
  cudax::uninitialized_buffer<int, ::cuda::mr::device_accessible> dst_buffer{
      src_buffer.get_resource(), 1024};

  // This check fails because there is only one `test_device_memory_resource`
  CHECK(test_device_memory_resource::count == 2);

  // Move the `dst_buffer` into `buffer` in the enclosing scope.
  buffer = ::cuda::std::move(dst_buffer);

  // `src_buffer` is destroyed here, and the `test_device_memory_resource` along
  // with it.
}

// `buffer` is left holding a dangling reference to a memory resource

// This check fails. There are no `test_device_memory_resource` objects left.
CHECK(test_device_memory_resource::count == 1);

How to Reproduce

see above

Expected behavior

i should be able to call buffer.get_resource() and construct a new buffer with the result that does not dangle when buffer is destroyed.

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

@ericniebler ericniebler added the bug Something isn't working right. label Sep 18, 2024
@github-project-automation github-project-automation bot moved this to Todo in CCCL Sep 18, 2024
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Sep 18, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Sep 19, 2024
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
1 participant