Skip to content

[rocjtisu] Fix isa semantics for rdna3 and rdna4 - #7646

Merged
kuhar merged 2 commits into
developfrom
users/kuhar/rdna3-rdna4-isa-split
Jun 23, 2026
Merged

kuhar merged 2 commits into
developfrom
users/kuhar/rdna3-rdna4-isa-split

Conversation

@kuhar

@kuhar kuhar commented Jun 23, 2026

Copy link
Copy Markdown
Member

Motivation

This extends RocJITsu’s generated AMDGPU ISA support so RDNA3/RDNA3.5/RDNA4 simulation can execute the instruction patterns needed by IREE e2e tests and the fpsan numeric suite.

The bulk of the diff is regenerated ISA output. The source changes are concentrated in the Python generator/profile logic, shared execution helpers, and regression tests.

This needs #7625 to work e2e.

Technical Details

  • Add generator-backed execution coverage for RDNA packed/vector paths:

    • packed 16-bit source/destination handling
    • true16 VOP3 op_sel handling
    • DPP-aware VOP3 paths
    • VOP3/VOP3P dot, compare, convert, and mixed-width operations
  • Add RDNA WMMA/SWMMAC dispatch support:

    • RDNA3/RDNA3.5 GFX11 WMMA layout
    • RDNA4 GFX12 WMMA/SWMMAC layout
    • FP8/BF8/F16/BF16/IU matrix paths needed by smoke kernels
  • Fix RDNA4 compatibility behavior:

    • inject opcode-9 s_waitcnt compatibility form where the XML only exposes split wait instructions
    • keep execution and disassembly formatting on the same GFX11 waitcnt bit layout
    • preserve generated decode/format tests for nonzero waitcnt immediates
  • Refresh generated outputs from the same generator state:

    • RDNA3/RDNA3.5/RDNA4 generated ISA files
    • gfx1250 generated VOP3 split files
    • DBT legalization tables
  • Expand regression coverage:

    • generator/profile tests for RDNA feature gates and matrix dispatch wiring
    • decode and execution harness tests for RDNA/RDNA4 paths
    • SIMD correctness coverage for wide MAD/shift behavior
    • value-level tests for dot2, SCC overflow, true16 modifiers, and waitcnt formatting

JIRA ID

N/A

Test Plan

Unit tests, IREE e2e tests, fpsan tests across rdan3, rdna4, and gfx1250.

Rerun the generator across all ISAs.

Test Result

All good with the runtime patch.

Submission Checklist

@kuhar
kuhar requested review from Groverkss and amd-eochoalo June 23, 2026 01:34
@kuhar
kuhar requested a review from atgutier as a code owner June 23, 2026 01:34
Copilot AI review requested due to automatic review settings June 23, 2026 01:34
@kuhar
kuhar requested a review from a team as a code owner June 23, 2026 01:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@atgutier atgutier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This LGTM, but should probably fix the dot2_true16 dispatch entry problem.

Here are some other agent comments:

  1. Systemic copy-paste of per-arch operand logic (MINOR, the main maintainability risk)
    packed_16bit_vgpr_source/dst, the Packed16VgprSource struct, resolve_src_scalar16, the half-merge
    read_lane/write_lane, and the VCCZ/EXECZ active-mask fix are byte-for-byte identical across
    rdna3/rdna3_5/rdna4/gfx1250 (and resolve_src_scalar16 across cdna1–4 too — 7+ files). Confirmed via
    diff. This violates the project's stated style (factor reuse into templates+using), and a future fix
    to the true16 half-mapping would have to land in N places — real drift risk.
    → Hoist into a shared CRTP/base in shared/ (e.g. extend AmdgpuIsaOperand), parameterized by the
    per-ISA inline-constant table.

Lower priority

  • packed.py:561-571 (+628, +700) (MINOR) — read_mix_src f16 path only treats selectors 240–248 as
    float inline constants; integer inline constants fed to an f16 mix get reinterpreted as raw f16
    bits. Nonsensical-but-legal encoding, low impact. Assert or document.
  • Wait-counter update inconsistency (MINOR) — _generator.py:2682-2691 emits lgkmcnt via a fragile
    read-modify-write of the combined set_wait_target(...) while the other three counters use
    single-field setters. Verified functionally correct, but a dedicated set_wait_target_lgkmcnt() would
    be cleaner. Mirror in rdna4/sopk.cpp etc. where expcnt uses the string-keyed
    set_wait_counter("wait_expcnt", …) vs typed siblings.
  • addr_calc_buffer.h:129 (MINOR, pre-existing) — static uint64_t pl_count in the MUBUF log block is
    non-thread_local; benign race across SIMD threads. Not a regression (this PR only added constexpr
    helpers nearby). Make thread_local while in the area, like mma_exec.h:895.
  • read_lane/write_lane half-select asymmetry (NIT) — write_lane calls packed_16bit_vgpr_dst
    unconditionally while read_lane gates on packed_16bit_source_. Currently unreachable (generated
    true16 ops always pass the flag or merge manually), but a foot-gun. Gate symmetrically or assert.
  • rdna4/operand.cpp:561-566 OPR_WAITCNT decode (NIT) — the combined S_WAITCNT is ignored on gfx12
    (separated into s_wait_loadcnt/dscnt/expcnt). The new vmcnt/expcnt/lgkmcnt bit-decode is disassembly
    cosmetics only, not a semantic fix. Optionally render as s_wait_idle/"(ignored)".

@kuhar kuhar changed the title [rocjtisu] Fix isa semantics for rdna3 and rdan4 [rocjtisu] Fix isa semantics for rdna3 and rdna4 Jun 23, 2026
kuhar added 2 commits June 23, 2026 13:26
Update the AMDISA generator, generated RDNA/CDNA execution sources, shared executor helpers, and ISA-focused tests for the RDNA3/RDNA4 kernels exercised by IREE and hip-fpsan.

Add generated RDNA3/RDNA4 execution coverage for packed operations, DPP/true16 handling, VOP3P FP8 paths, matrix dispatch, and address wrapping.

Refresh the generated gfx1250 ISA split and DBT legalization tables from the same generator state so the checked-in generated outputs remain reproducible.
@kuhar
kuhar force-pushed the users/kuhar/rdna3-rdna4-isa-split branch from 7756d4a to 6852fe2 Compare June 23, 2026 17:43
@kuhar
kuhar merged commit c07cb05 into develop Jun 23, 2026
19 checks passed
@kuhar
kuhar deleted the users/kuhar/rdna3-rdna4-isa-split branch June 23, 2026 18:30
yashjha123 added a commit that referenced this pull request Oct 26, 2026
RDNA scratch addressed each lane's private space contiguously
(scratch_base + lane * lane_size + offset). The RDNA3 and RDNA3.5 ISA
guides (11.2) define scratch as dword-swizzled with index_stride equal
to the wave size:

  Addr = SCRATCH_BASE + (offset / 4) * 4 * index_stride + offset % 4 + TID * 4

The RDNA4 guide uses the same SWIZZLE(offset, ThreadID) wording, and
rocm-dbgapi reads gfx10/11/12 private memory with this 4-byte interleave.
CDNA already uses this layout. RDNA's per-lane layout came from #7646,
which copied the CDNA convention of the time, and #13019 named it
FlatPrivateLayout::Linear to preserve that behavior.

Map SCRATCH instructions and private-aperture FLAT lanes through
scratch_lane_address(), and mark them as interleaved private lanes so
multi-dword accesses split per dword. FLAT wait planning uses the same
layout. A spill where every lane uses the same offset now touches one
contiguous line instead of one line per lane.

FlatPrivateLayout::Linear has no remaining users. Remove it together
with FlatAddress::swizzled, which every remaining translation set with
private_address; the wait scoreboard now reads private_address.

Interleaving moves a lane's high dword a wave stride away, so 8-byte
FLAT atomics on private lanes would modify the neighbouring lane's
dword. RDNA3/3.5/4 section 11.1 specifies MEMVIOL for them; extend the
existing CDNA5 rejection to these targets.

Run the layout test on RDNA3 and RDNA3.5 for wave32 and wave64, check
mixed private/global FLAT lanes on RDNA3, RDNA3.5 and RDNA4, and update
the expectations that encoded RDNA4's per-lane backing.

Run the decoded FLAT wait-plan cross-check with b128 loads and returning
32-bit atomics too, so private lanes that split per dword or take the
atomic handlers keep the routing execution uses.
yashjha123 added a commit that referenced this pull request Oct 28, 2026
RDNA scratch addressed each lane's private space contiguously
(scratch_base + lane * lane_size + offset). The RDNA3 and RDNA3.5 ISA
guides (11.2) define scratch as dword-swizzled with index_stride equal
to the wave size:

  Addr = SCRATCH_BASE + (offset / 4) * 4 * index_stride + offset % 4 + TID * 4

The RDNA4 guide uses the same SWIZZLE(offset, ThreadID) wording, and
rocm-dbgapi reads gfx10/11/12 private memory with this 4-byte interleave.
CDNA already uses this layout. RDNA's per-lane layout came from #7646,
which copied the CDNA convention of the time, and #13019 named it
FlatPrivateLayout::Linear to preserve that behavior.

Map SCRATCH instructions and private-aperture FLAT lanes through
scratch_lane_address(), and mark them as interleaved private lanes so
multi-dword accesses split per dword. FLAT wait planning uses the same
layout. A spill where every lane uses the same offset now touches one
contiguous line instead of one line per lane.

FlatPrivateLayout::Linear has no remaining users. Remove it together
with FlatAddress::swizzled, which every remaining translation set with
private_address; the wait scoreboard now reads private_address.

Interleaving moves a lane's high dword a wave stride away, so 8-byte
FLAT atomics on private lanes would modify the neighbouring lane's
dword. RDNA3/3.5/4 section 11.1 specifies MEMVIOL for them; extend the
existing CDNA5 rejection to these targets.

Run the layout test on RDNA3 and RDNA3.5 for wave32 and wave64, check
mixed private/global FLAT lanes on RDNA3, RDNA3.5 and RDNA4, and update
the expectations that encoded RDNA4's per-lane backing.

Run the decoded FLAT wait-plan cross-check with b128 loads and returning
32-bit atomics too, so private lanes that split per dword or take the
atomic handlers keep the routing execution uses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants