Skip to content

Commit

Permalink
[L0] Preallocate EventCachesDeviceMap on context creation
Browse files Browse the repository at this point in the history
Signed-off-by: Winston Zhang <[email protected]>
  • Loading branch information
winstonzhang-intel committed Sep 18, 2024
1 parent c0a24c3 commit ad11182
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions source/adapters/level_zero/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ struct ur_context_handle_t_ : _ur_object {
: ZeContext{ZeContext}, Devices{Devs, Devs + NumDevices},
NumDevices{NumDevices} {
OwnNativeHandle = OwnZeContext;
for (const auto &Device : Devices) {
for (int i = 0; i < EventCacheTypeCount; i++) {
EventCaches.emplace_back();
EventCachesDeviceMap[i].insert(
std::make_pair(Device, EventCaches.size() - 1));
}
}
}

ur_context_handle_t_(ze_context_handle_t ZeContext) : ZeContext{ZeContext} {}
Expand Down Expand Up @@ -333,11 +340,6 @@ struct ur_context_handle_t_ : _ur_object {
auto EventCachesMap =
WithProfiling ? &EventCachesDeviceMap[HostVisibleProfilingCacheType]
: &EventCachesDeviceMap[HostVisibleRegularCacheType];
if (EventCachesMap->find(Device) == EventCachesMap->end()) {
EventCaches.emplace_back();
EventCachesMap->insert(
std::make_pair(Device, EventCaches.size() - 1));
}
return &EventCaches[(*EventCachesMap)[Device]];
} else {
return WithProfiling ? &EventCaches[HostVisibleProfilingCacheType]
Expand All @@ -349,11 +351,6 @@ struct ur_context_handle_t_ : _ur_object {
WithProfiling
? &EventCachesDeviceMap[HostInvisibleProfilingCacheType]
: &EventCachesDeviceMap[HostInvisibleRegularCacheType];
if (EventCachesMap->find(Device) == EventCachesMap->end()) {
EventCaches.emplace_back();
EventCachesMap->insert(
std::make_pair(Device, EventCaches.size() - 1));
}
return &EventCaches[(*EventCachesMap)[Device]];
} else {
return WithProfiling ? &EventCaches[HostInvisibleProfilingCacheType]
Expand All @@ -369,11 +366,6 @@ struct ur_context_handle_t_ : _ur_object {
WithProfiling
? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
: &EventCachesDeviceMap[CounterBasedImmediateCacheType];
if (EventCachesMap->find(Device) == EventCachesMap->end()) {
EventCaches.emplace_back();
EventCachesMap->insert(
std::make_pair(Device, EventCaches.size() - 1));
}
return &EventCaches[(*EventCachesMap)[Device]];
} else {
return WithProfiling
Expand All @@ -386,11 +378,6 @@ struct ur_context_handle_t_ : _ur_object {
WithProfiling
? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
: &EventCachesDeviceMap[CounterBasedRegularCacheType];
if (EventCachesMap->find(Device) == EventCachesMap->end()) {
EventCaches.emplace_back();
EventCachesMap->insert(
std::make_pair(Device, EventCaches.size() - 1));
}
return &EventCaches[(*EventCachesMap)[Device]];
} else {
return WithProfiling
Expand Down

0 comments on commit ad11182

Please sign in to comment.