Skip to content

Commit 79fb832

Browse files
[L0] Fixed profiling fault in e2e
Signed-off-by: Winston Zhang <winston.zhang@intel.com>
1 parent 98f883d commit 79fb832

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

source/adapters/level_zero/context.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ ur_event_handle_t ur_context_handle_t_::getEventFromContextCache(
564564
std::scoped_lock<ur_mutex> Lock(EventCacheMutex);
565565
auto Cache = getEventCache(HostVisible, WithProfiling, Device);
566566
if (CounterBasedEventEnabled) {
567-
Cache = getCounterBasedEventCache(UsingImmCmdList, Device);
567+
Cache = getCounterBasedEventCache(WithProfiling, UsingImmCmdList, Device);
568568
}
569569
if (Cache->empty())
570570
return nullptr;
@@ -576,6 +576,7 @@ ur_event_handle_t ur_context_handle_t_::getEventFromContextCache(
576576
}
577577
Cache->erase(It);
578578
// We have to reset event before using it.
579+
// if(!CounterBasedEventEnabled)
579580
Event->reset();
580581
return Event;
581582
}
@@ -590,6 +591,7 @@ void ur_context_handle_t_::addEventToContextCache(ur_event_handle_t Event) {
590591

591592
if (Event->CounterBasedEventsEnabled) {
592593
auto Cache = getCounterBasedEventCache(
594+
Event->isProfilingEnabled(),
593595
!(Event->UrQueue) || (Event->UrQueue)->UsingImmCmdLists, Device);
594596
Cache->emplace_back(Event);
595597
} else {

source/adapters/level_zero/context.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ struct ur_context_handle_t_ : _ur_object {
235235
HostInvisibleRegularCacheType,
236236
CounterBasedImmediateCacheType,
237237
CounterBasedRegularCacheType,
238+
CounterBasedImmediateProfilingCacheType,
239+
CounterBasedRegularProfilingCacheType,
238240
EventCacheTypeCount
239241
};
240242

@@ -359,33 +361,41 @@ struct ur_context_handle_t_ : _ur_object {
359361
}
360362
}
361363
};
362-
auto getCounterBasedEventCache(bool UsingImmediateCmdList,
364+
auto getCounterBasedEventCache(bool WithProfiling, bool UsingImmediateCmdList,
363365
ur_device_handle_t Device) {
364366
if (UsingImmediateCmdList) {
365367
if (Device) {
366368
auto EventCachesMap =
367-
&EventCachesDeviceMap[CounterBasedImmediateCacheType];
369+
WithProfiling
370+
? &EventCachesDeviceMap[CounterBasedImmediateProfilingCacheType]
371+
: &EventCachesDeviceMap[CounterBasedImmediateCacheType];
368372
if (EventCachesMap->find(Device) == EventCachesMap->end()) {
369373
EventCaches.emplace_back();
370374
EventCachesMap->insert(
371375
std::make_pair(Device, EventCaches.size() - 1));
372376
}
373377
return &EventCaches[(*EventCachesMap)[Device]];
374378
} else {
375-
return &EventCaches[CounterBasedImmediateCacheType];
379+
return WithProfiling
380+
? &EventCaches[CounterBasedImmediateProfilingCacheType]
381+
: &EventCaches[CounterBasedImmediateCacheType];
376382
}
377383
} else {
378384
if (Device) {
379385
auto EventCachesMap =
380-
&EventCachesDeviceMap[CounterBasedRegularCacheType];
386+
WithProfiling
387+
? &EventCachesDeviceMap[CounterBasedRegularProfilingCacheType]
388+
: &EventCachesDeviceMap[CounterBasedRegularCacheType];
381389
if (EventCachesMap->find(Device) == EventCachesMap->end()) {
382390
EventCaches.emplace_back();
383391
EventCachesMap->insert(
384392
std::make_pair(Device, EventCaches.size() - 1));
385393
}
386394
return &EventCaches[(*EventCachesMap)[Device]];
387395
} else {
388-
return &EventCaches[CounterBasedRegularCacheType];
396+
return WithProfiling
397+
? &EventCaches[CounterBasedRegularProfilingCacheType]
398+
: &EventCaches[CounterBasedRegularCacheType];
389399
}
390400
}
391401
}

0 commit comments

Comments
 (0)