Skip to content

Commit 4e1f63d

Browse files
DeviceCache builder uses try/catch (#738)
If exception ocurred, error handler is invoked, and the device->context map is not cached. std::terminate call was removed (dead code).
1 parent f3160da commit 4e1f63d

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

libsyclinterface/source/dpctl_sycl_device_manager.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,18 @@ struct DeviceCacheBuilder
126126
if (mRanker(D) < 0)
127127
continue;
128128

129-
// Per https://github.com/intel/llvm/blob/sycl/sycl/doc/
130-
// extensions/PlatformContext/PlatformContext.adoc
131-
// sycl::queue(D) would create default platform context
132-
// for capable compiler, sycl::context(D) otherwise
133-
auto Q = queue(D);
134-
auto Ctx = Q.get_context();
135-
auto entry = cache_l.emplace(D, Ctx);
136-
137-
if (!entry.second) {
138-
error_handler("Fatal Error during device cache "
139-
"construction.",
140-
__FILE__, __func__, __LINE__);
141-
std::terminate();
129+
try {
130+
// Per https://github.com/intel/llvm/blob/sycl/sycl/doc/
131+
// extensions/PlatformContext/PlatformContext.adoc
132+
// sycl::queue(D) would create default platform context
133+
// for capable compiler, sycl::context(D) otherwise
134+
auto Q = queue(D);
135+
auto Ctx = Q.get_context();
136+
cache_l.emplace(D, Ctx);
137+
} catch (const std::exception &e) {
138+
// Nothing is added to the cache_l by guarantees of
139+
// emplace
140+
error_handler(e, __FILE__, __func__, __LINE__);
142141
}
143142
}
144143
}

0 commit comments

Comments
 (0)