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

Improve the design of StreamSafeCUDAAllocator #38195

Conversation

From00
Copy link
Contributor

@From00 From00 commented Dec 16, 2021

PR types

New features

PR changes

Others

Describe

This PR do the following things to improve the StreamSafeCUDAAllocator impletemented in #37290 :

  1. Rewrites the StreamSafeCUDAAllocator to directly create and record an event when the RecordStream is called, not when the allocation is freed
  2. Changes the default stream of StreamSafeCUDAAllocator from NULL stream to the main stream in CUDADeviceContext
  3. Adds a GetStream interface for getting the owning stream of a StreamSafeCUDAAllocation

Why we no longer create and record events in a deferred manner?
When the main process finish, Paddle may clear some remaining tensors in shared memory (see #22541), and thus free allocations that may be recorded some CUDA streams. However, the stream created in executor has already destroyed at that time, so we should not try to record events to it. Similar problems may occur in any scenarios where StreamSafeCUDAAllocator is used, so we cannot assume that the recorded streams are still valid when freeing CUDA allocations.

@paddle-bot-old
Copy link

paddle-bot-old bot commented Dec 16, 2021

✅ This PR's description meets the template requirements!
Please wait for other CI results.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@From00 From00 changed the title Add GetStream Interface for StreamSafeCUDAAllocator Add GetStream Interface for StreamSafeCUDAAllocation Dec 16, 2021
@From00 From00 changed the title Add GetStream Interface for StreamSafeCUDAAllocation Improve the design of StreamSafeCUDAAllocator Dec 16, 2021
Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

@zhiqiu zhiqiu merged commit b0d12d9 into PaddlePaddle:develop Dec 17, 2021
@From00 From00 deleted the add-GetStream-interface-for-StreamSafeCudaAllocator branch December 17, 2021 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants