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

switch allocator when switch stream #70922

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion paddle/phi/backends/gpu/gpu_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ limitations under the License. */
#include "paddle/phi/common/place.h"
#include "paddle/phi/core/allocator.h"
#include "paddle/phi/core/cuda_stream.h"

#include "paddle/phi/core/memory/allocation/allocator_facade.h"
#ifdef PADDLE_WITH_CUDA
#include "paddle/phi/backends/dynload/cublas.h"
#include "paddle/phi/backends/dynload/cudnn.h"
Expand Down Expand Up @@ -960,11 +960,21 @@ void GPUContext::Init() {
}

void GPUContext::SetStream(gpuStream_t stream) {
#if !defined(_WIN32)
this->SetAllocator(paddle::memory::allocation::AllocatorFacade::Instance()
.GetAllocator(impl_->GetPlace(), stream)
.get());
#endif
impl_->allocator_ = const_cast<Allocator*>(&this->GetAllocator()); // NOLINT
impl_->SetStream(stream);
}

void GPUContext::SetCUDAStream(CUDAStream* stream, bool clear) {
#if !defined(_WIN32)
this->SetAllocator(paddle::memory::allocation::AllocatorFacade::Instance()
.GetAllocator(stream->place(), stream->raw_stream())
.get());
#endif
impl_->allocator_ = const_cast<Allocator*>(&this->GetAllocator()); // NOLINT
impl_->SetCUDAStream(stream, clear);
}
Expand Down
Loading