rdna2spirv: treat VOP3P v_dot2_f32_f16 clamp as hardware no-op (SHADER-DOT2-F32-F16-CLAMP) #410

Merged
tahffo68hk-hash merged 1 commit from upstream-pr/410 into main 2026-11-28 11:51:29 +00:00
tahffo68hk-hash commented 2026-11-24 04:46:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tahffo68hk-hash on 2026-11-24T04:46:48Z.


Claimed in the coordination issue as: SHADER-DOT2-F32-F16-CLAMP

Problem

tools/rdna2spirv.py applied clamp_mods ([0.0, 1.0] saturation) when VOP3P v_dot2_f32_f16 had the clamp modifier set. As noted in docs/design.md, v_dot2_f32_f16 had not previously been hardware-measured on RDNA2.

Measured natively on AMD RDNA2 (gfx1036 via tools/hw_oracle) across all four ieee / dx10_clamp / denorm32 / denorm16_64 MODE combinations: the VOP3P clamp bit on v_dot2_f32_f16 is a hardware no-op:

  • 1.0*1.0 + 1.0*1.0 + 1.0 with clamp -> 0x40400000 (+3.0f), whereas the translator returned 0x3f800000 (1.0f).
  • -1.0*1.0 + -1.0*1.0 + -1.0 with clamp -> 0xc0400000 (-3.0f), whereas the translator returned 0x00000000 (0.0f).
  • +inf with clamp -> 0x7f800000; NaN with clamp -> 0x7fc00000.

Fix

  • Do not apply clamp_mods on VOP3P v_dot2_f32_f16 in tools/rdna2spirv.py.
  • Update tests/semantic/test_alu_dot_complete.py to match the hardware-measured no-op behavior and add explicit +3.0f / -3.0f / +inf regression assertions.
  • Record the hardware-measured result in docs/design.md.

Verification

  • CPU semantic tests: python -I tests/semantic/test_alu_dot_complete.py -> OK.
  • Hardware differential verification (Native AMD RDNA2 vs. Translated Vulkan + spirv-val):
    • Native reference: AMD GFX1036 (RDNA2) via tools/hw_oracle -> 4/4 dwords across +3.0f, -3.0f, +inf, and op_sel+neg_lo+clamp (verified across all 4 MODE combinations).
    • Translated execution: NVIDIA GeForce RTX 5060 Ti (driver 617.42, Windows 11) via vk_compute_test.exe:
      • Wave32: 4/4 exact dwords (spirv-val PASS)
      • Wave64 (--wave64-emulate): 4/4 exact dwords (spirv-val PASS)
  • No game files used (synthetic assembly only).
  • AI-assisted: Yes (Antigravity).
中文翻译

在协调帖 #14 中认领的 ID:SHADER-DOT2-F32-F16-CLAMP

问题描述

tools/rdna2spirv.py 此前对带有 clamp 的 VOP3P 指令 v_dot2_f32_f16 施加了 [0.0, 1.0] 截断(docs/design.md 注明此前尚未在 RDNA2 硬件实测)。

经原生 AMD RDNA2(gfx1036)在全部 4 种 ieee / dx10_clamp / denorm MODE 组合下实测确认:VOP3P v_dot2_f32_f16 的 clamp 位为硬件空操作(+3.0f 保持 0x40400000、-3.0f 保持 0xc0400000、+inf 保持 0x7f800000、NaN 保持 0x7fc00000)。

修复方案

  • 在 tools/rdna2spirv.py 中对 VOP3P v_dot2_f32_f16 不再施加 clamp_mods。
  • 更新 tests/semantic/test_alu_dot_complete.py 并新增 +3.0f / -3.0f / +inf 回归用例。
  • 在 docs/design.md 契约表中记录硬件实测结果。

验证结果

  • CPU 语义测试:tests/semantic/test_alu_dot_complete.py 全部通过。
  • 跨架构硬件差分验证(原生 AMD GFX1036 vs 翻译后 NVIDIA RTX 5060 Ti,驱动 617.42):Wave32 4/4 精确一致,Wave64 模拟(--wave64-emulate)4/4 精确一致,spirv-val 全部通过。
  • 仅使用手写合成汇编,无游戏文件。
  • AI 辅助:是(Antigravity)。
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5466253013 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/410). Originally posted by [tahffo68hk-hash](https://github.com/tahffo68hk-hash) on 2026-11-24T04:46:48Z. --- Claimed in the coordination issue as: `SHADER-DOT2-F32-F16-CLAMP` ## Problem `tools/rdna2spirv.py` applied `clamp_mods` (`[0.0, 1.0]` saturation) when VOP3P `v_dot2_f32_f16` had the `clamp` modifier set. As noted in `docs/design.md`, `v_dot2_f32_f16` had not previously been hardware-measured on RDNA2. Measured natively on AMD RDNA2 (`gfx1036` via `tools/hw_oracle`) across all four `ieee` / `dx10_clamp` / `denorm32` / `denorm16_64` MODE combinations: the VOP3P `clamp` bit on `v_dot2_f32_f16` is a **hardware no-op**: - `1.0*1.0 + 1.0*1.0 + 1.0` with `clamp` -> `0x40400000` (`+3.0f`), whereas the translator returned `0x3f800000` (`1.0f`). - `-1.0*1.0 + -1.0*1.0 + -1.0` with `clamp` -> `0xc0400000` (`-3.0f`), whereas the translator returned `0x00000000` (`0.0f`). - `+inf` with `clamp` -> `0x7f800000`; `NaN` with `clamp` -> `0x7fc00000`. ## Fix - Do not apply `clamp_mods` on VOP3P `v_dot2_f32_f16` in `tools/rdna2spirv.py`. - Update `tests/semantic/test_alu_dot_complete.py` to match the hardware-measured no-op behavior and add explicit `+3.0f` / `-3.0f` / `+inf` regression assertions. - Record the hardware-measured result in `docs/design.md`. ## Verification - **CPU semantic tests**: `python -I tests/semantic/test_alu_dot_complete.py` -> OK. - **Hardware differential verification (Native AMD RDNA2 vs. Translated Vulkan + `spirv-val`)**: - Native reference: AMD GFX1036 (RDNA2) via `tools/hw_oracle` -> 4/4 dwords across `+3.0f`, `-3.0f`, `+inf`, and `op_sel`+`neg_lo`+`clamp` (verified across all 4 MODE combinations). - Translated execution: NVIDIA GeForce RTX 5060 Ti (driver 617.42, Windows 11) via `vk_compute_test.exe`: - Wave32: **4/4 exact dwords** (`spirv-val` PASS) - Wave64 (`--wave64-emulate`): **4/4 exact dwords** (`spirv-val` PASS) - No game files used (synthetic assembly only). - AI-assisted: Yes (Antigravity). <details> <summary>中文翻译</summary> 在协调帖 #14 中认领的 ID:`SHADER-DOT2-F32-F16-CLAMP` ## 问题描述 `tools/rdna2spirv.py` 此前对带有 `clamp` 的 VOP3P 指令 `v_dot2_f32_f16` 施加了 `[0.0, 1.0]` 截断(`docs/design.md` 注明此前尚未在 RDNA2 硬件实测)。 经原生 AMD RDNA2(`gfx1036`)在全部 4 种 `ieee` / `dx10_clamp` / `denorm` MODE 组合下实测确认:VOP3P `v_dot2_f32_f16` 的 `clamp` 位为**硬件空操作**(`+3.0f` 保持 `0x40400000`、`-3.0f` 保持 `0xc0400000`、`+inf` 保持 `0x7f800000`、`NaN` 保持 `0x7fc00000`)。 ## 修复方案 - 在 `tools/rdna2spirv.py` 中对 VOP3P `v_dot2_f32_f16` 不再施加 `clamp_mods`。 - 更新 `tests/semantic/test_alu_dot_complete.py` 并新增 `+3.0f` / `-3.0f` / `+inf` 回归用例。 - 在 `docs/design.md` 契约表中记录硬件实测结果。 ## 验证结果 - CPU 语义测试:`tests/semantic/test_alu_dot_complete.py` 全部通过。 - 跨架构硬件差分验证(原生 AMD GFX1036 vs 翻译后 NVIDIA RTX 5060 Ti,驱动 617.42):Wave32 **4/4 精确一致**,Wave64 模拟(`--wave64-emulate`)**4/4 精确一致**,`spirv-val` 全部通过。 - 仅使用手写合成汇编,无游戏文件。 - AI 辅助:是(Antigravity)。 </details>
Oliwettoo commented 2026-11-24 10:36:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Oliwettoo on 2026-11-24T10:36:34Z.


Code and test look right, and test_alu_dot_complete.py passes with the PR on current main. The measured words are only in the PR text, so nobody can reproduce them: please commit a reproducible gfx103x case (an int_hw_probe.py case, or the tools/hw_oracle .asm plus its raw output), as the maintainer asked on #392/#398 (AGENTS.md: a new rule goes in with how it was confirmed). AI-assisted review.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7129007466 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/410#issuecomment-7129007466). Originally posted by [Oliwettoo](https://github.com/Oliwettoo) on 2026-11-24T10:36:34Z. --- Code and test look right, and `test_alu_dot_complete.py` passes with the PR on current `main`. The measured words are only in the PR text, so nobody can reproduce them: please commit a reproducible gfx103x case (an `int_hw_probe.py` case, or the `tools/hw_oracle` .asm plus its raw output), as the maintainer asked on #392/#398 (AGENTS.md: a new rule goes in with how it was confirmed). AI-assisted review.
sodove commented 2026-11-28 10:45:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:45:27Z.


#410 | head abb68a9ab2964fce5c39e652b66095df11a94b64 | python3 -m unittest discover -s tests/semantic -p test_alu_dot_complete.py -v | red: 9 run, 5 failures | green: 9 passed | Red → green

On main the packed dot-product clamp cases produced incorrect words. The merged translator passed the clamp and negation combinations.

Captured 81 distinct complete SPIR-V module(s) emitted while rerunning test_alu_dot_complete.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand.

Base 3bd936ecd98995bca3e1da83d5e28d2343001aef was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238102020 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/410#issuecomment-7238102020). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:45:27Z. --- #410 | head `abb68a9ab2964fce5c39e652b66095df11a94b64` | `python3 -m unittest discover -s tests/semantic -p test_alu_dot_complete.py -v` | red: 9 run, 5 failures | green: 9 passed | **Red → green** On main the packed dot-product clamp cases produced incorrect words. The merged translator passed the clamp and negation combinations. Captured 81 distinct complete SPIR-V module(s) emitted while rerunning test_alu_dot_complete.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand. Base `3bd936ecd98995bca3e1da83d5e28d2343001aef` was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7237873883).
DadaCap commented 2026-11-28 11:51:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:51:31Z.


Merged, thank you @tahffo68hk-hash! This translator PR (rdna2spirv: treat VOP3P v_dot2_f32_f16 clamp as hardware no-op (SHADER-DOT2-F32-F16-CLAMP)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238828915 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/410#issuecomment-7238828915). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:51:31Z. --- Merged, thank you @tahffo68hk-hash! This translator PR (rdna2spirv: treat VOP3P v_dot2_f32_f16 clamp as hardware no-op (SHADER-DOT2-F32-F16-CLAMP)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!410
No description provided.