From b969c32ab15cff4ae3b72027b6268d38abe2e174 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Fri, 20 Nov 2020 19:10:16 +0800 Subject: [PATCH] fix occupied 0 device memory bug (#28771) --- paddle/fluid/operators/reader/buffered_reader.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/paddle/fluid/operators/reader/buffered_reader.cc b/paddle/fluid/operators/reader/buffered_reader.cc index f13b0d800bd..8da6c4d08eb 100644 --- a/paddle/fluid/operators/reader/buffered_reader.cc +++ b/paddle/fluid/operators/reader/buffered_reader.cc @@ -104,6 +104,12 @@ void BufferedReader::ReadAsync(size_t i) { std::vector cuda_pinned_ptrs; cuda_pinned_ptrs.reserve(cpu.size()); platform::RecordEvent record_event("BufferedReader:MemoryCopy"); + // NODE(chenwehiang): When we use CUDAPinned Memory, we need call + // cudaHostAlloc, that is a CUDA API, calling CUDA API need load + // cuda lib into device, it will cost hundreds of MB of GPU memory. + // If we don't set Device here, which will use CUDAPlace(0) default. + platform::SetDeviceId( + BOOST_GET_CONST(platform::CUDAPlace, place_).device); for (size_t i = 0; i < cpu.size(); ++i) { if (platform::is_cpu_place(cpu[i].place())) { cuda[i].Resize(cpu[i].dims()); -- GitLab