Skip to content

Recompiler: a bridged mask write in the split form meets no barrier - #2074

Open
gefydev wants to merge 1 commit into
xcl-dev:mainfrom
gefydev:per-lane-bridge-local-masks
Open

gefydev wants to merge 1 commit into
xcl-dev:mainfrom
gefydev:per-lane-bridge-local-masks

Conversation

@gefydev

@gefydev gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

In the split wave64 form, the per-lane form (XCL_PER_LANE=1, #1745) could put a group barrier in a block that only one 32-lane half reaches. Point 5 of Pipodi's review of #1745. Part of #1269.

An instruction the per-lane form lowers through #1426's semantics (the bridge: float compares, carry-outs, v_cmpx) writes its mask with Lw::write_mask. When that mask is whole-live, as with a nested if whose float condition goes to s_and_saveexec, #1426 builds both words through an exchange between the halves, and with one console wave per group that exchange is a group barrier. In a block only the lower half reaches, the upper half never gets there. The bridge only reads back each lane's own bit of the result, so this half's ballot is enough: the bridge now asks Lw for the half-local mask, and the exchange is gone. Only XCL_PER_LANE=1 reaches this code.

What is in it

  • crates/xcl/src/gpu/dxil/lower.rs, kernel.rs: Lw::local_masks. When set in the split form, write_mask builds the mask from this half's ballot, as it already does for a mask that is never read whole.
  • crates/xcl/src/gpu/recomp/lower_dxil.rs: DxilIr::foreign sets it around inst_guarded. New test a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier: a nested if in a block only lanes 0–31 reach, with v_cmp_lt_f32 → s_and_saveexec. It counts the group barriers in the DXIL and checks the result on the GPU. Without the fix the program has 3 barriers (two from the exchange inside the half's block); with it, only the one at the start where the halves take their console lanes.

Tested

  • NVIDIA GTX 1650 (32-lane waves only), driver 621.24, Windows 11 Pro 26300, Rust 1.100.0, debug.
  • The new test fails without the fix (left: 3, right: 1) and passes with it, including the GPU check: v7 = 5 in lanes 1–31 and 0 elsewhere, in both groups.
  • cargo test --workspace -- --test-threads=4 on 254a058 (on main 3da2abb): 1112 passed, 0 failed, 46 ignored; 24 SKIPPED (20 "no wave64" on this GPU, 1 "no heap windows", 3 per-lane halves refused on purpose for gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426's f16 rounding).

Regression run
main:

xcl-smoke v1
commit: 3da2abb81606df622610e009f0430de99aa9881c
gpu: NVIDIA GeForce GTX 1650
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 934 (PresentX 934)
presents per 2 s (last 3): 17 10 2
device removals: 0
crashes: 0
peak commit: 11918 MB

This PR's head:

xcl-smoke v1
commit: 254a058c400ea86645810f0660d70be23f146fbb
gpu: NVIDIA GeForce GTX 1650
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 829 (PresentX 829)
presents per 2 s (last 3): 7 2 0
device removals: 0
crashes: 0
peak commit: 14598 MB

Both with XCL_PER_LANE off (the default), which this change does not reach.

Not tested

  • Native wave64 GPUs (AMD): the split form is not used there.
  • A title run with XCL_PER_LANE=1; the regression runs are with it off, the default.
  • The hang itself: I checked the barrier count only, and did not run the old code on the GPU.

AI use

  • Claude Code (Claude Opus 5.5): wrote the fix, the test and this description, ran the checks.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pu3TMXtx8TYFxrYEFhfdEp

In the split wave64 form, an instruction the per-lane form lowers
through xcl-dev#1426's semantics (a float compare, a carry-out, v_cmpx) builds
its mask with Lw::write_mask. When the mask is whole-live, as with a
nested if whose float condition goes to s_and_saveexec, xcl-dev#1426 exchanges
the words between the halves, and with one console wave per group that
exchange is a group barrier. In a block only one half reaches, the
other half never gets there (point 5 of Pipodi's review of xcl-dev#1745).

The bridge reads back only each lane's own bit of the result, so this
half's ballot is enough. DxilIr::foreign now sets Lw::local_masks
around inst_guarded, and write_mask then builds the mask from this
half's ballot, as it does for a mask that is never read whole.

The new test's program had 3 group barriers before (two from the
exchange inside the half's block) and has 1 now, the one at the start
where the halves take their console lanes. Only XCL_PER_LANE=1 reaches
this code.
@Pipodi

Pipodi commented Nov 25, 2026

Copy link
Copy Markdown

Test report for 254a058 (this PR's head, on main 3da2abb).

Tested

  • RTX 4090 (driver 617.42), i9-13900K, 32 GB, Windows 11 Pro 26300, rustc 1.100.0, debug.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 1112 passed, 0 failed, 46 ignored, in 20 result blocks.
    • a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier passes, including its GPU dispatch: this adapter runs the split wave64 form.
  • SKIPPED: 23 GPU cases, all "no wave64" or a per-lane refusal that also happens on main; heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows); pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache: Developer Mode is required).
  • Fails without the change: I removed the two self.lw.local_masks = … lines in DxilIr::foreign and ran the new test alone. It failed on its barrier count, left: 3, right: 1, as the commit message says.

Not tested

  • A title run with XCL_PER_LANE=1: the default path does not reach this code.
  • Native wave64 hardware (AMD).

I read the diff. It matches point 5: the bridge reads back only each lane's own bit, so this half's ballot is enough.

AI use: Claude Code with Claude Opus 5.5 ran the tests and wrote this report.

@gefydev

gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@Pipodi thank you for the test report on 254a058: 1112 passed, 0 failed, 46 ignored on the RTX 4090, with the new test passing including its GPU dispatch, and failing without the change (barrier count left: 3, right: 1). Noted that a title run with XCL_PER_LANE=1 and native wave64 hardware were not covered.

AI use: Claude Code (Claude Opus 5.5) wrote this comment for @gefydev.

@JJAutoCompare

Copy link
Copy Markdown

PR #2074 split-wave64 mask-write verification

Tested

  • Commit 254a058c400ea86645810f0660d70be23f146fbb. The assigned checkout was clean and matched the open PR before and after testing.
  • Windows 11 Enterprise Evaluation 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 with driver 32.0.101.9175, Rust and Cargo 1.100.0 (x86_64-pc-windows-msvc), DXC and DXIL DLLs 1.9.2609.5.
  • Prebuild outside the GPU mutex with cargo test -p xcl --lib --no-run -j 2. Test profile unoptimized with debug info disabled. Prebuild completed in 1m 01s.
  • The successful run used the prebuilt executable from Cargo’s output. The child script was loaded with powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -EncodedCommand $encoded (UTF-16LE base64 of arc-command.txt), and called the lock wrapper below. The policy override was scoped to that child process.
$exe = 'L:/XclTooling/pr2014-1c971de6/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe'
$fixture = 'gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { & $exe $fixture --exact --nocapture }
  • Environment for the build and run used CARGO_TARGET_DIR=L:/XclTooling/pr2014-1c971de6/target, CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0, XCL_ADAPTER=A770, and XCL_DXC_DIR=%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64. Both TEMP and TMP pointed to this report’s directory.
Run Passed Failed Ignored Skipped Filtered out Fixture time
Mutex run with separate stdout and stderr 1 0 0 0 1088 0.16s

The checked-in fixture’s DXIL disassembly assertion found exactly one group barrier, at entry. Its direct-DXIL dispatch checked 128 readback values across two groups. In each group, v7 was 5 in lanes 1–31 and 0 in lane 0 and lanes 32–63.

The first two launches ended before the test ran. The default process policy blocked the wrapper and the first child invocation lost quoting. A subsequent exact run passed in 0.66s, but PowerShell reported a stderr parsing error. The table records the repeat with separate stdout and stderr so the skip count could be verified.

Not tested

The run covers the synthetic split-wave64 fixture on one Intel Arc A770. Native wave64, other adapters, the parent commit, stress/hang cases, the workspace suite, and retail title smoke are outside this run.

Evidence

Raw evidence in this directory includes environment.log, build.log, pr-before.log, pr-after.log, arc-command.txt, arc-verified.stdout.log, arc-verified.stderr.log, and arc-verified-exit.txt. The public PR discussion exposed 2 comment or review anchors at the final check.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the checked-in fixture and wrote this empirical report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@gefydev

gefydev commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@DavidM1911 thank you for the verification of #2074 on the RTX 3060 Ti (cargo test -p xcl --lib: all passed, 0 failed, about 26 ignored; the intermittent parallel-scheduling abort tracked in #1978 was clean on a single-threaded rerun). Noted.

AI use: Claude Code (Claude Opus 5.5) wrote this comment for @gefydev.

@LANgmas

LANgmas commented Nov 25, 2026

Copy link
Copy Markdown

Independent hardware validation — RTX 3050 (Ampere): PASS

I independently reproduced the author's GTX 1650 result on an NVIDIA GeForce RTX 3050 Laptop GPU (Ampere, wave32-only).

  • Focused test a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, run twice with XCL_ADAPTER=nvidia XCL_PER_LANE=1: 2/2 PASS.
  • DXIL assertion confirmed exactly 1 barrier.
  • Actual GPU dispatch assertions passed: v7 == 5 in lanes 1–31 and 0 elsewhere, across both groups. The focused test was not skipped.
  • Narrow lower_dxil suite: 19 passed, 0 failed, 17 skipped. Skips were 14 wave64 capability skips and 3 intentional gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantic refusals.

Hardware: RTX 3050 Laptop GPU, driver 617.14, D3D12 FL 12_2 / Shader Model 6.8, DXC 1.9.2602.17, Windows build 26300.

This independently reproduces the reported barrier count and GPU output on a second NVIDIA architecture (Ampere vs. the author's Turing GTX 1650).

Scope: supplemental GPU validation only. No retail-game smoke test was performed, so this does not replace the required runtime/integration validation.

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