@@ -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;
144
+ std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{ 4 } ;
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;
168
+ std::vector<std::list<ur_event_handle_t >> EventCaches{ 4 } ;
169
169
std::vector<
170
170
std::unordered_map<ur_device_handle_t , std::list<ur_event_handle_t > *>>
171
171
EventCachesDeviceMap{4 };
@@ -207,44 +207,31 @@ 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
- }
219
210
if (HostVisible) {
220
211
if (ZeDevice) {
221
212
auto ZeEventPoolCacheMap = WithProfiling
222
213
? &ZeEventPoolCacheDeviceMap[0 ]
223
214
: &ZeEventPoolCacheDeviceMap[1 ];
224
215
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
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;
216
+ ZeEventPoolCache.emplace_back ();
217
+ (*ZeEventPoolCacheMap)[ZeDevice] = &ZeEventPoolCache.back ();
229
218
}
230
219
return (*ZeEventPoolCacheMap)[ZeDevice];
231
220
} else {
232
- return WithProfiling ? ZeEventPoolCache[0 ] : ZeEventPoolCache[1 ];
221
+ return WithProfiling ? & ZeEventPoolCache[0 ] : & ZeEventPoolCache[1 ];
233
222
}
234
223
} else {
235
224
if (ZeDevice) {
236
225
auto ZeEventPoolCacheMap = WithProfiling
237
226
? &ZeEventPoolCacheDeviceMap[2 ]
238
227
: &ZeEventPoolCacheDeviceMap[3 ];
239
228
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
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;
229
+ ZeEventPoolCache.emplace_back ();
230
+ (*ZeEventPoolCacheMap)[ZeDevice] = &ZeEventPoolCache.back ();
244
231
}
245
232
return (*ZeEventPoolCacheMap)[ZeDevice];
246
233
} else {
247
- return WithProfiling ? ZeEventPoolCache[2 ] : ZeEventPoolCache[3 ];
234
+ return WithProfiling ? & ZeEventPoolCache[2 ] : & ZeEventPoolCache[3 ];
248
235
}
249
236
}
250
237
}
@@ -287,42 +274,29 @@ struct ur_context_handle_t_ : _ur_object {
287
274
// Get the cache of events for a provided scope and profiling mode.
288
275
auto getEventCache (bool HostVisible, bool WithProfiling,
289
276
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
- }
299
277
if (HostVisible) {
300
278
if (Device) {
301
279
auto EventCachesMap =
302
280
WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
303
281
if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
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;
282
+ EventCaches.emplace_back ();
283
+ (*EventCachesMap)[Device] = &EventCaches.back ();
308
284
}
309
285
return (*EventCachesMap)[Device];
310
286
} else {
311
- return WithProfiling ? EventCaches[0 ] : EventCaches[1 ];
287
+ return WithProfiling ? & EventCaches[0 ] : & EventCaches[1 ];
312
288
}
313
289
} else {
314
290
if (Device) {
315
291
auto EventCachesMap =
316
292
WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
317
293
if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
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;
294
+ EventCaches.emplace_back ();
295
+ (*EventCachesMap)[Device] = &EventCaches.back ();
322
296
}
323
297
return (*EventCachesMap)[Device];
324
298
} else {
325
- return WithProfiling ? EventCaches[2 ] : EventCaches[3 ];
299
+ return WithProfiling ? & EventCaches[2 ] : & EventCaches[3 ];
326
300
}
327
301
}
328
302
}
0 commit comments