← Back to Pull requests

feat(tensilelite): add the A2A+GEMM shard-loop kernel (FusedA2A: A2AGemm) #14168

Closed
unknown closed this pull request without merging on Nov 14, 2026 15:30 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 00:46 UTC
Author

Motivation

hipBLASLt already fuses an all-to-all after the GEMM (FusedA2A: GemmA2A: compute, then scatter D over xGMI). The mirror case has no implementation: a GEMM whose B operand arrives by all-to-all, where each of the W ranks holds one K/W shard of every token block and the GEMM cannot start a shard until that shard lands. Run unfused, the collective is fully exposed. This PR adds FusedA2A: A2AGemm, which walks the W shards in an outer loop and overlaps each round's compute with the next round's transfer.

The two modes are the two ends of one all-to-all edge: the producer's feature dimension is the consumer's K dimension, so a GemmA2A output buffer is layout-identical to an A2AGemm input.

JIRA ID : ROCM-27524

Technical Details

  • Problem type: one FusedA2A key with values Disabled (default), GemmA2A and A2AGemm replaces the FusedGemmA2A bool, and a FusedA2AEqual predicate on every solution keeps a problem matching kernels of its own mode. The predicate's serialized name moves with it, so a device library built before this change fails to load: hipBLASLt reports Could not load <path>, TENSILE_DB=0x1000 prints the cause, and the device library has to be rebuilt.

  • Kernel: K holds the whole W k_local reduction and one shard round covers K/W. Each round's transition, skipped after the last round, rebinds the A/B descriptors, resets the LDS pointers and, unless A and B are both DirectToLds, syncs the work-group. B is the rank's pre-gather input and the kernel only reads it: round 0 reads the rank's own block of B, and the peers' shards are gathered by in-kernel SDMA packets into a2aBuf, which later rounds read.

  • Sub-rounds: A2ASubRounds (S, one of 1, 2 or 4; default 1) splits each peer's arrival into S independently flagged pieces, so a round's compute waits on 1/S of a peer's shard instead of all of it. The shard loop then runs 1 + (W-1) S rounds rather than W, the rank's own round never being split, and A2AGemmShape requires K to be a multiple of W DepthU S.

  • Buffers: B holds the rank's pre-gather input, segment-major [W][N][K/W] with block d bound for rank d, under a dense [N, K] descriptor, so the caller passes ldb == K (W * k_local), which A2AGemmShape checks; ContractionSolution divides B's strides by world, so the kernel walks each segment with row stride k_local. The gathered segments land in a2aBuf (the A2A_BUF slot), which has the same layout. The per-peer kernarg slot recvPtr is renamed bufPtr: GemmA2A fills it with each rank's receive buffer, A2AGemm with each peer's B and, for its own rank, its a2aBuf. The public RECV_PTRS attribute keeps its name.

  • Guards: A2AGemmShape also requires a2aExtent == K (setA2ABuf sizes a2aBuf from it) and the strided batch mode (the pointer-array branch would read the gathered buffer as a pointer array), and the client refuses --batch-mode=1 for A2AGemm. Both modes require MacroTile0/1 in {128, 256}. A2AGemm solutions require BufferLoad, a bf16 B, and, with A2ASubRounds > 1, a DepthU whose B bytes are a multiple of 128. The A2AGemm batch election needs each batch's feature-tile-0 work-group to be dispatched before the batches it places fill every free slot, so A2AGemm also rejects negative WorkGroupMapping, WorkGroupMappingXCC != 1 and any SpaceFillingAlgo, and the host rejects an A2AGemm launch whose runtime mapping (e.g. from TENSILE_FIXED_WGM) breaks the same rule or whose a2aBuf is not 128-byte aligned. A batch is the whole token blocks whose work-groups add up to about computeUnitCount; its size affects only how early the next wave's copies are placed, not forward progress. A2AGemm takes AssertSummationElementMultiple 1 or DepthU and sets it to DepthU, so its kernels have no tail loop. A2AGemmShape also rejects K = 0.

  • Shared helpers also change GemmA2A's emitted code: some cursor emitters merge, and FusedNumCu, which only A2AGemm reads, grows the segment's scalar tail from 16 to 20 bytes for every fused mode; appendFusedSegment throws when there is no CU count or when the rank is outside the world.

  • Naming: GemmA2A problem names now carry a GemmA2A tag instead of FusedA2A, as A2AGemm names carry A2AGemm, so the shipped gfx950 logic file becomes gfx950_Cijk_Alik_Bljk_BBS_BH_GemmA2A_UserArgs.yaml (its kernel names, solution names and BaseName move with it).

  • Client: --fused-a2a-sdma-rotate defaults to -1 for both modes and is rejected without --fused-a2a. It moves each remote peer's SDMA queue along the even xGMI engines 2, 4, ..., 14 from KFD's recommendation: A2AGemm pulls B from its peers, and with KFD's engines two concurrent pull queues can sit on the two engines of one xGMI port group, which slows both. GemmA2A pushes and showed no measurable change, so both modes share one queue setup. The loopback queue uses engine 0. A nonzero rotation requires the node to report 14 xGMI SDMA engines, and every remote peer queue must use an even engine in 2..14 at any rotation, because on GC 9.4.3, 9.4.4 and 9.5.0 a doorbell rung from a shader for a queue on an odd engine reaches the previous engine.

  • L2 staleness: reading a gathered segment after its flag rests on nothing having pulled those lines into L2 first, since on gfx950 an SDMA write leaves an already-resident line stale. The shard loop never creates such a line, and A2AGemmShape keeps every segment 128-byte aligned. That is a property of the current read order, not a construction-level guarantee: changing the shard loop's read order, or allowing a B type other than bf16, requires revisiting it.

  • Goldens: A2ASubRounds joins the parameter registry and test_a2a_gemm_loop_char.ambr is a new codegen golden. Only A2AGemm names carry AASR<n>; GemmA2A's golden moves only with its new name tag.

  • The 256 shipped logic files carrying an inert FusedGemmA2A: false are left as they are; Problem.py raises only on a truthy value, so they load unchanged.
  • Test Plan

    The TensileLite Python unit suite and the host gtests, including the new FusedA2AProblem_test and FusedA2AKernArg_test. On an 8-GPU gfx950 host, the a2a_gemm_loop comm config at world 2, 4 and 8 with A2ASubRounds 1, 2 and 4, covering an odd k_local/DepthU trip, an N spanning several batches, a DirectToLds 0 group and token counts that do not fill a macro tile, and the existing fused_a2a config as a GemmA2A regression; world 1 runs locally from a temporary copy of the configs. The comm configs run three enqueues per sync on rotated buffer slots and validate the later launches. CI runs these comm configs on two gfx950 GPUs, which covers world 2, so world 4 and 8 are a local gate. Emitted assembly is compared for the changes expected to be codegen-neutral.

    Test Result

    The unit suite and the gtests pass and everything builds clean. On 8 GPUs every comm row reports validation: PASSED, at each world and in both modes, including the launches on rotated slots, and world 1 passes from the temporary copy; fused_a2a.yaml (GemmA2A) passes at world 2, 4 and 8, and its timing showed no measurable change under the -1 rotate default. Hardware validation covers gfx950 only. Emitted A2AGemm assembly is byte-identical across the a2aExtent change and, once kernel name lines are excluded, across the AASR naming change. Deliberately broken clients each fail validation: remote peer entries pointing at a2aBuf, the peer table shifted by one rank, and the poison written into B fail D validation at world 2, 4 and 8, and an input corrupted only in the rotated slots fails in both modes. The per-round write-pointer reset, the barrier and the ASEM change show no measurable time change at world 4 (M = 3072 and 8192). Not covered: interleaveA2AGemmReferences is reached only through the multi-GPU comm run.

    At the production shape, A2AGemm is about 1.4–1.9× faster than an unfused torch all-to-all followed by a matmul at world 2, 4 and 8, and hides about 60–85% of the all-to-all time at world 4 and 8 relative to the same GEMM without communication (35–50% at world 2, where the all-to-all alone takes longer than the GEMM). GemmA2A shows no regression against develop.

    Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: yzhang93 Review duration: 34003m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #14168"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%