Skip to content

Do not synchronize in caching_allocator::{de}allocate#7792

Merged
miscco merged 2 commits intoNVIDIA:mainfrom
miscco:fix_caching_allocator
Feb 26, 2026
Merged

Do not synchronize in caching_allocator::{de}allocate#7792
miscco merged 2 commits intoNVIDIA:mainfrom
miscco:fix_caching_allocator

Conversation

@miscco
Copy link
Contributor

@miscco miscco commented Feb 25, 2026

We should not need the additional synchronization.

@miscco miscco requested a review from a team as a code owner February 25, 2026 14:49
@miscco miscco requested a review from jrhemstad February 25, 2026 14:49
@github-project-automation github-project-automation bot moved this to Todo in CCCL Feb 25, 2026
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Feb 25, 2026
@miscco miscco force-pushed the fix_caching_allocator branch from b786fec to 81243c3 Compare February 25, 2026 15:08
Copy link
Contributor

@davebayer davebayer left a comment

Choose a reason for hiding this comment

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

I don't believe this is correct. We should .sync() in .deallocate(), because if you just want to enqueue the deallocation in the stream, but you aren't yet done with the buffers, next allocation could pick up this buffer and overwrite your data.

@github-project-automation github-project-automation bot moved this from In Review to In Progress in CCCL Feb 25, 2026
@github-actions

This comment has been minimized.

@miscco
Copy link
Contributor Author

miscco commented Feb 25, 2026

I don't believe this is correct. We should .sync() in .deallocate(), because if you just want to enqueue the deallocation in the stream, but you aren't yet done with the buffers, next allocation could pick up this buffer and overwrite your data.

yeah you are right, Its not only the pointer, but it could be that the operation has not yet finished

Copy link
Contributor

@davebayer davebayer left a comment

Choose a reason for hiding this comment

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

What we could do is that we could add synchronization using cuda::event. In the .deallocate(...) method, we would recor an event that would be a replacement for cudaFreeAsync in the queue. Then in .allocate(...) method, we would enqueue wait for the event before returning the pointer, which would replace cudaMallocAsync in the queue.

This way we can be sure there are no race conditions.

@miscco miscco force-pushed the fix_caching_allocator branch from ebeb540 to dd0842c Compare February 25, 2026 16:21
}
else
{
const cudaError_t status = cudaMallocAsync(&result, num_bytes, __stream.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if you can allocate memory with cudaMallocAsync and then free it with cudaFree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty sure you can

Copy link
Contributor

Choose a reason for hiding this comment

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

You can: https://docs.nvidia.com/cuda/cuda-programming-guide/04-special-topics/stream-ordered-memory-allocation.html#freeing-memory
"Likewise, memory allocated with cudaMallocAsync can be freed with cudaFree()."

@github-actions
Copy link
Contributor

🥳 CI Workflow Results

🟩 Finished in 1h 22m: Pass: 100%/33 | Total: 9h 00m | Max: 1h 05m | Hits: 85%/19433

See results here.

@miscco miscco enabled auto-merge (squash) February 25, 2026 17:49
Copy link
Contributor

@davebayer davebayer left a comment

Choose a reason for hiding this comment

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

But we should rework the allocator in the future

@miscco miscco merged commit 852d65d into NVIDIA:main Feb 26, 2026
54 checks passed
@miscco miscco deleted the fix_caching_allocator branch February 26, 2026 07:28
@github-project-automation github-project-automation bot moved this from In Progress to In Review in CCCL Feb 26, 2026
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants