Skip to content

[comgr][hotswap] Preserve VGPR-MSB mode when splitting gfx1250 WMMAs#3428

Open
YashDeshpande25 wants to merge 1 commit into
ROCm:amd-stagingfrom
YashDeshpande25:gfx1250-hotswap-wmma-vgpr-msb
Open

[comgr][hotswap] Preserve VGPR-MSB mode when splitting gfx1250 WMMAs#3428
YashDeshpande25 wants to merge 1 commit into
ROCm:amd-stagingfrom
YashDeshpande25:gfx1250-hotswap-wmma-vgpr-msb

Conversation

@YashDeshpande25

@YashDeshpande25 YashDeshpande25 commented Jul 16, 2026

Copy link
Copy Markdown

Summary

The WMMA split pass rewrites gfx1250 B0-only WMMAs into pairs of narrower WMMAs that also run on A0. On gfx1250, VGPR operands past v255 are reached through a persistent VGPR-MSB bank mode, so a split whose upper half crosses
v255 (or a K-split whose second half reuses dst as src2) must execute that half under a different bank.

This makes the pass VGPR-MSB aware:

  • Recovers the live VGPR-MSB mode at each WMMA via a whole-function CFG fixed point, fail-closed: an ambiguous or unprovable mode declines the split.
  • Brackets the upper half with s_set_vgpr_msb (switch before, restore after), and emits nothing when no bank change is needed.
  • Fails closed on every matched-but-unsplittable path (RequiredPatchFailed) instead of silently leaving an A0-illegal opcode in .text.
  • Shares the PC-materialized target resolver between s_swap_pc_i64 calls and s_set_pc_i64 jumps so the CFG can follow materialized-PC jumps.

@YashDeshpande25
YashDeshpande25 force-pushed the gfx1250-hotswap-wmma-vgpr-msb branch from 9b631a4 to fb68ee8 Compare July 16, 2026 22:45
@YashDeshpande25 YashDeshpande25 changed the title [Test] Unverified implementation of wmma issue 4 [comgr][hotswap] Preserve VGPR-MSB mode when splitting gfx1250 WMMAs Jul 17, 2026
@YashDeshpande25
YashDeshpande25 marked this pull request as ready for review July 17, 2026 16:26
@github-actions github-actions Bot added comgr Related to Code Object Manager hotswap Related to the Comgr Hotswap feature labels Jul 17, 2026
@chinmaydd
chinmaydd requested a review from harsh-amd July 17, 2026 17:52
if ((!LS.MIA->isBranch(DI.Inst) && !LS.MIA->isCall(DI.Inst)) ||
LS.MIA->isIndirectBranch(DI.Inst) || LS.MIA->isReturn(DI.Inst))
continue;
std::optional<uint64_t> Target = evaluateDirectControlFlowTarget(DI, LS);

@harsh-amd harsh-amd Jul 17, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this uses the same control-flow surface as the rewrite. This only asks evaluateDirectControlFlowTarget(), so it misses the absolute and PC-materialized s_swap_pc_i64 targets that collectDirectBranchTargets() already treats as known text entries. A caller can enter another function at an interior WMMA after skipping the normal s_set_vgpr_msb prefix; then this analysis seeds from the symbol entry and can emit brackets for the wrong incoming mode instead of failing closed.

Can we share the known-target logic from collectDirectBranchTargets() here, or otherwise make absolute/materialized/unresolved call targets force the affected function to stay unanalyzed? Please add a lit case for an interior cross-function s_swap_pc_i64 target, ideally both materialized-PC and absolute-immediate forms.

In[I] = mergeVgprMsbState(In[I], vgprMsbStateFromMode(0));
Worklist.push_back(I);
};
SeedAbiEntry(0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the VGPR-MSB analysis also needs to seed declared text entries, not just the function symbol start and pc-relative callable entries. collectDeclaredTextEntries() already treats kernel descriptor entries as real entry points, but computeVgprMsbModes() only seeds SeedAbiEntry(0) plus CallableEntries found via evaluateDirectControlFlowTarget().

That can mark an interior KD entry block as unreachable and then findActiveVgprMsbMode() returns mode 0 for a WMMA there, even if the real entry path executes a local s_set_vgpr_msb first. Can we pass the declared entries into this analysis and seed any entry inside the current range? A lit test with a KD entry offset to an interior block would cover this.

@harsh-amd

Copy link
Copy Markdown

Non-blocking AGENT_CONVENTIONS cleanup before merge: please spell out the new auto lambdas, add a TODO/tracker for the mirrored VGPR-MSB setreg decoding, and clean up the commit messages before landing.

@YashDeshpande25
YashDeshpande25 force-pushed the gfx1250-hotswap-wmma-vgpr-msb branch 2 times, most recently from 973e8f3 to 6068a5d Compare July 17, 2026 23:34
@ronlieb

ronlieb commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

needs to be rebased on latest amd-staging to unbreak spirv

The WMMA split pass rewrites gfx1250 B0-only WMMAs into pairs of narrower
WMMAs that also run on A0. On gfx1250, VGPR operands past v255 are reached
through a persistent VGPR-MSB bank mode, so a split whose upper half crosses
v255 (or a K-split whose second half reuses dst as src2) must execute that
half under a different bank.

Make the pass VGPR-MSB aware:

- Recover the live VGPR-MSB mode at each WMMA via a whole-function CFG fixed
  point, fail-closed: an ambiguous or unprovable mode declines the split.
- Bracket the upper half with s_set_vgpr_msb (switch before, restore after),
  and emit nothing when no bank change is needed.
- Fail closed on every matched-but-unsplittable path (RequiredPatchFailed)
  instead of silently leaving an A0-illegal opcode in .text.

Use the same control-flow surface as the rewrite so the mode proof cannot be
seeded from a wrong incoming mode:

- Decline the analysis when collectDirectBranchTargets() reports an unresolved
  call target, since such a call may enter any function at an interior offset.
- Resolve absolute-immediate and PC-materialized s_swap_pc_i64 / s_set_pc_i64
  targets in the interior-entry pre-pass so a cross-function interior entry
  declines the split rather than seeding the symbol-start mode.
- Seed declared kernel-descriptor entries so an interior KD-entry block is
  analyzed from the real entry mode rather than misread as unreachable.

Add lit coverage for the bank-crossing, fail-closed, and loop-carried mode
cases, plus interior cross-function s_swap_pc_i64 (materialized and absolute),
an interior s_set_pc_i64 jump, and an interior kernel-descriptor entry.
@YashDeshpande25
YashDeshpande25 force-pushed the gfx1250-hotswap-wmma-vgpr-msb branch from 6068a5d to d79c0d1 Compare July 18, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comgr Related to Code Object Manager hotswap Related to the Comgr Hotswap feature mi455

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants