From 79400a1f2310f9d58bea2c9428d6ec14e709bba7 Mon Sep 17 00:00:00 2001 From: shwetakhatri-amd <155576586+shwetagkhatri@users.noreply.github.com> Date: Mon, 25 Aug 2025 19:20:37 -0400 Subject: [PATCH] rocr: GFX12+ - Fix trap handler to process SW trap ID correctly (#736) When stochastic sampling is not active, the trap handler is incorrectly branching to .check_exceptions, bypassing the software trap ID checks and inturn not advancing the PC. Fixed the issue to always check software traps regardless of PC sampling state. Co-authored-by: Shweta Khatri --- .../hsa-runtime/core/runtime/trap_handler/trap_handler_gfx12.s | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/trap_handler/trap_handler_gfx12.s b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/trap_handler/trap_handler_gfx12.s index aa2c1dd297..491d5f4bfa 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/trap_handler/trap_handler_gfx12.s +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/trap_handler/trap_handler_gfx12.s @@ -231,7 +231,7 @@ s_getreg_b32 ttmp2, hwreg(HW_REG_EXCP_FLAG_PRIV) // EXCP_FLAG_PRIV.b10=stochastic_sample_trap s_bitcmp1_b32 ttmp2, SQ_WAVE_EXCP_FLAG_PRIV_PERF_SNAPSHOT // Test Performance Snapshot bit. - s_cbranch_scc0 .check_exceptions // If not Stochastic, check for other exceptions. + s_cbranch_scc0 .handle_sw_trap // If not Stochastic, continue to check trap ID s_load_b64 ttmp[14:15], ttmp[14:15], 0x8, scope:SCOPE_CU // ttmp[14:15]=*stoch_trap_buf s_wait_kmcnt 0 @@ -241,6 +241,7 @@ s_setreg_imm32_b32 hwreg(HW_REG_EXCP_FLAG_PRIV, SQ_WAVE_EXCP_FLAG_PRIV_PERF_SNAPSHOT,1), 0 // Clear the perf_snapshot flag s_branch .profile_trap_handlers +.handle_sw_trap: // Check if this is a trap (s_trap instruction) or a hardware exception. // Extract TrapID from ttmp1 (which contains PC_HI). // Branch if not a trap (an exception instead).