Repository navigation
Conversation
…c's lock A lane that waits out its bound goes on without the lock and can lose its update (pragyaangaur#240, pragyaangaur#306). Such a lane now adds one to a count after the lock words (ATOMIC_LOCKS_GAVE_UP_AT; the u1 buffer grows by 4 bytes), so a loss can be told apart from any other fault. The count rides on the atomic a lane already makes at the end of its step: a lane that took the lock adds all ones to it (it holds 1, so that frees it), and a lane that gave up adds one to the count instead of an `and` that changed nothing. No new branch and no extra atomic. Test: adds64_apply_once checks that every lost add has a lane that gave up behind it, then that there is no loss and no give-up. On an M5 Pro with compute back on 2^16 tries, every failing stress run had lanes that gave up behind it, and no run lost more adds than lanes gave up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After every submission the host reads and clears the count of lanes that gave up their lock (crate::shadow::take_gave_up) and logs the run's total each time it passes a power of two, so a game run shows whether the bound is ever reached and updates may be lost. Freeing stuck locks after an ended submission now leaves the count alone. Test: freeing_atomic_locks_keeps_pages_and_read_marks covers the count. docs/macos.md describes the count and the log line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #306. evan-kolberg's M4 Pro run there still lost 5–6 adds in 1 of 20 trials per mode at 2,048 groups. This makes every such loss visible, so we can tell whether a lane gave up its lock or something else went wrong.
What changed
ATOMIC_LOCKS_GAVE_UP_AT, at the end of theu1buffer, which grows by 4 bytes). The count rides on the atomic each lane already makes at the end of its step. A lane that took the lock adds all ones to it (it holds 1, so that frees it), and a lane that gave up adds one to the count. Before, it made a no-opandon the lock instead. There is no new branch and no extra atomic.lanes gave up waiting for a 64-bit atomic's lock and went on without it, so their updates may be lost (#240)each time the run's total passes a power of two. Freeing stuck locks after an ended submission (fix(shader): 64-bit atomics no longer lose updates under heavy lock contention #306) leaves the count alone.adds64_apply_oncereads the count and checks that every lost add has a lane that gave up behind it. A loss without one would be another fault. It then checks for no loss and no give-up. The unit test of the lock freeing also covers the count.docs/macos.mdand the module notes ("Atomic locks") describe the count and the log line.Why
On an M5 Pro, with compute put back on 2^16 tries, every failing stress run had lanes that gave up behind it (from 1 to 448 lanes, in 13 failing runs out of 22 invocations on two bases), and no run lost more adds than lanes gave up. That pins the M5 Pro losses on the bound. Under that contention a try takes about 1.5 µs here, so 2^22 tries is a budget of several seconds for a dispatch of about 0.1 s. If the M4 Pro still loses adds at 2^22, the count will say whether it is the bound or a different fault there.
#304's reduced
umaxruns through the same step, so its representatives are counted too.How tested
On an M5 Pro (64 GB, macOS 27.2.1, CrossOver 26.3 Wine, D3DMetal 4.0 beta 3):
mainae26882:cargo test --workspace542 passed, 0 failed both times.tools/macos/test-wine.sh --workspace --no-fail-fast1,104 passed, 0 failed both times (existing tests changed, none added).image_atomic_adds_of_64_bits_apply_once_under_contention(ignored, D3DMetal): 3 of 3 invocations passed on 2^22. With compute back on 2^16, 3 of 4 failed, each with lanes that gave up (18, 214 and 91).umax: within this Mac's run-to-run noise. A lighter copy ofatomic_lock_rounds_timing(16 and 256 per lane, the best of 4 warm runs, 6 runs per build) gave turns 15.9–18.1 before fix(shader): 64-bit atomics no longer lose updates under heavy lock contention #306, 16.7–18.9 with fix(shader): 64-bit atomics no longer lose updates under heavy lock contention #306 and 15.5–23.3 with this. Rounds gave 2.4–7.5, 3.2–7.1 and 3.3–7.0. The full test swung between about 21 and 32 µs in turns on every build, from run to run.cargo clippy -p victory-shader -p victory-gpu --all-targets --target x86_64-pc-windows-gnullvm -- -D warningsandcargo xtask policypass. Only changed lines are formatted.🤖 Generated with Claude Code