@@ -113,12 +113,18 @@ struct DeviceCacheBuilder
113
113
* post-creation we do not need any further protection to ensure
114
114
* thread-safety.
115
115
*/
116
- static const DeviceCache &getDeviceCache ()
116
+ static const DeviceCache &getDeviceCache () noexcept
117
117
{
118
118
static DeviceCache *cache = new DeviceCache ([] {
119
- DeviceCache cache_l;
119
+ DeviceCache cache_l{} ;
120
120
dpctl_default_selector mRanker ;
121
- auto Platforms = platform::get_platforms ();
121
+ std::vector<platform> Platforms{};
122
+ try {
123
+ Platforms = platform::get_platforms ();
124
+ } catch (std::exception const &e) {
125
+ error_handler (e, __FILE__, __func__, __LINE__);
126
+ return cache_l;
127
+ }
122
128
for (const auto &P : Platforms) {
123
129
auto Devices = P.get_devices ();
124
130
for (const auto &D : Devices) {
@@ -169,7 +175,15 @@ DPCTLDeviceMgr_GetCachedContext(__dpctl_keep const DPCTLSyclDeviceRef DRef)
169
175
__FILE__, __func__, __LINE__);
170
176
return CRef;
171
177
}
172
- auto &cache = DeviceCacheBuilder::getDeviceCache ();
178
+
179
+ using CacheT = typename DeviceCacheBuilder::DeviceCache;
180
+ CacheT const &cache = DeviceCacheBuilder::getDeviceCache ();
181
+
182
+ if (cache.empty ()) {
183
+ // an exception was caught and logged by getDeviceCache
184
+ return nullptr ;
185
+ }
186
+
173
187
auto entry = cache.find (*Device);
174
188
if (entry != cache.end ()) {
175
189
context *ContextPtr = nullptr ;
@@ -289,7 +303,13 @@ int DPCTLDeviceMgr_GetPositionInDevices(__dpctl_keep DPCTLSyclDeviceRef DRef,
289
303
size_t DPCTLDeviceMgr_GetNumDevices (int device_identifier)
290
304
{
291
305
size_t nDevices = 0 ;
292
- auto &cache = DeviceCacheBuilder::getDeviceCache ();
306
+ using CacheT = typename DeviceCacheBuilder::DeviceCache;
307
+ CacheT const &cache = DeviceCacheBuilder::getDeviceCache ();
308
+
309
+ if (cache.empty ()) {
310
+ // an exception was caught and logged by getDeviceCache
311
+ return 0 ;
312
+ }
293
313
294
314
device_identifier = to_canonical_device_id (device_identifier);
295
315
if (!device_identifier)
0 commit comments