recomp: lower clamped dot products to hardware DP4a intrinsics #985
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!985
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@UnkwnDev on GitHub · 2026-11-24 09:53 UTC · original
UnkwnDev:arc-dp4a-uma→main· +50 −2 · 2 files · 1 commits · openThis 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
@raylitebull on GitHub · 2026-11-24 10:41 UTC · original
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 on GitHub · 2026-11-24 11:03 UTC · original
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 on GitHub · 2026-11-24 12:19 UTC · original
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.
@throny on GitHub · 2026-11-24 12:27 UTC · original
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
@UnkwnDev on GitHub · 2026-11-24 12:50 UTC · original
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 d3ea6664e212076649a8870224ff47756b5346c6. CI check is green.
@UnkwnDev on GitHub · 2026-11-24 18:13 UTC · original
@throny Rebased onto main
9e3831ewith the tests.rs conflict resolved (both tests preserved). Pushed to arc-dp4a-uma as commit df490c1. CI check is green.@throny on GitHub · 2026-11-24 17:34 UTC · original · edited 2026-11-24 18:16 UTC
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
@UnkwnDev on GitHub · 2026-11-25 07:31 UTC · original
@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).@throny on GitHub · 2026-11-25 07:39 UTC · original
@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).
@UnkwnDev on GitHub · 2026-11-25 07:44 UTC · original
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.@UnkwnDev on GitHub · 2026-11-25 16:00 UTC · original
@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)@throny on GitHub · 2026-11-25 18:55 UTC · original
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.
@DavidM1911 on GitHub · 2026-11-26 00:23 UTC · original
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.)3f841cb653to35ad5fe805@UnkwnDev on GitHub · 2026-11-26 05:16 UTC · original · edited 2026-11-26 05:19 UTC
@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 failedView 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.