From bc585bd8de6f2b080b9d513f9f97e0b41decd8b6 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 6 Jul 2023 23:00:50 +0000 Subject: [PATCH] Force clock sync on profiling enablement Fix a condition where we can get a divide-by-zero in the TranslateTime(tick) function if the GPU tick predates HSA startup and we did not do a SyncClocks since initialization. Change-Id: I0dcec8553ccb8f01211928991f4b3ed3cb4a1ebb --- runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp index effe251fbf..d86a113e31 100644 --- a/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp +++ b/runtime/hsa-runtime/core/runtime/amd_gpu_agent.cpp @@ -1034,6 +1034,12 @@ hsa_status_t GpuAgent::EnableDmaProfiling(bool enable) { } } + // If we did not update t1 since agent initialization, force a SyncClock. Otherwise computing + // the SystemClockCounter to GPUClockCounter ratio in TranslateTime(tick) results to a division + // by 0. We perform the check here because we do not want to check everytime there is a call to + // TranslateTime(tick) + if (enable && t0_.GPUClockCounter == t1_.GPUClockCounter) SyncClocks(); + return HSA_STATUS_SUCCESS; }