Repository navigation
On MSL 3.2+, heap_free reads the error flag with a coherent volatile load, not an atomic one (#1143) - #1299
Conversation
Lorenzobattistela
left a comment
There was a problem hiding this comment.
I ran the gates on this PR merged onto main 95217e9c: repo 50/50, ping 47/47, test 1559/1559 and perf 124/124. I didn't run gates/safe.ts, since this only touches the runtime. The cap note is out of date: since #1281, comp.ts merged comes to 63,027 / 64,000 ttok, so nothing needs trimming.
The M1/M2 build is still the blocker. a32_load reads through a volatile local because, as its comment says, "Metal's loads read through a volatile local, or the M1 and M2 pipeline builds die". err_peek instead reads device memory directly with *(volatile DEV u32*). gpu_desc sets no language version, so an M1 or M2 on macOS 15+ compiles at MSL 3.2+ and takes this load. heap_free is on nearly every path, so if this form is one that kills the build, every --gpu program fails on those machines. The gate minis are all M4, so the gates can't catch this; it needs a run on a real M1 or M2 before merging, as you note.
A small one: err_peek does a plain read of a word that err_post writes with an atomic CAS. MSL's model calls that a data race. It works on current Apple GPUs, and your out-of-heap runs show no difference from main beyond chance. But it's the one place the runtime reads a shared word outside a32_*, so it deserves a line at the macro saying why that's safe here.
The perf gate only checks against the pins, so I haven't measured the 1.06x / 1.02x myself.
…load, not an atomic one (bendlang#1143) Every free on every lane read the one error word atomically; atomics on one address are served one at a time. MSL 3.2's coherent device memory lets a volatile load see another lane's post, so heap_free keeps its check at the cost of a cached read. Below 3.2, and on the host and CUDA, it is err_seen as before. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
d814ba8 to
5bf7fe7
Compare
Closes #1143 with its first option. Needs a check on an M1 or M2 before merging (see below).
heap_freechecks the error flag on every free, and on the device that check is an atomic load of one shared word, which lanes are served one at a time. On MSL 3.2+, whereDEViscoherent(device), it now reads the flag with a volatile load. That keeps the check but lets the read come from cache. Below 3.2, and on the host and CUDA,err_peekiserr_seen, unchanged.Speed (M4, wall time,
--gpu, 20 alternating rounds, same outputs):The issue measured 1.12x and 1.07x in GPU time on an M5.
Error path: I ran both benches out of heap (
--gpu 512MB) 150 times each, with the same volatile read patched into main's emitted C:Counting earlier, smaller runs too, main had 2 bad outcomes in ~400 and the volatile read 5 in ~384, which is within chance (Fisher's exact p ≈ 0.3). Main's out-of-heap path occasionally faults or hangs on its own; that's #1300. Removing the check instead and guarding only the sink page went bad in 19 of 60 runs, so the check itself has to stay.
Before merging:
air.load.device_coherent.volatile), anda32_load's comment says M1/M2 pipeline builds die on some load forms. Nobody has built a!program on an M1 or M2 with this change; it needs one there.Gates (rebased on main at
1487e77d): repo 50 / 50, withcomp.tsat 63,507 ttok, under its 64,000 cap (main is 63,464); test 1577 / 1577. perf scores 121 to 124 / 124 from run to run, on this PR and on main alike, failing on the same cells (the short GPU runs of nbody, mandelbrot and merkle, and raytrace's compiler time). ping was skipped: the site repo isn't checked out on the machine that ran them.🤖 Generated with Claude Code