Repository navigation
A spin is a call on the device when its C is long, by characters not lines, and inline on the host - #1413
Conversation
…place of SPIN_FAR's line count Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…and inline on the host; a short loop stays inline Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Nice to see DFAR and the character-based SPIN_FAR land. I re-ran bend-bench paired on the RTX 3090 against current main: #1413 captures 1.53x of #1282's 1.87x CUDA speedup on raytrace by putting spin_18 (11.9 KB) back over SPIN_FAR, but still leaves a 1.22x speedup on raytrace (95% interval 1.20x to 1.24x) and 1.12x on editdist (1.12x to 1.14x) from the looping spins under 8 KB (spin_13 at 3.0 KB, spin_16 at 3.4 KB, and editdist's 0.7 to 0.9 KB loops). Even if M4 Metal barely feels that divergence, most GPU compute runs on CUDA, where inlining multiple copies of a variable-trip loop serializes the warp. With DFAR already in main and the quadratic map bug fixed, the zero-magic-number rule from #1282 (sharing a spin that has a loop calling spins when one caller runs it twice) drops from +325 to +174 ttok (63,495 -> 63,669, well under the 64k cap) and changes no other benchmark's code. If you prefer a size threshold like |
emit_nativechose a spin's qualifier by its line count: underSPIN_FAR(256) lines it wasINLINE, elseFAR, on the host and the device alike. Lines are a fragile measure: #834 changed how template keys print, raytrace's main loop (spin_18) folded into fewer, longer lines (358 → 259, 217 on main) with about the same code, crossed under 256 and becameINLINE. Metal inlines everything that is notnoinlineinto the onebend_devkernel, so its back end (library → binary archive) went from ~120 to ~220 ms, and raytrace's COMPILER cell sat at 1.15–1.16x its pin, failing the perf gate on most runs.The rule is now:
SPIN_FAR(8192) characters or more is a call (DFAR,FARon the device); a shorter one is inlined. Characters do not change when the emitter folds code onto fewer lines.INLINE, so clang decides. A forced call there never saved clang time and cost speed (raytrace lost 31% on PAR-CPU at a threshold of 128 lines).Where 8192 comes from
Each constraint below was measured on the minis (macOS 26.5.2) or locally, and every one sits on its side of 8 KB:
!!(the caseSPIN_FARwas added for, in 386b7fc)Two alternatives that were measured and rejected:
!is inlined again (the hvm5 case).No straight-line spin in
bench/,demos/ortests/that the device reaches is 8 KB or more today; the largest is kmeans' at 7.4 KB.Same device calls elsewhere
!), the device makes exactly the calls it made on main, including slash_boss_3d's two long loops.FAR).FARspin on main (slash_boss_3d's 3 MB of C, hvm5_mini's 1 MB among them) take the same clang time with itINLINE.Perf gate (cluster)
The one miss on this PR is mandelbrot PAR-GPU at 1.17x, which main misses too (1.20x). Every other cell is within ±4% of main, which is the spread of cells whose code did not change. Expect a COMPILER cell or two to read slow on the first runs after the merge: the minis' Metal shader cache is cold for new C (tree-radix read 0.67 s for three runs and 0.50 s on the fourth, during this work).
Checks
🤖 Generated with Claude Code