recomp: lower clamped dot products to hardware DP4a intrinsics #979
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/985"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-24T09:53:19Z.
This pull request lowers clamped 8-bit dot products (
v_dot4_u32_u8andv_dot4_i32_i8) directly to hardware DP4a intrinsics incrates/xcl/src/gpu/recomp/emit.rs:dot4_u8_clampanddot4_i8_clamplowering directly to SM 6.4dot4add_u8packedanddot4add_i8packedinstead of 4-iteration scalar software loops.v_dot4_u32_u8withCLAMP, accumulatescviadot4add_u8packed(a, b, c)and clamps viaselect(r < c, 0xFFFFFFFFu, r)without 64-bit casts.v_dot4_i32_i8withCLAMP, isolatesint d = dot4add_i8packed(a, b, 0);before widening insat_i32((int64_t)d + (int64_t)(int)c)to avoid DXC scalar promotion ICEs.gpu_dp4a_dot_products_hardware_loweringincrates/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 commit9f5225e.Tested
9f5225e:cargo test -p xcl --lib gpu_dp4a_dot_products_hardware_lowering -- --test-threads=1: 1 passedcargo test -p xcl --lib gpu_bvh_triangle_types_2_and_3 -- --test-threads=1: 1 passedcargo test -p xcl --lib gpu_clamp_and_omod_per_instruction -- --test-threads=1: fails atCreateComputePipelineState(E_INVALIDARG0x80070057) on Intel Arc A770 because this test usesV_ADD_F64(known non-fp64 Arc baseline; previously passed on RTX 4080 per@thronyatd3ea666/77bee48).Regression run
Prior head
df490c1(smoke rerun needed on rebased head9f5225e):main(beaa245):PR (
df490c1):Not tested
scripts/smoke.ps1on rebased head9f5225e(no retail title on author machine)AI use
[PR #985] recomp, sparse: hardware DP4a lowering for clamped dot products and accelerated UMA chunk scanningto [PR #985] recomp: lower clamped dot products to hardware DP4a intrinsicsImported from ivall/xcl. Originally posted by raylitebull on 2026-11-24T10:41:07Z.
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.Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-24T11:03:42Z.
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).
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T12:19:00Z.
Independent verification, merged onto current
main384f7f7locally (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_i8packedinside thesat_*((uint64_t)… + (uint64_t)x)widening, and DXC fails to compile the result:gpu_dp4a_dot_products_hardware_lowering: FAILED —dxc: Internal Compiler errorwhile compiling the generated HLSL.gpu_clamp_and_omod_per_instruction(coversv_dot4_i32_i8/v_dot4_u32_u8with clamp): FAILED with the same DXC ICE — this passes onmain, so it is a regression from this change.gpu_valu_float_and_int(non-clampv_dot4_u32_u8/v_dot4_i32_i8, which already emitteddot4add_*packedon 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_i8helpers 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.
Imported from ivall/xcl. Originally posted by throny on 2026-11-24T12:27:45Z.
Test run of
355c7cfon NVIDIA Ada, merged ontomain47efa2e(clean merge): pass.Tested
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.SKIPPEDon this adapter:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).gpu_dp4a_dot_products_hardware_loweringruns on the GPU here and passes, and so doesgpu_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.gpu_clamp_and_omod_per_instructionfor(int64_t)dot4add_i8packed(a, b, 0)/(uint64_t)dot4add_u8packed(a, b, 0u), which is whymainkeeps thedot4_i8/dot4_u8helpers 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
main's code (no negative control).AI use
Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-24T12:50:47Z.
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:
_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.
_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
d3ea6664e2. CI check is green.Imported from ivall/xcl. Originally posted by throny on 2026-11-24T17:34:40Z.
Rerun on the new head
d3ea666(the helper-function form), NVIDIA Ada: pass. Also covers the rebased headdf490c1: its tree undercrates/is identical to the merge I tested (git diff 77bee48 df490c1 -- cratesis empty), so I did not run it again. The PR now conflicts withmain, but only intests.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
stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); debug.XCL_SAMPLE_*unset.d3ea666merged ontomain9e3831e(merge77bee48, conflict incrates/xcl/src/gpu/recomp/tests.rsresolved by keepingmain'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).SKIPPEDon 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_loweringandgpu_clamp_and_omod_per_instructionboth run on the GPU and pass with the newdot4_u8_clamp/dot4_i8_clamphelpers.Not tested
main's code.AI use
Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-24T18:13:02Z.
@throny Rebased onto main
9e3831ewith the tests.rs conflict resolved (both tests preserved). Pushed to arc-dp4a-uma as commitdf490c1. CI check is green.Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-25T07:31:46Z.
@throny Rebased onto
origin/main(568e7db) at commit3ca81fe, resolving thetests.rsconflicts and preserving both the BVH test andgpu_dp4a_dot_products_hardware_lowering. Re-verified on Intel Arc A770 (gpu_dp4a_dot_products_hardware_loweringandgpu_bvh_triangle_types_2_and_3pass;gpu_clamp_and_omod_per_instructionhitsE_INVALIDARGonV_ADD_F64under the Arc non-fp64 baseline).Imported from ivall/xcl. Originally posted by throny on 2026-11-25T07:39:42Z.
@UnkwnDev the rebased head
3ca81fehas a conflict left in it:crates/xcl/src/gpu/recomp/tests.rsstill contains a conflict marker line (<<<<<<< HEADat 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:main568e7db1602 frames,3ca81fe1574, no removals or crashes), but none of the tests could be run, includinggpu_dp4a_dot_products_hardware_loweringandgpu_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).
Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-25T07:44:31Z.
Updated rebased head to
9f5225eto remove a leftover<<<<<<< HEADconflict marker incrates/xcl/src/gpu/recomp/tests.rsand re-verifiedgpu_dp4a_dot_products_hardware_loweringandgpu_bvh_triangle_types_2_and_3.Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-25T16:00:31Z.
@throny Rebased onto
origin/main(0829441) at commit3f841cb, resolving thecrates/xcl/src/gpu/recomp/tests.rsconflict (preserving all upstream tests alongsidegpu_dp4a_dot_products_hardware_lowering) with zero conflict markers verified acrosscrates/.Verification on Intel Arc A770 (DXC
1.9.2602.17, Windows SDK10.0.26100.0,--test-threads=1):gpu_dp4a_dot_products_hardware_lowering: 1 passed, 0 failed, 0 ignoredgpu_valu_float_and_int: 1 passed, 0 failed, 0 ignoredgpu_bvh_triangle_types_2_and_3: 1 passed, 0 failed, 0 ignoredgpu_clamp_and_omod_per_instruction: 0 passed, 1 failed (CreateComputePipelineState: The parameter is incorrect. (0x80070057)from the Arc non-fp64V_ADD_F64baseline; DXC compilation succeeded)Imported from ivall/xcl. Originally posted by throny on 2026-11-25T18:55:48Z.
Test report for exact head
3f841cb.Tested
cargo build --workspace && cargo test --workspace -- --test-threads=4on3f841cbas 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,main38ac3d9first, then this head. Both runs started without the preload list newer builds leave behind (used-pipelines.txtin the DXIL cache), which makes builds on an older base run out of memory at start:main:
PR:
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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T00:23:18Z.
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.)Imported from ivall/xcl. Originally posted by UnkwnDev on 2026-11-26T05:16:29Z.
@DavidM1911 @throny Rebased onto
origin/main(b49be18) at commit35ad5fe, resolving thecrates/xcl/src/gpu/recomp/tests.rsconflict while preserving all upstream tests alongsidegpu_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 failedgpu_valu_float_and_int: 1 passed, 0 failedgpu_bvh_triangle_types_2_and_3: 1 passed, 0 failedImported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:32:30Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:35:58Z.
Triage (#1607) – head
35ad5feNo open or merged PR makes the same change. Main still lowers the clamped
v_dot4_u32_u8/v_dot4_i32_i8throughsat_*of the softwaredot4_*loops. #2221 changes onlyv_dot8_u32_u4in the Direct DXIL path.The two helpers are correct: the unsigned overflow test
r < cis 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'sRecompiler:prefix, and the description names a rebased head9f5225e, while the PR head is35ad5fe. 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.