Skip to content

Commit 5d2babf

Browse files
[SYCL] Fix uncaught exception in ~DeviceGlobalUSMMem() (#20581)
1 parent ec5d354 commit 5d2babf

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

sycl/source/detail/device_global_map_entry.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <detail/memory_manager.hpp>
1313
#include <detail/queue_impl.hpp>
1414
#include <detail/usm/usm_impl.hpp>
15+
#include <sycl/detail/common.hpp>
1516

1617
namespace sycl {
1718
inline namespace _V1 {
@@ -21,16 +22,21 @@ DeviceGlobalUSMMem::~DeviceGlobalUSMMem() {
2122
// removeAssociatedResources is expected to have cleaned up both the pointer
2223
// and the event. When asserts are enabled the values are set, so we check
2324
// these here.
24-
auto ContextImplPtr = MAllocatingContext.lock();
25-
if (ContextImplPtr) {
26-
if (MPtr != nullptr) {
27-
detail::usm::freeInternal(MPtr, ContextImplPtr.get());
28-
MPtr = nullptr;
29-
}
30-
if (MInitEvent != nullptr) {
31-
ContextImplPtr->getAdapter().call<UrApiKind::urEventRelease>(MInitEvent);
32-
MInitEvent = nullptr;
25+
try {
26+
auto ContextImplPtr = MAllocatingContext.lock();
27+
if (ContextImplPtr) {
28+
if (MPtr != nullptr) {
29+
detail::usm::freeInternal(MPtr, ContextImplPtr.get());
30+
MPtr = nullptr;
31+
}
32+
if (MInitEvent != nullptr) {
33+
ContextImplPtr->getAdapter().call<UrApiKind::urEventRelease>(
34+
MInitEvent);
35+
MInitEvent = nullptr;
36+
}
3337
}
38+
} catch (std::exception &e) {
39+
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~DeviceGlobalUSMMem", e);
3440
}
3541

3642
assert(MPtr == nullptr && "MPtr has not been cleaned up.");

0 commit comments

Comments
 (0)