From c5786be10719497170ed5b0c401edd827b041dda Mon Sep 17 00:00:00 2001 From: ronnywang Date: Wed, 30 Aug 2023 13:02:49 +0800 Subject: [PATCH] [CustomDevice] Fix error that query a destroyed event (#56745) --- .../memory/allocation/stream_safe_custom_device_allocator.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/memory/allocation/stream_safe_custom_device_allocator.cc b/paddle/fluid/memory/allocation/stream_safe_custom_device_allocator.cc index b88f40f6a27..ce63ab807e0 100644 --- a/paddle/fluid/memory/allocation/stream_safe_custom_device_allocator.cc +++ b/paddle/fluid/memory/allocation/stream_safe_custom_device_allocator.cc @@ -88,8 +88,7 @@ bool StreamSafeCustomDeviceAllocation::CanBeFreed() { } std::call_once(once_flag_, [this] { phi::DeviceManager::SetDevice(place_); }); for (auto it = outstanding_event_map_.begin(); - it != outstanding_event_map_.end(); - ++it) { + it != outstanding_event_map_.end();) { auto& event = it->second; if (!event->Query()) { VLOG(9) << "Event " << event->raw_event() << " for " << ptr() @@ -98,6 +97,7 @@ bool StreamSafeCustomDeviceAllocation::CanBeFreed() { } VLOG(8) << "Destroy event " << event->raw_event(); event->Destroy(); + it = outstanding_event_map_.erase(it); } outstanding_event_map_.clear(); return true; -- GitLab