Shaders: round FP16 transcendentals to nearest in either mode #3617

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3617 into main
andrewpozdnakov7-jpg commented 2026-11-27 22:23:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T22:23:24Z.


RDNA2 rounds seven FP16 transcendental instructions to nearest even under both values of the tested rounding field. The published RX 6700 XT sweep ran all input encodings with the original and round-to-zero settings, and the harness validated the MODE bits on the device. Sweep results · MODE check

Use nearest-even narrowing for v_rcp_f16, v_sqrt_f16, v_rsq_f16, v_log_f16, v_exp_f16, v_sin_f16, and v_cos_f16. Ordinary FP16 conversions continue to use the requested rounding mode.

On Windows with app-local WARP 1.0.22 and D3D12 Agility 1.620.2, the synthetic regression reports 7 mismatches out of 28 readbacks on 63bcca4, all with FP_ROUND=3. The patch passes all 28. For example, v_rcp_f16(17) changes from 0x2b87 to 0x2b88 in that mode. The existing conversion control passes all 38 inputs under both modes. Inputs are synthetic.

Coordination claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7229239430

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5533870431 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3617). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T22:23:24Z. --- RDNA2 rounds seven FP16 transcendental instructions to nearest even under both values of the tested rounding field. The published RX 6700 XT sweep ran all input encodings with the original and round-to-zero settings, and the harness validated the MODE bits on the device. [Sweep results](https://github.com/ubiquitarianism/leonida/blob/a73a57e1339be072baf5522351c8ec7f1482b56b/docs/shader_validation.md#L1360-L1425) · [MODE check](https://github.com/ubiquitarianism/leonida/blob/a73a57e1339be072baf5522351c8ec7f1482b56b/tools/f16_trans_sweep.py#L220-L241) Use nearest-even narrowing for `v_rcp_f16`, `v_sqrt_f16`, `v_rsq_f16`, `v_log_f16`, `v_exp_f16`, `v_sin_f16`, and `v_cos_f16`. Ordinary FP16 conversions continue to use the requested rounding mode. On Windows with app-local WARP 1.0.22 and D3D12 Agility 1.620.2, the synthetic regression reports 7 mismatches out of 28 readbacks on `63bcca4`, all with `FP_ROUND=3`. The patch passes all 28. For example, `v_rcp_f16(17)` changes from `0x2b87` to `0x2b88` in that mode. The existing conversion control passes all 38 inputs under both modes. Inputs are synthetic. Coordination claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7229239430 AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-27 22:25:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T22:25:30Z.


Verified 8bfad4c against 63bcca4 on Windows with app-local WARP 1.0.22 and D3D12 Agility 1.620.2. The same synthetic fixture went from 7 wrong outputs in 28 readbacks to 28 correct. The 38-input FP32-to-FP16 control still distinguishes the two rounding settings. Both strict shader Clippy configurations and the repository asset policy passed. Windows CI for this head

I also ran both regressions on 4ccc63e with #3609. It passes the seven-op fixture and the exp midpoint test, including 16 readbacks across the plain, abs, neg, and clamp variants. The two changes can be reviewed separately, with the combined branch available for an integration test.

Please keep the Git author on a cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if the work is folded into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7229316566 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3617#issuecomment-7229316566). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T22:25:30Z. --- Verified `8bfad4c` against `63bcca4` on Windows with app-local WARP 1.0.22 and D3D12 Agility 1.620.2. The same synthetic fixture went from 7 wrong outputs in 28 readbacks to 28 correct. The 38-input FP32-to-FP16 control still distinguishes the two rounding settings. Both strict shader Clippy configurations and the repository asset policy passed. [Windows CI for this head](https://github.com/Marvisak/VIctory/actions/runs/46076350312/job/140764856572) I also ran both regressions on [`4ccc63e` with #3609](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/4ccc63e54222acc47718686f6994bddb22c8e476). It passes the seven-op fixture and the exp midpoint test, including 16 readbacks across the plain, abs, neg, and clamp variants. The two changes can be reviewed separately, with the combined branch available for an integration test. Please keep the Git author on a cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if the work is folded into another commit. AI-assisted with OpenAI Codex.
ColorMeBoom commented 2026-11-28 00:24:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T00:24:25Z.


Hardware run on AMD, since the report so far is WARP: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head 8bfad4c on 63bcca4. The test fixture checks the hardware adapter and WARP in turn, and neither was skipped.

  • half_transcendentals_round_to_nearest_in_both_modes passes on both.
  • Full victory-shader --lib --features host: 303 passed, 0 failed, 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7230887089 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3617#issuecomment-7230887089). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T00:24:25Z. --- Hardware run on AMD, since the report so far is WARP: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head `8bfad4c` on `63bcca4`. The test fixture checks the hardware adapter and WARP in turn, and neither was skipped. - `half_transcendentals_round_to_nearest_in_both_modes` passes on both. - Full `victory-shader --lib --features host`: 303 passed, 0 failed, 3 ignored. AI use: Claude Code (Claude Opus 5.5).
upipibi commented 2026-11-28 04:44:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T04:44:31Z.


Hardware runs for this PR and #3620, both WARP-only so far: RTX 3070 8 GB, driver 616.56, Windows 11, 3 runs each, hardware adapter and WARP in the same process.

  • #3617 at 8bfad4c: half_transcendentals_round_to_nearest_in_both_modes passed 3 of 3.
  • #3620 at 0fcf49d: f16_results_round_as_the_mode_says passed 3 of 3. The v_cvt_f16_f32 probe had 62 inputs, model mismatches hardware 0 and warp 0, and hardware and WARP differed on 0. main 63bcca4 runs the same test on its 38 inputs with the same result, so the 24 added midpoint inputs pass on NVIDIA too.

AI-assisted (Claude Code, Claude Opus 5.5 built both heads and ran the tests on this card).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7234230421 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3617#issuecomment-7234230421). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-28T04:44:31Z. --- Hardware runs for this PR and #3620, both WARP-only so far: RTX 3070 8 GB, driver 616.56, Windows 11, 3 runs each, hardware adapter and WARP in the same process. - **#3617 at `8bfad4c`:** `half_transcendentals_round_to_nearest_in_both_modes` passed 3 of 3. - **#3620 at `0fcf49d`:** `f16_results_round_as_the_mode_says` passed 3 of 3. The `v_cvt_f16_f32` probe had 62 inputs, model mismatches `hardware 0` and `warp 0`, and hardware and WARP differed on 0. `main` `63bcca4` runs the same test on its 38 inputs with the same result, so the 24 added midpoint inputs pass on NVIDIA too. AI-assisted (Claude Code, Claude Opus 5.5 built both heads and ran the tests on this card).
kilolimaVI commented 2026-11-28 21:55:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T21:55:35Z.


AMD Radeon 780M (RDNA3) + WARP, Windows 11, head 8bfad4c. Before (main 63bcca4 + this PR's test): fails on both adapters, every checked case one ulp low with FP_ROUND=3, e.g. rcp(0x4c40) gives 0xa55a2b87 for 0xa55a2b88, sqrt(0x3200) …36ed for …36ee. After: passes, 5 of 5 runs. Full suite (victory-shader + victory-gpu --features diagnostics): 552 passed. AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7246372663 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3617#issuecomment-7246372663). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-28T21:55:35Z. --- AMD Radeon 780M (RDNA3) + WARP, Windows 11, head `8bfad4c`. Before (main `63bcca4` + this PR's test): fails on both adapters, every checked case one ulp low with FP_ROUND=3, e.g. `rcp(0x4c40)` gives `0xa55a2b87` for `0xa55a2b88`, `sqrt(0x3200)` `…36ed` for `…36ee`. After: passes, 5 of 5 runs. Full suite (`victory-shader` + `victory-gpu --features diagnostics`): 552 passed. AI-assisted (Claude).
andrewpozdnakov7-jpg commented 2026-11-28 22:22:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T22:22:43Z.


kilolimaVI independently tested the #3617 and #3717 integration on a physical Radeon 780M (RDNA3). The plain merge 15edfeb failed the nearest-even test in FP_ROUND=3. The follow-up 15f2978 passed both the rounding and NaN tests and all 37 VALU tests on that adapter. Native A/B report

The maintainer can review the narrow integration change when taking both PRs. Please retain the Git authors on cherry-pick or rebase. Tested follow-up

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7246693179 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3617#issuecomment-7246693179). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T22:22:43Z. --- kilolimaVI independently tested the #3617 and #3717 integration on a physical Radeon 780M (RDNA3). The plain merge 15edfeb failed the nearest-even test in FP_ROUND=3. The follow-up 15f2978 passed both the rounding and NaN tests and all 37 VALU tests on that adapter. [Native A/B report](https://github.com/Marvisak/VIctory/pull/3717#issuecomment-7246644226) The maintainer can review the narrow integration change when taking both PRs. Please retain the Git authors on cherry-pick or rebase. [Tested follow-up](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/15f297817992600086f74c76ab099caf7b2a6275) AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3617:upstream-pr/3617'
git switch 'upstream-pr/3617'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3617'
git switch 'upstream-pr/3617'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3617'
git switch 'upstream-pr/3617'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3617'
git switch 'main'
git merge --squash 'upstream-pr/3617'
git switch 'main'
git merge --ff-only 'upstream-pr/3617'
git switch 'main'
git merge 'upstream-pr/3617'
git push origin 'main'
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
Marvisak/VIctory!3617
No description provided.