Skip to content

[rocjitsu] Implement gfx1251 F64 WMMA execution. - #11124

Merged
hanhanW merged 4 commits into
ROCm:developfrom
hanhanW:users/hanhanW/gfx1251-f64-wmma
Sep 21, 2026
Merged

hanhanW merged 4 commits into
ROCm:developfrom
hanhanW:users/hanhanW/gfx1251-f64-wmma

Conversation

@hanhanW

@hanhanW hanhanW commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

The public LLVM gfx1251 profile exposes V_WMMA_F64_16X16X4_F64, but
rocJITsu previously treated the instruction as model-only and did not emit an
execution callback. Add semantic derivation, generated decode validation and
callback wiring, and a CDNA5 wave32 execution helper so compiler-produced forms
can execute in functional simulation.

Enforce the public operand contract: a 16-VGPR destination/accumulator tuple,
4-VGPR A and B tuples, supported source modifiers and matrix-reuse hints, and
the standard integer and FP64 inline accumulator selectors. Reject reserved
control bits, invalid or misaligned register tuples, and DPP/DPP8 extension
encodings.

CDNA5 requires EXEC to contain all 32 wave lanes for WMMA instructions.
Reject wave64 or non-full-EXEC execution before resolving or reading operands.
Report this through rocJITsu's instruction-execution failure path instead of
using exceptions for control flow.

Stage every source before writing the destination so legal overlapping tuples
preserve read-before-write behavior. Evaluate each reduction with a fixed
round-to-nearest-even, preserve-input/output-denormals policy independent of the
wavefront MODE register, consistent with LLVM marking the instruction with
ReadsModeReg = 0.

The logical operation and encoding forms come from public LLVM support. The
lane/register mapping combines the public CDNA5 ISA description with the
checked-in WMMA format metadata. The exact fixed arithmetic policy and physical
lane/register behavior still require validation on gfx1251 hardware; this
change does not claim that source-derived behavior is hardware-confirmed.

@hanhanW

hanhanW commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@hanhanW
hanhanW force-pushed the users/hanhanW/diff-gfx1251-packed-fp64-fma branch from 26e80e9 to 8ed5a3b Compare September 2, 2026 16:53
@hanhanW
hanhanW force-pushed the users/hanhanW/gfx1251-f64-wmma branch from 31241ef to 1aae284 Compare September 2, 2026 16:54

@newling newling 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.

LGTM. I have an AI review here: https://github.com/newling/agent-public-reviews/blob/main/rocm-systems/review_pr11124.md
The suggestions there should be ignored (the first is about variable names, the second is about a test that I don't think is necessary).
I also discussed the relationship of some emulation performance work I recently did for mfma/wmma, to this PR. It seems like this PR does most of the 'right' things, but there might be some follow-up work for SIMD, definitely not needed in this PR.

@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.

Agent found a few issues:

[MAJOR] emulation/rocjitsu/lib/python/amdisa/codegen/_generator.py:10377 — Legal F64 WMMA inline accumulators are rejected

The generated validator accepts src2 only when it is selector 242 (1.0) or an aligned 16-register VGPR tuple. This rejects other legal inline accumulators.

Evidence:

  • LLVM defines this operand as ROCm llvm-project/llvm/lib/Target/AMDGPU/SIRegisterInfo.td:1578, a VGPR-or-FP64-inline operand.

  • llvm-mc from the exact referenced LLVM tree accepts and encodes 0, 0.5, -1.0, integer inline constants, and the other standard FP64 inline values.

  • rocjitsu’s generated operand definitions likewise list these selectors in emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/generated/cdna5/operand_types.h:295.

  • The new test incorrectly codifies selector 243 (-1.0) as invalid at emulation/rocjitsu/tests/cdna5_execution_test.cpp:1699.

Valid compiler-produced kernels—particularly zero-initialized WMMA accumulations—can therefore fail during decode.

Suggested fix: accept the complete legal inline-selector set and apply tuple span/alignment
validation only when src2 is a VGPR. Add decode/execution coverage for at least 0, 0.5, and -1.0.

Confidence: high.

[MAJOR] emulation/rocjitsu/lib/python/amdisa/codegen/execute/matrix.py:424 — Execution is made MODE-dependent despite LLVM explicitly marking WMMA as MODE-independent

The generated callback passes the wavefront’s F64 rounding and denormal modes into every WMMA reduction. The new tests then require results to vary when those MODE fields change.

However, LLVM defines all GFX12 WMMA instructions with ROCm llvm-project/llvm/lib/Target/AMDGPU/VOP3PInstructions.td:1908. LLVM explicitly uses ReadsModeReg = 1 for instructions such as MFMA whose floating-point behavior depends on MODE.

Consequently, rocjitsu currently makes identical WMMA instructions and operands produce different results depending on MODE, contrary to the public compiler contract.

Suggested fix: implement the instruction’s fixed rounding/denormal behavior and replace the MODE-varying tests with fixed-result vectors. If physical gfx1251 validation shows LLVM’s metadata is wrong, that compiler-contract discrepancy should be resolved explicitly before retaining MODE-dependent behavior.

Confidence: medium-high. The LLVM contract is explicit, but hardware validation is still needed to establish the exact fixed arithmetic rules.

Add the generated execution callback for V_WMMA_F64_16X16X4_F64 and route it through a CDNA5 wave32 helper.

The public LLVM gfx1251 profile defines a 16-register F64 destination and accumulator tuple, four-register A and B tuples, modifier encodings, and the inline 1.0 accumulator form. Combine that contract with the checked-in CDNA5 WMMA data formats to map each logical F64 component to consecutive VGPR words. Stage all inputs before writing the destination so overlapping tuples retain read-before-write behavior, use the existing mode-aware fused F64 primitive for each reduction step, and apply EXEC to destination writes.

Reject reserved layouts, unsupported modifiers and sources, out-of-range or misaligned register tuples, DPP, and wave64. Cross-check legal encodings, invalid operands, and tuple boundaries with public LLVM MC. Cover full matrix mapping, final tuple boundaries, overlap, partial EXEC, composed modifiers, fused rounding, denorm modes, exceptional values, and invalid encodings.

Keep normal gfx1251 simulation disabled through execution_implemented=false. Target-specific setreg behavior and functional simulator enablement remain separate changes. The lane and register mapping and FP-mode behavior are source-derived and still require differential validation on physical gfx1251 hardware.

Test: LLVM MC and FileCheck; amdisa tests; rocjitsu_tests; CTest.
Accept the complete public LLVM VISrc_512_f64 integer and FP64 inline-accumulator selector ranges and resolve their values at full 64-bit width.

Make F64 WMMA arithmetic independent of wavefront MODE, matching LLVM ReadsModeReg=0. Use a fixed round-to-nearest-even, preserve-denorm baseline while retaining the physical-hardware validation TODO.

Update decoder and execution coverage for the newly accepted inline forms and fixed arithmetic policy. Check Result-returning execute_instruction calls required by the rebased upstream API.

Test: amdisa generator/sema/provenance tests; rocjitsu_tests build; focused gfx1251 packed-F64 and F64-WMMA CTest; pre-commit.
@hanhanW
hanhanW changed the base branch from users/hanhanW/diff-gfx1251-packed-fp64-fma to develop September 16, 2026 23:02
Copilot AI lite review requested due to automatic review settings September 16, 2026 23:02
@hanhanW
hanhanW force-pushed the users/hanhanW/gfx1251-f64-wmma branch from 1aae284 to 5daf283 Compare September 16, 2026 23:02
@therock-pr-bot

therock-pr-bot Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

❌ PR Check — Action Required

Check Status Details
📝 PR Description ❌ Fail Error: PR description must reference a JIRA ID, ISSUE ID, or a GitHub closing keyword.
Expected: include a JIRA ID / ISSUE ID line (separator : or -, or omitted; value may be a JIRA key, a number with/without #, or a link), OR a closing keyword + issue reference. Accepted examples:
• JIRA ID : TESTAUTO-6039
• JIRA ID - #330
• JIRA ID #330
• JIRA ID (on separate line)
ROCM-25757
• ISSUE ID : TESTUTO-3334
• ISSUE ID #3334
• ISSUE ID - TESTAUTO-3433
• ISSUE ID (on separate line)
AIRUNTIME-2352
• ISSUE ID : https://github.com/<org_name>/<repo_name>/issues/1234
• Closes #10
• Fixes octo-org/octo-repo#100
• Resolves: #123
• #123
• https://github.com/<org_name>/<repo_name>/issues/123
Current: no valid JIRA/ISSUE/closing-keyword reference found
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —

⚠️ 1 policy check(s) failed. Please address the issues above before this PR can be Reviewed.

🚫 Please fix the failed policies

  • ❌ PR Description

The Not ready to Review label was added to this PR. Once all policies pass, the label is removed automatically.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ PR Description

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

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.

🔵 Needs a closer look

A moderate generated-validation defect remains, DPP rejection coverage is incomplete, and the change requires human and hardware validation.

Pull request overview

Implements gfx1251 F64 WMMA execution through the CDNA5 wave32 path while keeping normal gfx1251 simulation disabled.

Changes:

  • Adds generated execution and callback/backend wiring.
  • Implements matrix mapping, validation, modifiers, fused arithmetic, and EXEC masking.
  • Adds execution, semantic, and generator test coverage.
File summaries
File Reviewed changes
shared/machine-readable-isa/isa/amdgpu_isa_cdna5_variants.json Updates F64 WMMA execution metadata.
emulation/rocjitsu/tests/cdna5_execution_test.cpp Adds execution, mapping, arithmetic, masking, overlap, and validation tests; DPP16/DPP8 rejection coverage remains incomplete.
emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/shared/mma_exec.h Adds the CDNA5 wave32 F64 WMMA helper and mappings.
emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/generated/cdna5/vop3p.h Declares the generated instruction execution interface.
emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/generated/cdna5/vop3p.cpp Adds decoding and operand validation.
emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/generated/cdna5/vop3p_exec.cpp Routes execution to the F64 WMMA helper.
emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/generated/cdna5/execution_backend.h Adds the execution identifier.
emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/generated/cdna5/execution_backend_exec.cpp Registers the execution callback.
emulation/rocjitsu/lib/python/amdisa/tests/test_sema_derive.py Tests F64 WMMA semantic derivation.
emulation/rocjitsu/lib/python/amdisa/tests/test_generator_profile_gates.py Tests generator execution and validation gates.
emulation/rocjitsu/lib/python/amdisa/semantics.py Recognizes F64 WMMA signatures.
emulation/rocjitsu/lib/python/amdisa/codegen/execute/matrix.py Generates the specialized matrix execution path.
emulation/rocjitsu/lib/python/amdisa/codegen/_generator.py Generates validation and callback wiring; src0 validation lacks the required lower-bound check for invalid selectors.
Review details

Suppressed comments (2)

emulation/rocjitsu/lib/python/amdisa/codegen/_generator.py:10430

  • src0 is constructed as OPR_SRC_VGPR, whose legal selectors start at 256, but this generated check only rejects values above 508. As a result, the added src0 = 0/242 cases are accepted instead of rejected, and execution can resolve an invalid VGPR offset; include the lower bound here and regenerate vop3p.cpp.
                                f'if ({raw_inst}->{src_name} > 508u) '

emulation/rocjitsu/tests/cdna5_execution_test.cpp:2276

  • The new rejection matrix does not exercise either DPP16 (SRC_DPP) or DPP8 (SRC_DPP8_FI_0/1), even though this instruction has a custom DPP rejection path and its tuple checks run before that path. Add decode-failure cases using the actual DPP extension encodings so a regression that accepts or mis-parses a DPP form is caught.
TEST(Gfx1251F64WmmaExecutionTest, RejectsUnsupportedControlsSourcesAndRegisterTuples) {
  auto decoder =
      make_isa_decoder<cdna5::Isa>(&cdna5::execution_backend(), cdna5::kGfx1251IsaFeatures);
  ASSERT_NE(decoder, nullptr);
  constexpr cdna5::Vop3pBuilderFields kValid{
      .vdst = 8, .src0 = 256, .src1 = 260, .src2 = 264, .opsel_hi = 3};
  const auto rejected = [&](cdna5::Vop3pBuilderFields fields) {
    const auto words = cdna5::build_vop3p(cdna5::kVWmmaF6416x16x4F64Vop3p, fields);
    EXPECT_EQ(decode_valid(*decoder, words.data()), nullptr);
  • Files reviewed: 8/13 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kuhar kuhar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please update the PR description to match this revision. It still says the implementation is mode-aware and covers denormal modes, but the helper now uses a fixed RNE/preserve-denorm policy and tests MODE independence. The body also says partial EXEC is covered as supported behavior, while CDNA5 ISA section 7.12 requires EXEC to be all ones. Keeping those statements aligned with the code and remaining hardware-validation caveat will prevent reviewers from assessing the superseded contract.

@hanhanW
hanhanW requested a review from kuhar September 21, 2026 18:29

@kuhar kuhar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@hanhanW
hanhanW merged commit 5c470f9 into ROCm:develop Sep 21, 2026
83 of 85 checks passed
@hanhanW
hanhanW deleted the users/hanhanW/gfx1251-f64-wmma branch September 21, 2026 21:03
@systems-assistant

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

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.

5 participants