From 8131b311982e26c23e376c42476fd1e65aa4ac3c Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Fri, 11 Feb 2022 13:15:03 -0800 Subject: [PATCH] [SYCL][L0] Fix timestamp calculation (in ns) Signed-off-by: Sergey V Maslov --- sycl/plugins/level_zero/pi_level_zero.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index dda8ae72e976a..7c7b24307091f 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -5105,6 +5105,8 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName, Event->Queue ? Event->Queue->Device->ZeDeviceProperties->timerResolution : Event->Context->Devices[0]->ZeDeviceProperties->timerResolution; + // Get timestamp frequency + const double ZeTimerFreq = 1E09 / ZeTimerResolution; ReturnHelper ReturnValue(ParamValueSize, ParamValue, ParamValueSizeRet); @@ -5113,11 +5115,8 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName, switch (ParamName) { case PI_PROFILING_INFO_COMMAND_START: { ZE_CALL(zeEventQueryKernelTimestamp, (Event->ZeEvent, &tsResult)); - - uint64_t ContextStartTime = tsResult.context.kernelStart; - ContextStartTime *= ZeTimerResolution; - - return ReturnValue(uint64_t{ContextStartTime}); + uint64_t ContextStartTime = tsResult.context.kernelStart * ZeTimerFreq; + return ReturnValue(ContextStartTime); } case PI_PROFILING_INFO_COMMAND_END: { ZE_CALL(zeEventQueryKernelTimestamp, (Event->ZeEvent, &tsResult)); @@ -5136,9 +5135,8 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName, (1LL << Device->ZeDeviceProperties->kernelTimestampValidBits) - 1; ContextEndTime += TimestampMaxValue - ContextStartTime; } - ContextEndTime *= ZeTimerResolution; - - return ReturnValue(uint64_t{ContextEndTime}); + ContextEndTime *= ZeTimerFreq; + return ReturnValue(ContextEndTime); } case PI_PROFILING_INFO_COMMAND_QUEUED: case PI_PROFILING_INFO_COMMAND_SUBMIT: