Skip to content

Commit eb3df08

Browse files
[SYCL] handle wrap around in HW timestamp (#2571)
Signed-off-by: Sergey V Maslov <sergey.v.maslov@intel.com>
1 parent d88ef3b commit eb3df08

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,7 +3128,20 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName,
31283128
case PI_PROFILING_INFO_COMMAND_END: {
31293129
zeEventQueryKernelTimestamp(Event->ZeEvent, &tsResult);
31303130

3131+
uint64_t ContextStartTime = tsResult.context.kernelStart;
31313132
uint64_t ContextEndTime = tsResult.context.kernelEnd;
3133+
//
3134+
// Handle a possible wrap-around (the underlying HW counter is < 64-bit).
3135+
// Note, it will not report correct time if there were multiple wrap
3136+
// arounds, and the longer term plan is to enlarge the capacity of the
3137+
// HW timestamps.
3138+
//
3139+
if (ContextEndTime <= ContextStartTime) {
3140+
pi_device Device = Event->Context->Devices[0];
3141+
const uint64_t TimestampMaxValue =
3142+
(1LL << Device->ZeDeviceProperties.kernelTimestampValidBits) - 1;
3143+
ContextEndTime += TimestampMaxValue - ContextStartTime;
3144+
}
31323145
ContextEndTime *= ZeTimerResolution;
31333146

31343147
return ReturnValue(uint64_t{ContextEndTime});

0 commit comments

Comments
 (0)