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 directly to hardware DP4a intrinsics:

In crates/xcl/src/gpu/recomp/emit.rs, clamped dot products (v_dot4_u32_u8 and v_dot4_i32_i8) previously fell back to 4-iteration scalar software loops (dot4_u8 and dot4_i8). We introduce helper functions (dot4_u8_clamp and dot4_i8_clamp) that lower directly to SM 6.4 dot4add_u8packed and dot4add_i8packed.
For unsigned clamped dots, dot4add_u8packed(a, b, c) is accumulated directly in hardware and clamped via select(r < c, 0xFFFFFFFFu, r) without 64-bit casts. For signed clamped dots, dot4add_i8packed(a, b, 0) is isolated to a 32-bit SSA register before widening to sat_i32, eliminating the AST scalar promotion ICE in DXC 1.8.2502.11 / Windows SDK 10.0.26100.0. This unlocks native hardware DP4a execution on Intel Arc Xe-cores (and RDNA/NVIDIA architectures supporting SM 6.4).

Added dedicated hardware instruction test gpu_dp4a_dot_products_hardware_lowering in crates/xcl/src/gpu/recomp/tests.rs exercising both saturating and non-saturating paths for clamped and unclamped dot products on hardware GPU runner.

Per review on #985, sparse UMA chunk scanning has been split into a separate pull request (#1058).

Tested

  • Hardware: Intel Arc A770 (16GB, Driver 32.0.101.9175), AMD Ryzen 7 5700X, 32 GB RAM, Windows 11 Pro, MSVC 14.44.35207
  • Full workspace test suite: cargo test --workspace (672 passed, 0 failed, 21 ignored in lib; 13/13 console_dlls_e2e passed; 3/3 console_shaders passed; 1/1 disasm_e2e passed; 3/3 e2e passed; 1/1 sparse_reinit passed; 1/1 texture_states passed; 6/6 xg_oracle passed)
  • gpu::recomp::tests::gpu_dp4a_dot_products_hardware_lowering: passed on Intel Arc hardware GPU runner with bit-exact results.

Regression run
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

  • RDNA3 / older RDNA1 GPUs, Linux/Wine

AI use

  • Claude Code and Antigravity assisted in profiling DP4a intrinsic lowering and constructing synthetic instruction test cases.

@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.

# Conflicts:
#	crates/xcl/src/gpu/recomp/tests.rs
@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.

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.

4 participants