Skip to content

[SYCL] handle wrap around in HW timestamp #2571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3100,7 +3100,20 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName,
case PI_PROFILING_INFO_COMMAND_END: {
zeEventQueryKernelTimestamp(Event->ZeEvent, &tsResult);

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

return ReturnValue(uint64_t{ContextEndTime});
Expand Down