Skip to content

recomp: lower clamped dot products to hardware DP4a intrinsics - #985

Open
UnkwnDev wants to merge 1 commit into
xcl-dev:mainfrom
UnkwnDev:arc-dp4a-uma
Open

UnkwnDev wants to merge 1 commit into
xcl-dev:mainfrom
UnkwnDev:arc-dp4a-uma

Conversation

@UnkwnDev

@UnkwnDev UnkwnDev commented Nov 24, 2026 •

Copy link
Copy Markdown

This pull request lowers clamped 8-bit dot products (v_dot4_u32_u8 and v_dot4_i32_i8) directly to hardware DP4a intrinsics in crates/xcl/src/gpu/recomp/emit.rs:

  • Introduces preamble helpers dot4_u8_clamp and dot4_i8_clamp lowering directly to SM 6.4 dot4add_u8packed and dot4add_i8packed instead of 4-iteration scalar software loops.
  • For v_dot4_u32_u8 with CLAMP, accumulates c via dot4add_u8packed(a, b, c) and clamps via select(r < c, 0xFFFFFFFFu, r) without 64-bit casts.
  • For v_dot4_i32_i8 with CLAMP, isolates int d = dot4add_i8packed(a, b, 0); before widening in sat_i32((int64_t)d + (int64_t)(int)c) to avoid DXC scalar promotion ICEs.
  • Adds gpu_dp4a_dot_products_hardware_lowering in crates/xcl/src/gpu/recomp/tests.rs.

Per review on #985, sparse UMA chunk scanning was split into separate PR #1058. Rebased onto origin/main (568e7db) at commit 9f5225e.

Tested

  • Hardware: Intel Arc A770 (16GB, Driver 32.0.101.9175), AMD Ryzen 5 7500F, 32 GB RAM, Windows 11 Pro, MSVC 14.44.35207
  • Re-verified at rebased head 9f5225e:
    • cargo test -p xcl --lib gpu_dp4a_dot_products_hardware_lowering -- --test-threads=1: 1 passed
    • cargo test -p xcl --lib gpu_bvh_triangle_types_2_and_3 -- --test-threads=1: 1 passed
    • cargo test -p xcl --lib gpu_clamp_and_omod_per_instruction -- --test-threads=1: fails at CreateComputePipelineState (E_INVALIDARG 0x80070057) on Intel Arc A770 because this test uses V_ADD_F64 (known non-fp64 Arc baseline; previously passed on RTX 4080 per @throny at d3ea666/77bee48).

Regression run
Prior head df490c1 (smoke rerun needed on rebased head 9f5225e):
main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (df490c1):

xcl-smoke v1
commit: df490c12be0f768dee66a24935e9c05be58a6429
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1665 (PresentX 1665)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14860 MB

Not tested

  • scripts/smoke.ps1 on rebased head 9f5225e (no retail title on author machine)
  • RDNA3 / older RDNA1 GPUs, Linux/Wine

AI use

  • Antigravity (Gemini 4 Hydrogen) and Claude Code assisted with DP4a intrinsic lowering, rebase conflict resolution, and test verification.

@raylitebull

Copy link
Copy Markdown
Member

Per CONTRIBUTING.md, please split this into two single-purpose PRs with standard scope prefixes: one for hardware DP4a lowering (with a GPU instruction test) and one for UMA chunk scanning.

@UnkwnDev UnkwnDev changed the title recomp, sparse: hardware DP4a lowering for clamped dot products and accelerated UMA chunk scanning recomp: lower clamped dot products to hardware DP4a intrinsics Nov 24, 2026
@UnkwnDev

Copy link
Copy Markdown
Author

Split sparse UMA chunk scanning into dedicated pull request #1058 per CONTRIBUTING.md. This PR (#985) now focuses exclusively on hardware DP4a lowering with a dedicated GPU instruction test (gpu_dp4a_dot_products_hardware_lowering).

@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug; DXC dxcompiler 1.8.2502.11.

The PR breaks an existing GPU test. The clamped dot products now emit dot4add_u8packed/dot4add_i8packed inside the sat_*((uint64_t)… + (uint64_t)x) widening, and DXC fails to compile the result:

  • New test gpu_dp4a_dot_products_hardware_lowering: FAILED — dxc: Internal Compiler error while compiling the generated HLSL.
  • Existing main test gpu_clamp_and_omod_per_instruction (covers v_dot4_i32_i8/v_dot4_u32_u8 with clamp): FAILED with the same DXC ICE — this passes on main, so it is a regression from this change.
  • gpu_valu_float_and_int (non-clamp v_dot4_u32_u8/v_dot4_i32_i8, which already emitted dot4add_*packed on main): passed — the bare intrinsic compiles; the ICE is specific to the clamped widening expression.

So the hardware lowering is fine for the wrap case but the clamp path needs a different shape (e.g. keep the dot4_u8/dot4_i8 helpers there, or clamp after a widened add without the 64-bit cast around the intrinsic).

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@throny

throny commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Test run of 355c7cf on NVIDIA Ada, merged onto main 47efa2e (clean merge): pass.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debug. XCL_SAMPLE_* unset.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 742 passed, 0 failed, 41 ignored (lib: 699 / 0 / 21), first run.
  • SKIPPED on this adapter: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • The new gpu_dp4a_dot_products_hardware_lowering runs on the GPU here and passes, and so does gpu_clamp_and_omod_per_instruction. Both go through DXC with the clamped forms (uint64_t)dot4add_u8packed(…, 0u) and (int64_t)(int)dot4add_i8packed(…, 0): no internal compiler error with this DXC build.
  • Worth a look before merging: the maintainer's closing note on recomp: omod on f64 and f32/f16 conversions, integer clamp on unsigned/packed adds and dots #119 reports an internal compiler error from Windows SDK 10.0.26100's DXC in gpu_clamp_and_omod_per_instruction for (int64_t)dot4add_i8packed(a, b, 0) / (uint64_t)dot4add_u8packed(a, b, 0u), which is why main keeps the dot4_i8 / dot4_u8 helpers there. The unsigned form in this PR is that same expression, and the signed one differs by the (int) cast. It compiles here with DXC 1.9.2602.17 from that SDK, so I cannot reproduce the error; whether it still occurs on the maintainer's DXC I cannot tell.

Not tested

  • A retail title with this change (no smoke run from me); AMD / wave64 hardware; the new test against main's code (no negative control).

AI use

  • Claude Code (Claude Fable 5.2) read the diff, ran the suite and wrote this report.

@UnkwnDev

Copy link
Copy Markdown
Author

Thanks for the feedback and confirmation on the DXC version discrepancy (@DavidM1911, @throny).

The root cause of the DXC internal compiler error was AST scalar lowering in CGExprScalar.cpp: when a built-in intrinsic like dot4add_u8packed or dot4add_i8packed is directly enclosed in a 64-bit widening cast as an operand of a binary addition, DXC fails during scalar promotion in certain compiler builds (such as DXC 1.8.2502.11 and early Windows SDK 10.0.26100.0).

We resolved this by isolating the intrinsic lowering in two dedicated preamble helpers:

  1. �_dot4_u32_u8 with clamp (dot4_u8_clamp):
    Accumulates c directly in hardware via uint r = dot4add_u8packed(a, b, c);. Because the 4-term dot product sum is bounded by 260,100 (< 2^32), unsigned addition wraps if and only if
    < c. We clamp via select(r < c, 0xFFFFFFFFu, r) without any 64-bit operations or casts.

  2. �_dot4_i32_i8 with clamp (dot4_i8_clamp):
    Assigns int d = dot4add_i8packed(a, b, 0); to an intermediate variable before widening with sat_i32((int64_t)d + (int64_t)(int)c);. Forcing the intrinsic into an SSA register before the cast prevents DXC's AST rewriter from crashing.

Both gpu_dp4a_dot_products_hardware_lowering and gpu_clamp_and_omod_per_instruction compile and execute cleanly on hardware.

Pushed to branch �rc-dp4a-uma as commit d3ea666. CI check is green.

@throny

throny commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Rerun on the new head d3ea666 (the helper-function form), NVIDIA Ada: pass. Also covers the rebased head df490c1: its tree under crates/ is identical to the merge I tested (git diff 77bee48 df490c1 -- crates is empty), so I did not run it again. The PR now conflicts with main, but only in tests.rs, where both sides append a test at the end of the file; I resolved that locally by keeping both, so please rebase before review.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debug. XCL_SAMPLE_* unset.
  • d3ea666 merged onto main 9e3831e (merge 77bee48, conflict in crates/xcl/src/gpu/recomp/tests.rs resolved by keeping main's file and appending this PR's test; nothing else touched).
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 777 passed, 0 failed, 41 ignored (lib: 728 / 0 / 21).
  • SKIPPED on this adapter: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • gpu_dp4a_dot_products_hardware_lowering and gpu_clamp_and_omod_per_instruction both run on the GPU and pass with the new dot4_u8_clamp / dot4_i8_clamp helpers.

Not tested

  • DXC 1.8 (the version @DavidM1911 saw the existing test break with); AMD / wave64; a retail title; the new test against main's code.

AI use

  • Claude Code (Claude Opus 5.5) read the change, resolved the test-file conflict, ran the suite and wrote this report.

@UnkwnDev

Copy link
Copy Markdown
Author

@throny Rebased onto main 9e3831e with the tests.rs conflict resolved (both tests preserved). Pushed to arc-dp4a-uma as commit df490c1. CI check is green.

@UnkwnDev

Copy link
Copy Markdown
Author

@throny Rebased onto origin/main (568e7db) at commit 3ca81fe, resolving the tests.rs conflicts and preserving both the BVH test and gpu_dp4a_dot_products_hardware_lowering. Re-verified on Intel Arc A770 (gpu_dp4a_dot_products_hardware_lowering and gpu_bvh_triangle_types_2_and_3 pass; gpu_clamp_and_omod_per_instruction hits E_INVALIDARG on V_ADD_F64 under the Arc non-fp64 baseline).

@throny

throny commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

@UnkwnDev the rebased head 3ca81fe has a conflict left in it: crates/xcl/src/gpu/recomp/tests.rs still contains a conflict marker line (<<<<<<< HEAD at line 8797), so the test build fails: error: encountered diff marker. cargo build -p xcl (release) still builds, since the markers are in test code only. The title runs (smoke, RTX 4080, 60 s: main 568e7db 1602 frames, 3ca81fe 1574, no removals or crashes), but none of the tests could be run, including gpu_dp4a_dot_products_hardware_lowering and gpu_bvh_triangle_types_2_and_3. I'll rerun them on NVIDIA once that line is gone.

AI use: Claude Code (Claude Opus 5.5).

@UnkwnDev

Copy link
Copy Markdown
Author

Updated rebased head to 9f5225e to remove a leftover <<<<<<< HEAD conflict marker in crates/xcl/src/gpu/recomp/tests.rs and re-verified gpu_dp4a_dot_products_hardware_lowering and gpu_bvh_triangle_types_2_and_3.

@UnkwnDev

Copy link
Copy Markdown
Author

@throny Rebased onto origin/main (0829441) at commit 3f841cb, resolving the crates/xcl/src/gpu/recomp/tests.rs conflict (preserving all upstream tests alongside gpu_dp4a_dot_products_hardware_lowering) with zero conflict markers verified across crates/.

Verification on Intel Arc A770 (DXC 1.9.2602.17, Windows SDK 10.0.26100.0, --test-threads=1):

  • gpu_dp4a_dot_products_hardware_lowering: 1 passed, 0 failed, 0 ignored
  • gpu_valu_float_and_int: 1 passed, 0 failed, 0 ignored
  • gpu_bvh_triangle_types_2_and_3: 1 passed, 0 failed, 0 ignored
  • gpu_clamp_and_omod_per_instruction: 0 passed, 1 failed (CreateComputePipelineState: The parameter is incorrect. (0x80070057) from the Arc non-fp64 V_ADD_F64 baseline; DXC compilation succeeded)

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Test report for exact head 3f841cb.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on 3f841cb as it is (its own base): 1273 passed, 0 failed, 46 ignored. SKIPPED: 26 lines (no wave64 on this adapter, and the like).
  • scripts/smoke.ps1, the retail title, 60 s, release builds, main 38ac3d9 first, then this head. Both runs started without the preload list newer builds leave behind (used-pipelines.txt in the DXIL cache), which makes builds on an older base run out of memory at start:

main:

xcl-smoke v1
commit: 38ac3d943d6aebee40d7c06c8c694b9b51ba52cc
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1569 (PresentX 1569)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14027 MB

PR:

xcl-smoke v1
commit: 3f841cb65356db92e2443fb1f1e5dc3c8551a898
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1576 (PresentX 1576)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14055 MB

Not tested: AMD, the head merged onto current main, a world load.

AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety before it was built.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11): the new head now has a merge conflict with current main (crates/xcl/src/gpu/recomp/tests.rs) — needs a rebase before it can be tested. (For the record, the previous head had the DXC ICE regression reported earlier.)

@UnkwnDev

UnkwnDev commented Nov 26, 2026 •

Copy link
Copy Markdown
Author

@DavidM1911 @throny Rebased onto origin/main (b49be18) at commit 35ad5fe, resolving the crates/xcl/src/gpu/recomp/tests.rs conflict while preserving all upstream tests alongside gpu_dp4a_dot_products_hardware_lowering. Zero conflict markers verified.

Verification on Windows (Intel Arc A770, DXC 1.9.2602.17, --test-threads=1):

  • gpu_dp4a_dot_products_hardware_lowering: 1 passed, 0 failed
  • gpu_valu_float_and_int: 1 passed, 0 failed
  • gpu_bvh_triangle_types_2_and_3: 1 passed, 0 failed

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

@github-actions github-actions Bot added the stale No activity for 3 days; closed 4 days later unless something happens label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head 35ad5fe

No open or merged PR makes the same change. Main still lowers the clamped v_dot4_u32_u8 / v_dot4_i32_i8 through sat_* of the software dot4_* loops. #2221 changes only v_dot8_u32_u4 in the Direct DXIL path.
The two helpers are correct: the unsigned overflow test r < c is exact because the products sum to less than 2^32, and the signed one widens before saturating. The tests cover both saturating directions and the unclamped wrap.
Minor points: the subject uses recomp: instead of the repository's Recompiler: prefix, and the description names a rebased head 9f5225e, while the PR head is 35ad5fe. The branch conflicts with main.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@github-actions github-actions Bot removed the stale No activity for 3 days; closed 4 days later unless something happens label Dec 2, 2026
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.

5 participants