Skip to content

[rocjitsu] Correct legacy floating min/max and median selection - #13898

Merged
kuhar merged 1 commit into
developfrom
users/jakub/rocjitsu-independent-minmax
Oct 22, 2026
Merged

kuhar merged 1 commit into
developfrom
users/jakub/rocjitsu-independent-minmax

Conversation

@kuhar

@kuhar kuhar commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Host min/max loses the NaN priority and signed-zero ordering required by
older CDNA and RDNA instructions. Median also selects the wrong operand
when a source is NaN, and unpacked selection misses MODE input-denormal
flushing.

Extend the shared encoding selector with legacy NaN policies and
MODE.IEEE signaling-NaN handling. Use it for scalar, SIMD, dual-issue
and packed F16 execution. Apply input flushing before selection and
preserve selected denormals. Use MIN3 for median inputs containing NaNs.
Match the measured RDNA3 median ordering of signed zeros while retaining
the documented rule for older targets. Require an explicit target policy
for legacy selection and regenerate the affected executors.

Cover denormal modes, signed zeros, NaN source and payload priority,
packed clamp, CDNA3/4 F16/F32/F64, RDNA vector and dual-issue forms, and
RDNA3.5 scalar F16/F32 operations.

Copilot AI balanced review requested due to automatic review settings October 21, 2026 10:59
@kuhar
kuhar requested review from a team and atgutier as code owners October 21, 2026 10:59

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@therock-pr-bot

therock-pr-bot Bot commented Oct 21, 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

therock-pr-bot Bot commented Oct 21, 2026 •

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.

@kuhar kuhar changed the title users/jakub/rocjitsu independent minmax [rocjitsu] Correct legacy floating min/max and median selection Oct 21, 2026

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

The changes to the Legacy logic seem fine. However, the results do not match HW. RDNA 1/2 show the same two deviations already fixed for RDNA 3_5/4.

The manual is just incorrect for two cases: NaN propogration, and zero ordering -0 < +0

Can you verify the claims against CDNA HW too? The changes can be easily propagated if the behavior repeats.

Click for more details (Agent's Description)

Ran a directed probe against RDNA1 and RDNA2 silicon to check the new legacy selection path: an RX 5700 XT (gfx1010) and an RX 6800 XT (gfx1030), every pair and triple of 14 encodings (±0, ±denormal, ±1, ±inf, ±qNaN with distinct payloads, ±sNaN) across 16 opcodes × 2,744 lanes × 32 MODEs (IEEE 0/1 × both FP_DENORM fields) = 1,404,928 results per GPU. The rerun is byte-identical and the two GPUs are byte-identical to each other.

Most of the model holds up exactly: one NaN → the numeric source, MODE.IEEE sNaN priority (a before b, quieted), IEEE=0 leaving the encoding untouched, input flushing before selection, and MED3-any-NaN → MIN3 all reproduce bit for bit.

The per-target table is the problem. LegacyPolicy{prefer_first_nan = true, ordered_zero_median = true} reproduces all 1,404,928 results on both parts; the {false, false} arm these targets currently sit in misses 122,880. Witnesses at MODE 0x0f0:

v_max_f32  7fc00000, 7fc12345                  -> 7fc00000          (src0, not src1)
v_max_f64  7ff8000000000000, 7ff8000012345678  -> 7ff8000000000000
v_med3_f32 -0, +0, -0                          -> -0                (-0 below +0)
v_med3_f32 7fc00000, 7fc12345, ffc00000        -> 7fc00000          (src0, not src2)

Two knock-ons beyond the inline suggestions: legacy_minmax_test.cpp currently asserts the contradicted behavior for these params, so the suite passes today and would need updating alongside; and I have no CDNA part available, so the CDNA1–4 entries are untouched by this and remain unverified in both fields.

Comment thread emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/shared/minmax.h Outdated
@kuhar
kuhar force-pushed the users/jakub/rocjitsu-independent-minmax branch from 0fcd5de to 3a1b154 Compare October 21, 2026 19:58
@sjain-stanford
sjain-stanford self-requested a review October 21, 2026 20:47
@kuhar
kuhar requested a review from yashjha123 October 21, 2026 21:27

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

I think it would help to close the remaining selection-test gaps while adding this coverage (paths below are under emulation/rocjitsu/):

  • In tests/simd_correctness/vop2_minmax_simd_correctness_test.cpp:214, remove the NaN/signed-zero lane exclusion and its obsolete comments. It hides the repaired cases in mixed-lane and partial-EXEC checks. Both tests pass with the exclusion disabled.
  • In tests/legacy_minmax_test.cpp:241, drive the F32 and F16/F64 input-denormal fields differently, and include F16 VOP2 alongside VOP3. Setting both fields to the same value cannot detect a wrong-field read; the existing F16 VOP2 cases contain no subnormals.
  • Add CDNA1/2 to the parameter lists at tests/legacy_minmax_test.cpp:409 and :589: their regenerated executors use these opcodes too. The existing cases pass for those targets (40 passed, four expected skips).
  • Add signaling-NaN cases to PackedNumberSelection at tests/legacy_minmax_test.cpp:562. The branch at lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/shared/fp_mode.h:413 correctly selects number semantics today, but the current denormal-only test cannot distinguish that from RDNA legacy selection. Two sNaNs with IEEE=0 and an sNaN/number pair with IEEE=1 exercise the difference; the analogous dual-issue cases already exist.

Comment thread emulation/rocjitsu/lib/rocjitsu/src/rocjitsu/isa/arch/amdgpu/shared/fp_mode.h Outdated
Comment thread emulation/rocjitsu/lib/python/amdisa/sema_derive.py
@kuhar
kuhar force-pushed the users/jakub/rocjitsu-independent-minmax branch from 3a1b154 to 26867bb Compare October 22, 2026 01:18
Host min/max loses the NaN priority and signed-zero ordering required by
older CDNA and RDNA instructions. Median also selects the wrong operand
when a source is NaN, and unpacked selection misses MODE input-denormal
flushing.

Extend the shared encoding selector with legacy NaN policies and
MODE.IEEE signaling-NaN handling. Use it for scalar, SIMD, dual-issue
and packed F16 execution. Apply input flushing before selection and
preserve selected denormals. Preserve SDWA output scaling after raw F16
selection. Use MIN3 for median inputs containing NaNs.
Match the measured RDNA1-3 first-NaN priority and median signed-zero
ordering, and retain the ISA rules for CDNA. Require an explicit target
policy for legacy selection, reject unsupported targets without throwing,
and regenerate the affected executors.

Cover denormal modes, signed zeros, NaN source and payload priority,
packed clamp, CDNA1-4 F16/F32/F64, RDNA1/2 scalar and SIMD selection,
RDNA vector and dual-issue forms, and RDNA3.5 scalar F16/F32 operations.
Check independent denormal fields, SDWA scaling and packed number
semantics, and compare every lane in scalar/SIMD equivalence tests.

Keep CI independent of the uninitialized tensor-DMA fixtures added
upstream by temporarily excluding only the 11 affected cases.
@kuhar
kuhar force-pushed the users/jakub/rocjitsu-independent-minmax branch from 26867bb to 8542f32 Compare October 22, 2026 01:53
@github-actions github-actions Bot added the github actions Pull requests that update GitHub Actions code label Oct 22, 2026
@kuhar
kuhar merged commit 0aec118 into develop Oct 22, 2026
55 of 58 checks passed
@kuhar
kuhar deleted the users/jakub/rocjitsu-independent-minmax branch October 22, 2026 02:19
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