@@ -39,6 +39,13 @@ struct ur_context_handle_t_ : _ur_object {
3939 : ZeContext{ZeContext}, Devices{Devs, Devs + NumDevices},
4040 NumDevices{NumDevices} {
4141 OwnNativeHandle = OwnZeContext;
42+ for (const auto &Device : Devices) {
43+ for (int i = 0 ; i < EventCacheTypeCount; i++) {
44+ EventCaches.emplace_back ();
45+ EventCachesDeviceMap[i].insert (
46+ std::make_pair (Device, EventCaches.size () - 1 ));
47+ }
48+ }
4249 }
4350
4451 ur_context_handle_t_ (ze_context_handle_t ZeContext) : ZeContext{ZeContext} {}
@@ -333,11 +340,6 @@ struct ur_context_handle_t_ : _ur_object {
333340 auto EventCachesMap =
334341 WithProfiling ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
335342 : &EventCachesDeviceMap[HostVisibleRegularCacheType];
336- if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
337- EventCaches.emplace_back ();
338- EventCachesMap->insert (
339- std::make_pair (Device, EventCaches.size () - 1 ));
340- }
341343 return &EventCaches[(*EventCachesMap)[Device]];
342344 } else {
343345 return WithProfiling ? &EventCaches[HostVisibleProfilingCacheType]
@@ -349,11 +351,6 @@ struct ur_context_handle_t_ : _ur_object {
349351 WithProfiling
350352 ? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
351353 : &EventCachesDeviceMap[HostInvisibleRegularCacheType];
352- if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
353- EventCaches.emplace_back ();
354- EventCachesMap->insert (
355- std::make_pair (Device, EventCaches.size () - 1 ));
356- }
357354 return &EventCaches[(*EventCachesMap)[Device]];
358355 } else {
359356 return WithProfiling ? &EventCaches[HostInvisibleProfilingCacheType]
@@ -369,11 +366,6 @@ struct ur_context_handle_t_ : _ur_object {
369366 WithProfiling
370367 ? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
371368 : &EventCachesDeviceMap[CounterBasedImmediateCacheType];
372- if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
373- EventCaches.emplace_back ();
374- EventCachesMap->insert (
375- std::make_pair (Device, EventCaches.size () - 1 ));
376- }
377369 return &EventCaches[(*EventCachesMap)[Device]];
378370 } else {
379371 return WithProfiling
@@ -386,11 +378,6 @@ struct ur_context_handle_t_ : _ur_object {
386378 WithProfiling
387379 ? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
388380 : &EventCachesDeviceMap[CounterBasedRegularCacheType];
389- if (EventCachesMap->find (Device) == EventCachesMap->end ()) {
390- EventCaches.emplace_back ();
391- EventCachesMap->insert (
392- std::make_pair (Device, EventCaches.size () - 1 ));
393- }
394381 return &EventCaches[(*EventCachesMap)[Device]];
395382 } else {
396383 return WithProfiling
0 commit comments