@@ -5147,8 +5147,15 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName,
51475147 Event->Queue
51485148 ? Event->Queue ->Device ->ZeDeviceProperties ->timerResolution
51495149 : Event->Context ->Devices [0 ]->ZeDeviceProperties ->timerResolution ;
5150- // Get timestamp frequency
5151- const double ZeTimerFreq = 1E09 / ZeTimerResolution;
5150+
5151+ const uint64_t TimestampMaxValue =
5152+ Event->Queue
5153+ ? ((1ULL << Event->Queue ->Device ->ZeDeviceProperties
5154+ ->kernelTimestampValidBits ) -
5155+ 1ULL )
5156+ : ((1ULL << Event->Context ->Devices [0 ]
5157+ ->ZeDeviceProperties ->kernelTimestampValidBits ) -
5158+ 1ULL );
51525159
51535160 ReturnHelper ReturnValue (ParamValueSize, ParamValue, ParamValueSizeRet);
51545161
@@ -5157,27 +5164,27 @@ pi_result piEventGetProfilingInfo(pi_event Event, pi_profiling_info ParamName,
51575164 switch (ParamName) {
51585165 case PI_PROFILING_INFO_COMMAND_START: {
51595166 ZE_CALL (zeEventQueryKernelTimestamp, (Event->ZeEvent , &tsResult));
5160- uint64_t ContextStartTime = tsResult.context .kernelStart * ZeTimerFreq;
5167+ uint64_t ContextStartTime =
5168+ (tsResult.context .kernelStart & TimestampMaxValue) * ZeTimerResolution;
51615169 return ReturnValue (ContextStartTime);
51625170 }
51635171 case PI_PROFILING_INFO_COMMAND_END: {
51645172 ZE_CALL (zeEventQueryKernelTimestamp, (Event->ZeEvent , &tsResult));
51655173
5166- uint64_t ContextStartTime = tsResult.context .kernelStart ;
5167- uint64_t ContextEndTime = tsResult.context .kernelEnd ;
5174+ uint64_t ContextStartTime =
5175+ (tsResult.context .kernelStart & TimestampMaxValue);
5176+ uint64_t ContextEndTime = (tsResult.context .kernelEnd & TimestampMaxValue);
5177+
51685178 //
51695179 // Handle a possible wrap-around (the underlying HW counter is < 64-bit).
51705180 // Note, it will not report correct time if there were multiple wrap
51715181 // arounds, and the longer term plan is to enlarge the capacity of the
51725182 // HW timestamps.
51735183 //
51745184 if (ContextEndTime <= ContextStartTime) {
5175- pi_device Device = Event->Context ->Devices [0 ];
5176- const uint64_t TimestampMaxValue =
5177- (1LL << Device->ZeDeviceProperties ->kernelTimestampValidBits ) - 1 ;
5178- ContextEndTime += TimestampMaxValue - ContextStartTime;
5185+ ContextEndTime += TimestampMaxValue;
51795186 }
5180- ContextEndTime *= ZeTimerFreq ;
5187+ ContextEndTime *= ZeTimerResolution ;
51815188 return ReturnValue (ContextEndTime);
51825189 }
51835190 case PI_PROFILING_INFO_COMMAND_QUEUED:
0 commit comments