Skip to content

shader: lower v_min3_f16, v_max3_f16, and v_med3_f16 in direct Compute and Pixel DXIL (#3266 merged with main) - #3452

Open
Leyukaka wants to merge 5 commits into
R0Y00:mainfrom
Leyukaka:takeover-3266-minmax-med3-f16
Open

Leyukaka wants to merge 5 commits into
R0Y00:mainfrom
Leyukaka:takeover-3266-minmax-med3-f16

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

#3266 by @legacy-code-archaeologist, merged with main so it can land. Supersedes #3266. Fixes #3264. Refs #2935.

What is here

Conflict resolution

git merge-tree --write-tree fe1c1d31 df6c0545 exits 1 with one conflicted file and one region: the half_binary op list in DirectCompute::lower(), src/gfx1013_direct_compute.inl. main extended the list after v_fract_f16; #3266 added its three ops at the same place. The resolution keeps both sides, main's entries first:

            op.name == "v_fract_f16" ||
            op.name == "v_ldexp_f16" ||
            op.name == "v_cvt_norm_i16_f16" ||
            op.name == "v_cvt_norm_u16_f16" ||
            op.name == "v_cvt_pknorm_i16_f16" ||
            op.name == "v_cvt_pknorm_u16_f16" ||
            op.name == "v_min3_f16" ||
            op.name == "v_max3_f16" ||
            op.name == "v_med3_f16")

tests/native_minmax_med3_f16_check.py and tests/cmake/native_minmax_med3_f16.cmake are new files and merge without conflict.

Verified

  • The conflict is that single region; no other file conflicts.
  • Nothing was built or run locally on the merged head.

Not covered

…0Y00#3264)

Lower VOP3 v_min3_f16 (0x351), v_max3_f16 (0x354), and v_med3_f16 (0x357) in DirectCompute::float_alu() with abs/neg/clamp/op_sel[3:0], exact binary16 NaN and signed-zero ordering, other-half preservation, binary16 denormal mode tracking, and IR/DXIL/Pixel/Compute tests.

Fixes R0Y00#3264, Refs R0Y00#2935. AI-assisted.
Add med3_nan_src2, med3_two_nans, min3_clamp_negative, med3_three_nans_clamp, and min3_inline_neg_int (src0=193) to tests/native_minmax_med3_f16_check.py (29 cases total). Refs R0Y00#3264, R0Y00#2935. AI-assisted.
Resolves the half_binary list as the union of both sides.
@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of head 5b06bab (read-only, on Linux; no build or ctest run here). I found no MUST items, 1 SHOULD and 4 NITs.

The merge leaves the #3266 commits unchanged: git range-diff d649e470..df6c0545 fe1c1d31..5b06bab7 shows 1: b82ba196 = 1: b82ba196 and 2: df6c0545 = 2: df6c0545. The only thing the merge adds is the union of the half_binary list. git merge-tree --write-tree origin/main 5b06bab7 exits with rc 0 on current main.

SHOULD

  1. The new tests have not been run on this head. CI run 46261152654 at 5b06bab runs none of them, because the pr preset doesn't include them: gh run view 46261152654 --log | grep -c minmax_med3 prints 0. runtime: default to native shaders and Opus decoding #3449 (1990fea, in this base) made the launchers default to native shaders. So these three ops are now lowered on the default launcher path with no flag, where before this PR they were refused. Before merge, please run this on this head, on WARP and on a GPU:
    ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'
    (On the author's Intel adapter, _compute_hardware exited 77, a capability skip.) I expect a pass. The commits are identical, and the helper drift since d649e47 doesn't affect this check: native_f16_alu_check STRIDE went from 512 to 1024, but this check uses a fixed PROLOGUE literal and the hard-coded layout group * 1024 + lane * 32.

NIT

  1. The in-op mode gate only tests the denorm bits, (mode_bits & 0xc0u) != 0xc0u. That is correct, since min/max don't round. But its message says "rounding or denormal". The gate also can't be reached: consume_half_mode refuses first, so neither mode refusal control ever hits it.
  2. The expected values come from a Python model that mirrors the lowering. So the GPU runs show that the DXIL matches the model, not that it matches gfx1013. Three conventions are unmeasured on gfx1013: the two-NaN result 0x7e00, sNaN quieting in IEEE mode, and med3 signed-zero ties. For example, med3(-0, +0, -1) gives 0x8000 here, while the ISA pseudocode (max3 == S0 compared as floats, giving max(S1,S2)) gives 0x0000. This matches the existing v_med3_f32 and v_pk_min_f16, so it is not a regression.
  3. In _controls, the DXIL marker is weak: assert 'icmp ugt i32' in dump and 'icmp ult i32' in dump. The compile rc and the refusal cases carry the real weight.
  4. There is no docs entry for these ops. git grep -E 'v_(min3|max3|med3)_f16' -- '*.md' finds nothing, while the f32 forms are in docs/experiments.md. The case counts in the shader: lower v_min3_f16, v_max3_f16, and v_med3_f16 in direct Compute and Pixel DXIL #3266 body are also stale. Both are already listed under "Not covered" in the body.

This comment was AI-assisted.

@Leyukaka

Copy link
Copy Markdown
Collaborator Author

SHOULD 1, run on head 5b06bab7 in an isolated Windows Sandbox with no network: dev preset configured with -DX2W_WITH_OPUS=OFF, full build, then

ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'

1/5 native_minmax_med3_f16_ir .................   Passed    1.22 sec
2/5 native_minmax_med3_f16_controls ...........   Passed    2.46 sec
3/5 native_minmax_med3_f16_compute_hardware ...   Passed    2.21 sec
4/5 native_minmax_med3_f16_pixel_warp .........   Passed    5.26 sec
5/5 native_minmax_med3_f16_pixel_hardware .....   Passed   10.00 sec
100% tests passed, 0 tests failed out of 5

Test output:

  • _ir: 29 cases matched exact model; 7 refusals matched.
  • _controls: compiled 29 cases to DXIL; verified 7 refusals.
  • _compute_hardware: 29 cases matched across 2x32 lanes and guards, on a hardware adapter. It passed, it did not exit 77.
  • _pixel_warp and _pixel_hardware: 14 pixel draws (28 cases) matched on each.

WARP is covered by the pixel test only: tests/cmake/native_minmax_med3_f16.cmake registers no WARP variant of the compute test.

NITs:

  1. Will fix in a follow-up commit: the gate at src/gfx1013_direct_compute.inl:2661 tests only (mode_bits & 0xc0u) != 0xc0u, so its message becomes a denormal-only one, as the packed min/max gate at line 3233 already has. The two mode controls get their string from consume_half_mode, so their expected text does not change.
  2. Left as the original author's design. Not measured on gfx1013 here either.
  3. Left as is.
  4. Will add a docs/experiments/ entry for the three ops in the same follow-up commit. The counts in this PR's body (29 cases, 14 draws) match the run above; the shader: lower v_min3_f16, v_max3_f16, and v_med3_f16 in direct Compute and Pixel DXIL #3266 description is not ours to edit.

The follow-up commit changes the head, so the five tests will be rerun on it and the result posted here.

@Leyukaka

Copy link
Copy Markdown
Collaborator Author

Follow-up commits 14aae9ba and 63416373 (NIT 1 and NIT 4), head is now 63416373. Three files:

  • src/gfx1013_direct_compute.inl:2662: the min3/max3/med3 gate message changes from unsupported binary16 rounding or denormal mode to unsupported binary16 min3/max3/med3 denormal mode. The condition is unchanged.
  • tests/native_minmax_med3_f16_check.py:188: the expected string of the conditional-branch MODE control follows the new message.
  • docs/experiments/native-minmax-med3-f16.md: new entry for the three ops (scope, refusals, test coverage, reproduction).

Correction to my previous comment: only the s_denorm_mode 3 control gets its message from consume_half_mode; the conditional-branch control writes denorm16 = 3, which consume_half_mode accepts, and the refusal comes from the gate itself, so its expected string did change.

Rerun on 14aae9ba (63416373 on top only rewords one sentence of docs/experiments/native-minmax-med3-f16.md, so it was not rerun), same procedure as before (isolated Windows Sandbox, no network, dev preset with -DX2W_WITH_OPUS=OFF, full build):

ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'

native_minmax_med3_f16_ir                  Passed    1.32 sec
native_minmax_med3_f16_controls            Passed    2.84 sec
native_minmax_med3_f16_compute_hardware    Passed    2.09 sec
native_minmax_med3_f16_pixel_warp          Passed    4.95 sec
native_minmax_med3_f16_pixel_hardware      Passed   10.54 sec
100% tests passed, 0 tests failed out of 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shader: lower v_min3_f16, v_max3_f16, and v_med3_f16 in direct Compute and Pixel DXIL

3 participants