@@ -142,8 +142,7 @@ struct ur_context_handle_t_ : _ur_object {
142142 //
143143 // Cache of event pools to which host-visible events are added to.
144144 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 >>
147146 ZeEventPoolCacheDeviceMap{4 };
148147
149148 // 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 {
165164 ur_mutex EventCacheMutex;
166165
167166 // 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 >>
171170 EventCachesDeviceMap{4 };
172171
173172 // Initialize the PI context.
@@ -205,18 +204,20 @@ struct ur_context_handle_t_ : _ur_object {
205204 // Add ur_event_handle_t to cache.
206205 void addEventToContextCache (ur_event_handle_t );
207206
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) {
210210 if (HostVisible) {
211211 if (ZeDevice) {
212212 auto ZeEventPoolCacheMap = WithProfiling
213213 ? &ZeEventPoolCacheDeviceMap[0 ]
214214 : &ZeEventPoolCacheDeviceMap[1 ];
215215 if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
216216 ZeEventPoolCache.emplace_back ();
217- (*ZeEventPoolCacheMap)[ZeDevice] = &ZeEventPoolCache.back ();
217+ ZeEventPoolCacheMap->insert (
218+ std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
218219 }
219- return (*ZeEventPoolCacheMap)[ZeDevice];
220+ return &ZeEventPoolCache[ (*ZeEventPoolCacheMap)[ZeDevice] ];
220221 } else {
221222 return WithProfiling ? &ZeEventPoolCache[0 ] : &ZeEventPoolCache[1 ];
222223 }
@@ -227,9 +228,10 @@ struct ur_context_handle_t_ : _ur_object {
227228 : &ZeEventPoolCacheDeviceMap[3 ];
228229 if (ZeEventPoolCacheMap->find (ZeDevice) == ZeEventPoolCacheMap->end ()) {
229230 ZeEventPoolCache.emplace_back ();
230- (*ZeEventPoolCacheMap)[ZeDevice] = &ZeEventPoolCache.back ();
231+ ZeEventPoolCacheMap->insert (
232+ std::make_pair (ZeDevice, ZeEventPoolCache.size () - 1 ));
231233 }
232- return (*ZeEventPoolCacheMap)[ZeDevice];
234+ return &ZeEventPoolCache[ (*ZeEventPoolCacheMap)[ZeDevice] ];
233235 } else {
234236 return WithProfiling ? &ZeEventPoolCache[2 ] : &ZeEventPoolCache[3 ];
235237 }
@@ -280,9 +282,10 @@ struct ur_context_handle_t_ : _ur_object {
280282 WithProfiling ? &EventCachesDeviceMap[0 ] : &EventCachesDeviceMap[1 ];
281283 if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
282284 EventCaches.emplace_back ();
283- (*EventCachesMap)[Device] = &EventCaches.back ();
285+ EventCachesMap->insert (
286+ std::make_pair (Device, EventCaches.size () - 1 ));
284287 }
285- return (*EventCachesMap)[Device];
288+ return &EventCaches[ (*EventCachesMap)[Device] ];
286289 } else {
287290 return WithProfiling ? &EventCaches[0 ] : &EventCaches[1 ];
288291 }
@@ -292,9 +295,10 @@ struct ur_context_handle_t_ : _ur_object {
292295 WithProfiling ? &EventCachesDeviceMap[2 ] : &EventCachesDeviceMap[3 ];
293296 if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
294297 EventCaches.emplace_back ();
295- (*EventCachesMap)[Device] = &EventCaches.back ();
298+ EventCachesMap->insert (
299+ std::make_pair (Device, EventCaches.size () - 1 ));
296300 }
297- return (*EventCachesMap)[Device];
301+ return &EventCaches[ (*EventCachesMap)[Device] ];
298302 } else {
299303 return WithProfiling ? &EventCaches[2 ] : &EventCaches[3 ];
300304 }
0 commit comments