Skip to content

Commit 2657352

Browse files
committed
[UR][L0] Explicitly mark timestamped events
This is a workaround for a case where L0 driver fails to retrieve a timestamp but doesn't return an error. In such case, when event profiling info is queried we check the timestamp value and assume the event was not timestamped even though it was. This scenario can happen on newer platform with not yet full driver support.
1 parent ecbb9bf commit 2657352

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

unified-runtime/source/adapters/level_zero/event.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ ur_result_t urEventGetProfilingInfo(
531531
std::shared_lock<ur_shared_mutex> EventLock(Event->Mutex);
532532

533533
// The event must either have profiling enabled or be recording timestamps.
534-
bool isTimestampedEvent = Event->isTimestamped();
534+
bool isTimestampedEvent = Event->IsTimestamped;
535535
if (!Event->isProfilingEnabled() && !isTimestampedEvent) {
536536
return UR_RESULT_ERROR_PROFILING_INFO_NOT_AVAILABLE;
537537
}
@@ -764,6 +764,9 @@ ur_result_t urEnqueueTimestampRecordingExp(
764764
Device, &DeviceStartTimestamp, nullptr));
765765
(*OutEvent)->RecordEventStartTimestamp = DeviceStartTimestamp;
766766

767+
// Mark this event as timestamped
768+
(*OutEvent)->IsTimestamped = true;
769+
767770
// Create a new entry in the queue's recordings.
768771
Queue->EndTimeRecordings[*OutEvent] = 0;
769772

@@ -1141,7 +1144,7 @@ ur_result_t urEventReleaseInternal(ur_event_handle_t Event,
11411144

11421145
// If the event was a timestamp recording, we try to evict its entry in the
11431146
// queue.
1144-
if (Event->isTimestamped()) {
1147+
if (Event->IsTimestamped) {
11451148
auto Entry = Queue->EndTimeRecordings.find(Event);
11461149
if (Entry != Queue->EndTimeRecordings.end()) {
11471150
auto &EndTimeRecording = Entry->second;
@@ -1435,6 +1438,7 @@ ur_result_t ur_event_handle_t_::reset() {
14351438
CommandList = std::nullopt;
14361439
completionBatch = std::nullopt;
14371440
OriginAllocEvent = nullptr;
1441+
IsTimestamped = false;
14381442

14391443
if (!isHostVisible())
14401444
HostVisibleEvent = nullptr;
@@ -1767,12 +1771,3 @@ bool ur_event_handle_t_::isProfilingEnabled() const {
17671771
return !UrQueue || // tentatively assume user events are profiling enabled
17681772
(UrQueue->Properties & UR_QUEUE_FLAG_PROFILING_ENABLE) != 0;
17691773
}
1770-
1771-
// Tells if this event was created as a timestamp event, allowing profiling
1772-
// info even if profiling is not enabled.
1773-
bool ur_event_handle_t_::isTimestamped() const {
1774-
// If we are recording, the start time of the event will be non-zero. The
1775-
// end time might still be missing, depending on whether the corresponding
1776-
// enqueue is still running.
1777-
return RecordEventStartTimestamp != 0;
1778-
}

unified-runtime/source/adapters/level_zero/event.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ struct ur_event_handle_t_ : ur_object {
200200
// plugin.
201201
bool IsDiscarded = {false};
202202

203+
// Indicates that this is a timestamped event.
204+
bool IsTimestamped = {false};
205+
203206
// Indicates that this event is needed to be visible by multiple devices.
204207
// When possible, allocate Event from single device pool for optimal
205208
// performance
@@ -246,10 +249,6 @@ struct ur_event_handle_t_ : ur_object {
246249
// Tells if this event is with profiling capabilities.
247250
bool isProfilingEnabled() const;
248251

249-
// Tells if this event was created as a timestamp event, allowing profiling
250-
// info even if profiling is not enabled.
251-
bool isTimestamped() const;
252-
253252
// Get the host-visible event or create one and enqueue its signal.
254253
ur_result_t getOrCreateHostVisibleEvent(ze_event_handle_t &HostVisibleEvent);
255254

0 commit comments

Comments
 (0)