@@ -142,8 +142,7 @@ struct ur_context_handle_t_ : _ur_object {
142
142
//
143
143
// Cache of event pools to which host-visible events are added to.
144
144
std::vector<std::list<ze_event_pool_handle_t >> ZeEventPoolCache{4 };
145
- std::vector<std::unordered_map<ze_device_handle_t ,
146
- std::list<ze_event_pool_handle_t > *>>
145
+ std::vector<std::unordered_map<ze_device_handle_t , size_t >>
147
146
ZeEventPoolCacheDeviceMap{4 };
148
147
149
148
// This map will be used to determine if a pool is full or not
@@ -165,9 +164,9 @@ struct ur_context_handle_t_ : _ur_object {
165
164
ur_mutex EventCacheMutex;
166
165
167
166
// Caches for events.
168
- std::vector<std::list<ur_event_handle_t >> EventCaches{ 4 } ;
169
- std::vector<
170
- std::unordered_map< ur_device_handle_t , std::list< ur_event_handle_t > * >>
167
+ using EventCache = std::vector<std::list<ur_event_handle_t >>;
168
+ EventCache EventCaches{ 4 };
169
+ std::vector< std::unordered_map< ur_device_handle_t , size_t >>
171
170
EventCachesDeviceMap{4 };
172
171
173
172
// Initialize the PI context.
@@ -205,18 +204,20 @@ struct ur_context_handle_t_ : _ur_object {
205
204
// Add ur_event_handle_t to cache.
206
205
void addEventToContextCache (ur_event_handle_t );
207
206
208
- auto getZeEventPoolCache (bool HostVisible, bool WithProfiling,
209
- ze_device_handle_t ZeDevice) {
207
+ std::list<ze_event_pool_handle_t > *
208
+ getZeEventPoolCache (bool HostVisible, bool WithProfiling,
209
+ ze_device_handle_t ZeDevice) {
210
210
if (HostVisible) {
211
211
if (ZeDevice) {
212
212
auto ZeEventPoolCacheMap = WithProfiling
213
213
? &ZeEventPoolCacheDeviceMap[0 ]
214
214
: &ZeEventPoolCacheDeviceMap[1 ];
215
215
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
216
216
ZeEventPoolCache.emplace_back ();
217
- (*ZeEventPoolCacheMap)[ZeDevice] = &ZeEventPoolCache.back ();
217
+ ZeEventPoolCacheMap->insert (
218
+ std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
218
219
}
219
- return (*ZeEventPoolCacheMap)[ZeDevice];
220
+ return &ZeEventPoolCache[ (*ZeEventPoolCacheMap)[ZeDevice] ];
220
221
} else {
221
222
return WithProfiling ? &ZeEventPoolCache[0 ] : &ZeEventPoolCache[1 ];
222
223
}
@@ -227,9 +228,10 @@ struct ur_context_handle_t_ : _ur_object {
227
228
: &ZeEventPoolCacheDeviceMap[3 ];
228
229
if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
229
230
ZeEventPoolCache.emplace_back ();
230
- (*ZeEventPoolCacheMap)[ZeDevice] = &ZeEventPoolCache.back ();
231
+ ZeEventPoolCacheMap->insert (
232
+ std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
231
233
}
232
- return (*ZeEventPoolCacheMap)[ZeDevice];
234
+ return &ZeEventPoolCache[ (*ZeEventPoolCacheMap)[ZeDevice] ];
233
235
} else {
234
236
return WithProfiling ? &ZeEventPoolCache[2 ] : &ZeEventPoolCache[3 ];
235
237
}
@@ -280,9 +282,10 @@ struct ur_context_handle_t_ : _ur_object {
280
282
WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
281
283
if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
282
284
EventCaches.emplace_back ();
283
- (*EventCachesMap)[Device] = &EventCaches.back ();
285
+ EventCachesMap->insert (
286
+ std::make_pair (Device, EventCaches.size () - 1 ));
284
287
}
285
- return (*EventCachesMap)[Device];
288
+ return &EventCaches[ (*EventCachesMap)[Device] ];
286
289
} else {
287
290
return WithProfiling ? &EventCaches[0 ] : &EventCaches[1 ];
288
291
}
@@ -292,9 +295,10 @@ struct ur_context_handle_t_ : _ur_object {
292
295
WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
293
296
if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
294
297
EventCaches.emplace_back ();
295
- (*EventCachesMap)[Device] = &EventCaches.back ();
298
+ EventCachesMap->insert (
299
+ std::make_pair (Device, EventCaches.size () - 1 ));
296
300
}
297
- return (*EventCachesMap)[Device];
301
+ return &EventCaches[ (*EventCachesMap)[Device] ];
298
302
} else {
299
303
return WithProfiling ? &EventCaches[2 ] : &EventCaches[3 ];
300
304
}
0 commit comments