@@ -141,7 +141,7 @@ struct ur_context_handle_t_ : _ur_object {
141
141
// head.
142
142
//
143
143
// Cache of event pools to which host-visible events are added to.
144
- std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{ 4 } ;
144
+ std::vector<std::list<ze_event_pool_handle_t > * > ZeEventPoolCache;
145
145
std::vector<std::unordered_map<ze_device_handle_t ,
146
146
std::list<ze_event_pool_handle_t > *>>
147
147
ZeEventPoolCacheDeviceMap{4 };
@@ -165,7 +165,7 @@ struct ur_context_handle_t_ : _ur_object {
165
165
ur_mutex EventCacheMutex;
166
166
167
167
// Caches for events.
168
- std::vector<std::list<ur_event_handle_t >> EventCaches{ 4 } ;
168
+ std::vector<std::list<ur_event_handle_t > * > EventCaches;
169
169
std::vector<
170
170
std::unordered_map<ur_device_handle_t , std::list<ur_event_handle_t > *>>
171
171
EventCachesDeviceMap{4 };
@@ -207,31 +207,44 @@ struct ur_context_handle_t_ : _ur_object {
207
207
208
208
auto getZeEventPoolCache (bool HostVisible, bool WithProfiling,
209
209
ze_device_handle_t ZeDevice) {
210
+ // Adding 4 initial global caches for provided scope and profiling modes:
211
+ // Host Scope, Device Scope, with Profiling, without Profiling.
212
+ if (ZeEventPoolCache.empty ()) {
213
+ for (int i = 0 ; i < 4 ; i++) {
214
+ std::list<ze_event_pool_handle_t > *deviceZeEventPoolCache =
215
+ new std::list<ze_event_pool_handle_t >;
216
+ ZeEventPoolCache.push_back (deviceZeEventPoolCache);
217
+ }
218
+ }
210
219
if (HostVisible) {
211
220
if (ZeDevice) {
212
221
auto ZeEventPoolCacheMap = WithProfiling
213
222
? &ZeEventPoolCacheDeviceMap[0 ]
214
223
: &ZeEventPoolCacheDeviceMap[1 ];
215
224
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
216
- ZeEventPoolCache.emplace_back ();
217
- (*ZeEventPoolCacheMap)[ZeDevice] = &ZeEventPoolCache.back ();
225
+ std::list<ze_event_pool_handle_t > *deviceZeEventPoolCache =
226
+ new std::list<ze_event_pool_handle_t >;
227
+ ZeEventPoolCache.push_back (deviceZeEventPoolCache);
228
+ (*ZeEventPoolCacheMap)[ZeDevice] = deviceZeEventPoolCache;
218
229
}
219
230
return (*ZeEventPoolCacheMap)[ZeDevice];
220
231
} else {
221
- return WithProfiling ? & ZeEventPoolCache[0 ] : & ZeEventPoolCache[1 ];
232
+ return WithProfiling ? ZeEventPoolCache[0 ] : ZeEventPoolCache[1 ];
222
233
}
223
234
} else {
224
235
if (ZeDevice) {
225
236
auto ZeEventPoolCacheMap = WithProfiling
226
237
? &ZeEventPoolCacheDeviceMap[2 ]
227
238
: &ZeEventPoolCacheDeviceMap[3 ];
228
239
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
229
- ZeEventPoolCache.emplace_back ();
230
- (*ZeEventPoolCacheMap)[ZeDevice] = &ZeEventPoolCache.back ();
240
+ std::list<ze_event_pool_handle_t > *deviceZeEventPoolCache =
241
+ new std::list<ze_event_pool_handle_t >;
242
+ ZeEventPoolCache.push_back (deviceZeEventPoolCache);
243
+ (*ZeEventPoolCacheMap)[ZeDevice] = deviceZeEventPoolCache;
231
244
}
232
245
return (*ZeEventPoolCacheMap)[ZeDevice];
233
246
} else {
234
- return WithProfiling ? & ZeEventPoolCache[2 ] : & ZeEventPoolCache[3 ];
247
+ return WithProfiling ? ZeEventPoolCache[2 ] : ZeEventPoolCache[3 ];
235
248
}
236
249
}
237
250
}
@@ -274,29 +287,42 @@ struct ur_context_handle_t_ : _ur_object {
274
287
// Get the cache of events for a provided scope and profiling mode.
275
288
auto getEventCache (bool HostVisible, bool WithProfiling,
276
289
ur_device_handle_t Device) {
290
+ // Adding 4 initial global caches for provided scope and profiling modes:
291
+ // Host Scope, Device Scope, with Profiling, without Profiling.
292
+ if (EventCaches.empty ()) {
293
+ for (int i = 0 ; i < 4 ; i++) {
294
+ std::list<ur_event_handle_t > *deviceEventCache =
295
+ new std::list<ur_event_handle_t >;
296
+ EventCaches.push_back (deviceEventCache);
297
+ }
298
+ }
277
299
if (HostVisible) {
278
300
if (Device) {
279
301
auto EventCachesMap =
280
302
WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
281
303
if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
282
- EventCaches.emplace_back ();
283
- (*EventCachesMap)[Device] = &EventCaches.back ();
304
+ std::list<ur_event_handle_t > *deviceEventCache =
305
+ new std::list<ur_event_handle_t >;
306
+ EventCaches.push_back (deviceEventCache);
307
+ (*EventCachesMap)[Device] = deviceEventCache;
284
308
}
285
309
return (*EventCachesMap)[Device];
286
310
} else {
287
- return WithProfiling ? & EventCaches[0 ] : & EventCaches[1 ];
311
+ return WithProfiling ? EventCaches[0 ] : EventCaches[1 ];
288
312
}
289
313
} else {
290
314
if (Device) {
291
315
auto EventCachesMap =
292
316
WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
293
317
if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
294
- EventCaches.emplace_back ();
295
- (*EventCachesMap)[Device] = &EventCaches.back ();
318
+ std::list<ur_event_handle_t > *deviceEventCache =
319
+ new std::list<ur_event_handle_t >;
320
+ EventCaches.push_back (deviceEventCache);
321
+ (*EventCachesMap)[Device] = deviceEventCache;
296
322
}
297
323
return (*EventCachesMap)[Device];
298
324
} else {
299
- return WithProfiling ? & EventCaches[2 ] : & EventCaches[3 ];
325
+ return WithProfiling ? EventCaches[2 ] : EventCaches[3 ];
300
326
}
301
327
}
302
328
}
0 commit comments